Resolve the LE advertising fail after slot exhaustion
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-adapter-le.c
index 16f8630..27b56fb 100644 (file)
@@ -188,22 +188,23 @@ gboolean _bt_hal_is_advertising_in_slot(int slot)
 
 void _bt_hal_set_advertising_status(int slot_id, gboolean mode)
 {
-       DBG("Advertising enabled [%s] server_slot [%d]",  mode ? "TRUE" : "FALSE", slot_id);
        bt_hal_adv_event_data_t *event;
-       int adv_slot_id = -1;
+       int adv_slot_id = slot_id;
+       int server_if = 0;
 
-       if (le_adv_slot == NULL)
-               return;
+       server_if = bt_hal_gatts_get_server_if(slot_id);
 
-       adv_slot_id = bt_hal_gatts_get_adv_slot_id(slot_id);
-       if (adv_slot_id < 0)
+       DBG("Advertising enabled [%s] server_slot [%d] server_if[%d]",  mode ? "TRUE" : "FALSE", slot_id, server_if);
+
+       if (le_adv_slot == NULL)
                return;
 
        le_adv_slot[adv_slot_id].is_advertising = mode;
 
        event = g_malloc0(sizeof(bt_hal_adv_event_data_t));
        event->event = mode ? BT_HAL_MULTI_ADV_ENB_EVT : BT_HAL_MULTI_ADV_DISABLE_EVT;
-       event->server_if = slot_id;
+
+       event->server_if = server_if;
        event->status = BT_STATUS_SUCCESS;
        /* To be removed later when we completely descope Legacy Adv concept */
 
@@ -213,7 +214,7 @@ void _bt_hal_set_advertising_status(int slot_id, gboolean mode)
 
        if (mode == false ) {
                DBG("release the adv_slot");
-               bt_hal_gatts_release_adv_slot(slot_id);
+               bt_hal_gatts_release_adv_slot(server_if);
        }
 
        __bt_hal_adv_event_cb((gpointer)event);
@@ -627,7 +628,7 @@ int _bt_hal_enable_advertising(int server_if, int adv_slot_id, bool enable, bool
        }
 
        ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
-                       g_variant_new("(bi)", enable, server_if),
+                       g_variant_new("(bi)", enable, adv_slot_id),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
@@ -660,6 +661,7 @@ int _bt_hal_set_advertising_params(int server_if, int min_interval,
        guint32 min = 0;
        guint32 max = 0;
        bt_hal_adv_event_data_t *event;
+       int slot_id = 0;
 
 
        proxy = _bt_hal_get_adapter_proxy();
@@ -681,10 +683,12 @@ int _bt_hal_set_advertising_params(int server_if, int min_interval,
        min = min_interval / BT_HAL_ADV_INTERVAL_SPLIT;
        max = max_interval / BT_HAL_ADV_INTERVAL_SPLIT;
 
+       slot_id = bt_hal_gatts_allocate_adv_slot_by_server_if(server_if);
+
        ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingParameters",
                        g_variant_new("(uuuuii)", min, max,
                        BT_HAL_ADV_FILTER_POLICY_DEFAULT, adv_type,
-                       tx_power, server_if), G_DBUS_CALL_FLAGS_NONE,
+                       tx_power, slot_id), G_DBUS_CALL_FLAGS_NONE,
                        -1, NULL, &error);
        if (error) {
                ERR("SetAdvertisingParameters Fail: %s", error->message);
@@ -723,6 +727,7 @@ int _bt_hal_set_advertising_data(btgatt_adv_param_setup_t adv_param_setup)
        bt_hal_adv_event_data_t *event;
        int length = 0;
        int i;
+       int slot_id = 0;
 
        /* Parse data according to Bluez Interface */
        if (__bt_hal_is_factory_test_mode()) {
@@ -735,6 +740,8 @@ int _bt_hal_set_advertising_data(btgatt_adv_param_setup_t adv_param_setup)
        if (proxy == NULL)
                return BT_STATUS_FAIL;
 
+       slot_id = bt_hal_gatts_allocate_adv_slot_by_server_if(adv_param_setup.server_if);
+
        memset(&adv_data, 0, 31);
 
        /* Service UUID */
@@ -820,13 +827,13 @@ int _bt_hal_set_advertising_data(btgatt_adv_param_setup_t adv_param_setup)
        if (adv_param_setup.set_scan_rsp == 0) {
                /* Set Advertising data to stack */
                ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingData",
-                               g_variant_new("(@ayi)", temp, adv_param_setup.server_if),
+                               g_variant_new("(@ayi)", temp, slot_id),
                                G_DBUS_CALL_FLAGS_NONE,
                                -1, NULL, &error);
        } else {
                /* Set Scan response data to stack */
                ret = g_dbus_proxy_call_sync(proxy, "SetScanRespData",
-                               g_variant_new("(@ayi)", temp, adv_param_setup.server_if),
+                               g_variant_new("(@ayi)", temp, slot_id),
                                G_DBUS_CALL_FLAGS_NONE,
                                -1, NULL, &error);
        }