From: Amit Purwar Date: Thu, 14 Nov 2019 11:39:39 +0000 (+0530) Subject: Resolve the LE advertising fail after slot exhaustion X-Git-Tag: accepted/tizen/unified/20191118.122930~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ed62f757f881b4851b3ec7d169ddd34f1628de52;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git Resolve the LE advertising fail after slot exhaustion Change-Id: Iebd4249b8ee1d7fe1db48c84e479058de83b192f Signed-off-by: Amit Purwar --- diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-le.c b/bt-oal/bluez_hal/src/bt-hal-adapter-le.c index 16f8630..27b56fb 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-le.c +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-le.c @@ -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); } diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-server.c b/bt-oal/bluez_hal/src/bt-hal-gatt-server.c index 4b9e2cc..d1eabe8 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-server.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-server.c @@ -1819,6 +1819,28 @@ static struct hal_gatts_server_register_info_t * bt_hal_gatts_find_server_regist return NULL; } +static struct hal_gatts_server_register_info_t * bt_hal_gatts_find_server_register_info_by_slot_id(int adv_slot_id) +{ + DBG("+"); + + GSList *l; + struct hal_gatts_server_register_info_t *info = NULL; + + for (l = hal_gatts_server_register_list; l != NULL; l = g_slist_next(l)) { + info = (struct hal_gatts_server_register_info_t *)l->data; + if (info == NULL) { + continue; + } + + if (info->adv_slot_id == adv_slot_id) { + DBG("gatt server register found"); + return info; + } + } + + return NULL; +} + static struct hal_gatts_server_register_info_t * bt_hal_gatts_add_server_app(bt_uuid_t *app_uuid) { DBG("+"); @@ -3428,6 +3450,37 @@ static int bt_hal_gatts_allocate_adv_slot(struct hal_gatts_server_register_info_ return 0; } +int bt_hal_gatts_allocate_adv_slot_by_server_if(int server_if) +{ + CHECK_BTGATT_INIT(); + + int ret = -1; + + struct hal_gatts_server_register_info_t *server_register_info = NULL; + + DBG("server_if: [%d]", server_if); + + server_register_info = bt_hal_gatts_find_server_register_info(server_if); + if (server_register_info == NULL) { + DBG("gatt server is not registered"); + return -1; + } + + DBG("gatt server:[%d], adv_slot:[%d]", server_register_info->server_if, server_register_info->adv_slot_id); + + if (server_register_info->adv_slot_id < 0 ) { + DBG("adv_slot is not assigned to server:[%d] \n", server_if); + + ret = bt_hal_gatts_allocate_adv_slot(server_register_info); + if (ret < 0) { + DBG("failed to get adv_slot"); + return -1; + } + } + + return server_register_info->adv_slot_id; +} + void bt_hal_gatts_release_adv_slot(int server_if) { struct hal_gatts_server_register_info_t *server_register_info = NULL; @@ -3465,6 +3518,19 @@ int bt_hal_gatts_get_adv_slot_id(int server_if) return server_register_info->adv_slot_id; } +int bt_hal_gatts_get_server_if(int slot_id) +{ + struct hal_gatts_server_register_info_t *server_register_info = NULL; + + server_register_info = bt_hal_gatts_find_server_register_info_by_slot_id(slot_id); + if (server_register_info == NULL) { + DBG("failed to get server_register_info"); + return -1; + } + + return server_register_info->server_if; +} + static bt_status_t gatt_server_multi_adv_enable(int server_if) { CHECK_BTGATT_INIT(); diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-server.h b/bt-oal/bluez_hal/src/bt-hal-gatt-server.h index c340fdc..ffae6d5 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-server.h +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-server.h @@ -49,6 +49,10 @@ void bt_hal_gatts_release_adv_slot(int server_if); int _bt_get_remote_gatt_client_conn_id(char *address); +int bt_hal_gatts_allocate_adv_slot_by_server_if(int server_if); + +int bt_hal_gatts_get_server_if(int slot_id); + #ifdef __cplusplus } #endif /* __cplusplus */