From 064713fba7d1d7c8f2d602ea91f31f5aed3b6d1b Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Wed, 15 Jan 2020 13:34:27 +0900 Subject: [PATCH] Modify the logic of bonding with LE type No need to unbond before bond with bluez stack Add new oal function to get stack name Change-Id: I29ade86c73bba5a26306a091b5da58a99f7666a8 --- bt-oal/bluez_hal/src/bt-hal-bluetooth.c | 2 +- bt-oal/include/oal-manager.h | 9 ++++++++ bt-oal/oal-manager.c | 5 +++++ .../services/device/bt-service-core-device.c | 25 ++++++++++++---------- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index d914d3e..7c7dd44 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -541,7 +541,7 @@ struct hw_module_t HAL_MODULE_INFO_SYM = { .version_major = 1, .version_minor = 0, .id = BT_HARDWARE_MODULE_ID, - .name = "Bluetooth stack", + .name = "bluez", .author = "Intel Corporation", .methods = &bluetooth_module_methods }; diff --git a/bt-oal/include/oal-manager.h b/bt-oal/include/oal-manager.h index ac05875..2b02fee 100755 --- a/bt-oal/include/oal-manager.h +++ b/bt-oal/include/oal-manager.h @@ -251,6 +251,15 @@ gboolean oal_get_debug_mode(void); void server_event_catch_register(oal_event_callback dbg_cb); #endif +/** + * @brief Get stack name + * + * @return stack name + * + * @pre OAL API must be initialized with oal_bt_init(). + */ +const char *oal_get_stack_name(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/oal-manager.c b/bt-oal/oal-manager.c index 56b821f..0d28d52 100644 --- a/bt-oal/oal-manager.c +++ b/bt-oal/oal-manager.c @@ -263,3 +263,8 @@ gboolean oal_get_debug_mode(void) /*TODO Unsupported */ return FALSE; } + +const char *oal_get_stack_name(void) +{ + return module ? module->name : NULL; +} diff --git a/bt-service-adaptation/services/device/bt-service-core-device.c b/bt-service-adaptation/services/device/bt-service-core-device.c index 38adcd1..01c0461 100644 --- a/bt-service-adaptation/services/device/bt-service-core-device.c +++ b/bt-service-adaptation/services/device/bt-service-core-device.c @@ -1832,6 +1832,7 @@ int _bt_bond_device(bluetooth_device_address_t *device_address, int result = BLUETOOTH_ERROR_NONE; char address[BT_ADDRESS_STRING_SIZE] = { 0 }; bluetooth_device_info_t dev_info; + const char *stack_name = NULL; BT_DBG("+"); retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM); @@ -1855,19 +1856,21 @@ int _bt_bond_device(bluetooth_device_address_t *device_address, /* Ready to initiate bonding */ - /* In Tizen, we will first remove bond and then attempt to create bond to keep - consistency with bluedroid. Even if remove bond fails due to device not already - bonded, then straight away create bond is triggered. This is because, remove bond - is handled differently in bluedroid and bluez. In Bluez, if device is - already removed, remove bond call fails. - However in bluedroid, remove bond on already removed device returns success. So we will - handle the cases transparently*/ - if (conn_type == BLUETOOTH_DEV_CONN_BREDR) { - bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVE_BONDING; - } else if (conn_type == BLUETOOTH_DEV_CONN_LE) { - /* No need to remove if LE conn */ + stack_name = oal_get_stack_name(); + if (stack_name && !g_strcmp0(stack_name, "bluez")) { + BT_DBG("[bluez] Create bond by type %d", conn_type); bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVED_BONDING; + } else { + /* In Tizen, we will first remove bond and then attempt to create bond to keep + consistency with bluedroid. Even if remove bond fails due to device not already + bonded, then straight away create bond is triggered. This is because, remove bond + is handled differently in bluedroid and bluez. In Bluez, if device is + already removed, remove bond call fails. + However in bluedroid, remove bond on already removed device returns success. So we will + handle the cases transparently */ + bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVE_BONDING; } + bond_retry_count = 0; result = __bt_device_handle_bond_state(); -- 2.7.4