Don't unregister hold advertising information 55/136655/1
authorSeungyoun Ju <sy39.ju@samsung.com>
Wed, 21 Jun 2017 05:52:29 +0000 (14:52 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Fri, 30 Jun 2017 14:41:33 +0000 (23:41 +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: Ia287da58204348f7deb06117654956bc2948f4e1

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

index 5101338..8ad5ad8 100644 (file)
@@ -196,6 +196,11 @@ void _bt_unregister_adv_slot_owner(int slot_id)
        if (le_adv_slot == NULL)
                return;
 
+       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;
@@ -296,14 +301,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);
 
@@ -363,14 +369,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);
 
@@ -425,8 +432,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]", enable);
@@ -499,7 +504,7 @@ int _bt_hold_current_advertising(void)
                le_adv_slot[0].hold_timer_id = g_timeout_add(2000,
                                __bt_hold_current_advertising_timeout_cb, NULL);
        } else {
-               BT_ERR("It's NOT advertising");
+               BT_INFO("It's NOT advertising");
                return BLUETOOTH_ERROR_NOT_IN_OPERATION;
        }
 
index fd1466b..96c8a78 100644 (file)
@@ -2032,10 +2032,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);
 }