Loading system/btif/include/btif_api.h +17 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,23 @@ bt_status_t btif_disable_bluetooth(void); *******************************************************************************/ bt_status_t btif_shutdown_bluetooth(void); /******************************************************************************* ** ** Function is_restricted_mode ** ** Description Checks if BT was enabled in restriced mode. In restricted ** mode, bonds that are created are marked as temporary. ** These bonds persist until we leave restricted mode, at ** which point they will be deleted from the config. Also ** while in restricted mode, the user can access devices ** that are already paired before entering restricted mode, ** but they cannot remove any of these devices. ** ** Returns bool ** *******************************************************************************/ bool is_restricted_mode(void); /******************************************************************************* ** ** Function btif_get_adapter_properties Loading system/btif/include/btif_storage.h +12 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,18 @@ bt_status_t btif_storage_add_device_to_autopair_blacklist(bt_bdaddr_t *remote_bd *******************************************************************************/ BOOLEAN btif_storage_is_fixed_pin_zeros_keyboard(bt_bdaddr_t *remote_bd_addr); /******************************************************************************* ** ** Function btif_storage_is_retricted_device ** ** Description BTIF storage API - checks if this device is a restricted device ** ** Returns TRUE if the device is labled as restricted ** FALSE otherwise ** *******************************************************************************/ BOOLEAN btif_storage_is_restricted_device(const bt_bdaddr_t *remote_bd_addr); #if (BLE_INCLUDED == TRUE) bt_status_t btif_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr, char *key, Loading system/btif/src/bluetooth.c +13 −2 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ #include "osi/include/osi.h" #include "stack_manager.h" #include "btif_config.h" #include "btif_storage.h" /************************************************************************************ ** Constants & Macros Loading @@ -68,6 +69,7 @@ ************************************************************************************/ bt_callbacks_t *bt_hal_cbacks = NULL; bool restricted_mode = FALSE; /** Operating System specific callouts for resource management */ bt_os_callouts_t *bt_os_callouts = NULL; Loading Loading @@ -136,8 +138,10 @@ static int init(bt_callbacks_t *callbacks) { return BT_STATUS_SUCCESS; } static int enable(void) { LOG_INFO("%s", __func__); static int enable(bool start_restricted) { LOG_INFO(LOG_TAG, "%s: start restricted = %d", __func__, start_restricted); restricted_mode = start_restricted; if (!interface_ready()) return BT_STATUS_NOT_READY; Loading @@ -158,6 +162,10 @@ static void cleanup(void) { stack_manager_get_interface()->clean_up_stack_async(); } bool is_restricted_mode() { return restricted_mode; } static int get_adapter_properties(void) { /* sanity check */ Loading Loading @@ -268,6 +276,9 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr) static int remove_bond(const bt_bdaddr_t *bd_addr) { if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr)) return BT_STATUS_SUCCESS; /* sanity check */ if (interface_ready() == FALSE) return BT_STATUS_NOT_READY; Loading system/btif/src/btif_config.c +22 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "osi/include/alarm.h" #include "osi/include/allocator.h" #include "btcore/include/bdaddr.h" #include "btif_api.h" #include "btif_config.h" #include "btif_config_transcode.h" #include "btif_util.h" Loading @@ -45,6 +46,7 @@ static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000; static void timer_config_save_cb(void *data); static void btif_config_write(void); static void btif_config_remove_unpaired(config_t *config); static void btif_config_remove_restricted(config_t *config); // TODO(zachoverflow): Move these two functions out, because they are too specific for this file // {grumpy-cat/no, monty-python/you-make-me-sad} Loading Loading @@ -111,6 +113,10 @@ static future_t *init(void) { btif_config_remove_unpaired(config); // Cleanup temporary pairings if we have left guest mode if (!is_restricted_mode()) btif_config_remove_restricted(config); // TODO(sharvil): use a non-wake alarm for this once we have // API support for it. There's no need to wake the system to // write back to disk. Loading Loading @@ -421,3 +427,19 @@ static void btif_config_remove_unpaired(config_t *conf) { snode = config_section_next(snode); } } static void btif_config_remove_restricted(config_t* config) { assert(config != NULL); pthread_mutex_lock(&lock); const config_section_node_t *snode = config_section_begin(config); while (snode != config_section_end(config)) { const char *section = config_section_name(snode); if (string_is_bdaddr(section) && config_has_key(config, section, "Restricted")) { BTIF_TRACE_DEBUG("%s: Removing restricted device %s", __func__, section); config_remove_section(config, section); } snode = config_section_next(snode); } pthread_mutex_unlock(&lock); } system/btif/src/btif_storage.c +24 −0 Original line number Diff line number Diff line Loading @@ -806,6 +806,13 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, int ret = btif_config_set_int(bdstr, "LinkKeyType", (int)key_type); ret &= btif_config_set_int(bdstr, "PinLength", (int)pin_length); ret &= btif_config_set_bin(bdstr, "LinkKey", link_key, sizeof(LINK_KEY)); if (is_restricted_mode()) { BTIF_TRACE_WARNING("%s: '%s' pairing will be removed if unrestricted", __func__, bdstr); btif_config_set_int(bdstr, "Restricted", 1); } /* write bonded info immediately */ btif_config_flush(); return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; Loading Loading @@ -1660,3 +1667,20 @@ BOOLEAN btif_storage_is_fixed_pin_zeros_keyboard(bt_bdaddr_t *remote_bd_addr) } /******************************************************************************* ** ** Function btif_storage_is_restricted_device ** ** Description BTIF storage API - checks if this device is a restricted device ** ** Returns TRUE if the device is labeled as restricted ** FALSE otherwise ** *******************************************************************************/ BOOLEAN btif_storage_is_restricted_device(const bt_bdaddr_t *remote_bd_addr) { bdstr_t bdstr; bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr)); return btif_config_exist(bdstr, "Restricted"); } Loading
system/btif/include/btif_api.h +17 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,23 @@ bt_status_t btif_disable_bluetooth(void); *******************************************************************************/ bt_status_t btif_shutdown_bluetooth(void); /******************************************************************************* ** ** Function is_restricted_mode ** ** Description Checks if BT was enabled in restriced mode. In restricted ** mode, bonds that are created are marked as temporary. ** These bonds persist until we leave restricted mode, at ** which point they will be deleted from the config. Also ** while in restricted mode, the user can access devices ** that are already paired before entering restricted mode, ** but they cannot remove any of these devices. ** ** Returns bool ** *******************************************************************************/ bool is_restricted_mode(void); /******************************************************************************* ** ** Function btif_get_adapter_properties Loading
system/btif/include/btif_storage.h +12 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,18 @@ bt_status_t btif_storage_add_device_to_autopair_blacklist(bt_bdaddr_t *remote_bd *******************************************************************************/ BOOLEAN btif_storage_is_fixed_pin_zeros_keyboard(bt_bdaddr_t *remote_bd_addr); /******************************************************************************* ** ** Function btif_storage_is_retricted_device ** ** Description BTIF storage API - checks if this device is a restricted device ** ** Returns TRUE if the device is labled as restricted ** FALSE otherwise ** *******************************************************************************/ BOOLEAN btif_storage_is_restricted_device(const bt_bdaddr_t *remote_bd_addr); #if (BLE_INCLUDED == TRUE) bt_status_t btif_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr, char *key, Loading
system/btif/src/bluetooth.c +13 −2 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ #include "osi/include/osi.h" #include "stack_manager.h" #include "btif_config.h" #include "btif_storage.h" /************************************************************************************ ** Constants & Macros Loading @@ -68,6 +69,7 @@ ************************************************************************************/ bt_callbacks_t *bt_hal_cbacks = NULL; bool restricted_mode = FALSE; /** Operating System specific callouts for resource management */ bt_os_callouts_t *bt_os_callouts = NULL; Loading Loading @@ -136,8 +138,10 @@ static int init(bt_callbacks_t *callbacks) { return BT_STATUS_SUCCESS; } static int enable(void) { LOG_INFO("%s", __func__); static int enable(bool start_restricted) { LOG_INFO(LOG_TAG, "%s: start restricted = %d", __func__, start_restricted); restricted_mode = start_restricted; if (!interface_ready()) return BT_STATUS_NOT_READY; Loading @@ -158,6 +162,10 @@ static void cleanup(void) { stack_manager_get_interface()->clean_up_stack_async(); } bool is_restricted_mode() { return restricted_mode; } static int get_adapter_properties(void) { /* sanity check */ Loading Loading @@ -268,6 +276,9 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr) static int remove_bond(const bt_bdaddr_t *bd_addr) { if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr)) return BT_STATUS_SUCCESS; /* sanity check */ if (interface_ready() == FALSE) return BT_STATUS_NOT_READY; Loading
system/btif/src/btif_config.c +22 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "osi/include/alarm.h" #include "osi/include/allocator.h" #include "btcore/include/bdaddr.h" #include "btif_api.h" #include "btif_config.h" #include "btif_config_transcode.h" #include "btif_util.h" Loading @@ -45,6 +46,7 @@ static const period_ms_t CONFIG_SETTLE_PERIOD_MS = 3000; static void timer_config_save_cb(void *data); static void btif_config_write(void); static void btif_config_remove_unpaired(config_t *config); static void btif_config_remove_restricted(config_t *config); // TODO(zachoverflow): Move these two functions out, because they are too specific for this file // {grumpy-cat/no, monty-python/you-make-me-sad} Loading Loading @@ -111,6 +113,10 @@ static future_t *init(void) { btif_config_remove_unpaired(config); // Cleanup temporary pairings if we have left guest mode if (!is_restricted_mode()) btif_config_remove_restricted(config); // TODO(sharvil): use a non-wake alarm for this once we have // API support for it. There's no need to wake the system to // write back to disk. Loading Loading @@ -421,3 +427,19 @@ static void btif_config_remove_unpaired(config_t *conf) { snode = config_section_next(snode); } } static void btif_config_remove_restricted(config_t* config) { assert(config != NULL); pthread_mutex_lock(&lock); const config_section_node_t *snode = config_section_begin(config); while (snode != config_section_end(config)) { const char *section = config_section_name(snode); if (string_is_bdaddr(section) && config_has_key(config, section, "Restricted")) { BTIF_TRACE_DEBUG("%s: Removing restricted device %s", __func__, section); config_remove_section(config, section); } snode = config_section_next(snode); } pthread_mutex_unlock(&lock); }
system/btif/src/btif_storage.c +24 −0 Original line number Diff line number Diff line Loading @@ -806,6 +806,13 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, int ret = btif_config_set_int(bdstr, "LinkKeyType", (int)key_type); ret &= btif_config_set_int(bdstr, "PinLength", (int)pin_length); ret &= btif_config_set_bin(bdstr, "LinkKey", link_key, sizeof(LINK_KEY)); if (is_restricted_mode()) { BTIF_TRACE_WARNING("%s: '%s' pairing will be removed if unrestricted", __func__, bdstr); btif_config_set_int(bdstr, "Restricted", 1); } /* write bonded info immediately */ btif_config_flush(); return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; Loading Loading @@ -1660,3 +1667,20 @@ BOOLEAN btif_storage_is_fixed_pin_zeros_keyboard(bt_bdaddr_t *remote_bd_addr) } /******************************************************************************* ** ** Function btif_storage_is_restricted_device ** ** Description BTIF storage API - checks if this device is a restricted device ** ** Returns TRUE if the device is labeled as restricted ** FALSE otherwise ** *******************************************************************************/ BOOLEAN btif_storage_is_restricted_device(const bt_bdaddr_t *remote_bd_addr) { bdstr_t bdstr; bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr)); return btif_config_exist(bdstr, "Restricted"); }