Don't unregister hold advertising information 10/183510/1
authorSeungyoun Ju <sy39.ju@samsung.com>
Fri, 6 Jul 2018 06:05:09 +0000 (15:05 +0900)
committerinjun.yang <injun.yang@samsung.com>
Fri, 6 Jul 2018 06:05:09 +0000 (15:05 +0900)
[Problem] Restarted advertising triggered by LE connection request
 doesn't have the information about sender and handle. It causes some
 malfunctions (e.g. Connect LE to out-of-range LE device twice. The
 second one is requested as Directed Advertising (Slave role request))
[Cause & Measure] Advertising information is flushed once it is stopped
 by LE connection request. So even though it is restarted by hold
 advertising logic, there is no sender / advertising handle information.
 It causes the next time hold advertising failed.
 This patch doesn't unregister hold state advertising slot. Because it
 will be used again after timer is expired. Or, once timer is cancelled,
 it will be unregistered properly.
[Checking Method] Connect LE to out-of-range LE device twice

Change-Id: Ia79dd8ab5ba06778d946856883879c1f5a93d898

bt-service/bt-service-adapter-le.c
bt-service/bt-service-device.c

index 214312b..aeb8cb8 100644 (file)
@@ -280,6 +280,11 @@ static void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int
 
 void _bt_unregister_adv_slot_owner(int slot_id)
 {
+       if (le_adv_slot[slot_id].hold_timer_id > 0) {
+               BT_INFO("Hold state adv is not unregistered");
+               return;
+       }
+
        g_free(le_adv_slot[slot_id].sender);
        le_adv_slot[slot_id].sender = NULL;
        le_adv_slot[slot_id].adv_handle = 0;
@@ -372,14 +377,15 @@ int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gbo
        if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
                return BLUETOOTH_ERROR_IN_PROGRESS;
 
-       if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
-               return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
        if (le_adv_slot[slot_id].hold_timer_id > 0) {
                g_source_remove(le_adv_slot[slot_id].hold_timer_id);
                le_adv_slot[slot_id].hold_timer_id = 0;
+               _bt_unregister_adv_slot_owner(slot_id);
        }
 
+       if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
+               return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
@@ -439,14 +445,15 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle,
        if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
                return BLUETOOTH_ERROR_IN_PROGRESS;
 
-       if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
-               return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
        if (le_adv_slot[slot_id].hold_timer_id > 0) {
                g_source_remove(le_adv_slot[slot_id].hold_timer_id);
                le_adv_slot[slot_id].hold_timer_id = 0;
+               _bt_unregister_adv_slot_owner(slot_id);
        }
 
+       if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
+               return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
@@ -501,8 +508,6 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle,
 
        if (enable == TRUE)
                __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
-       else
-               _bt_unregister_adv_slot_owner(slot_id);
 
        le_adv_slot[slot_id].is_advertising = enable;
        BT_INFO_C("### Set advertising [%d], Slot id [%d]", enable, slot_id);
index 92d75b0..eca0775 100644 (file)
@@ -692,9 +692,11 @@ static int __bt_remove_and_bond(void)
                                NULL,
                                &err);
        g_free(device_path);
-       if (err != NULL) {
-               BT_ERR("UnpairDevice Fail: %s", err->message);
-               g_error_free(err);
+       if (result == NULL) {
+               if (err != NULL) {
+                       BT_ERR("UnpairDevice Fail: %s", err->message);
+                       g_error_free(err);
+               }
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
@@ -1987,10 +1989,10 @@ int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
                        g_timeout_add(1000, __bt_connect_le_timer_cb, NULL);
 
                return BLUETOOTH_ERROR_NONE;
+       } else if (ret != BLUETOOTH_ERROR_NOT_IN_OPERATION) {
+               BT_ERR("Unable to hold advertising");
        }
 
-       BT_ERR("Unable to hold advertising");
-
        return __bt_connect_le_device_internal(req_id, bd_addr, auto_connect);
 }