+static int bt_hal_gatts_allocate_adv_slot(struct hal_gatts_server_register_info_t *server_register_info)
+{
+ int adv_slot_id = -1;
+
+ /* allocate adv slot for gatt server if not assigned */
+ if (server_register_info->adv_slot_id < 0 ) {
+ adv_slot_id = _bt_hal_get_available_adv_slot_id(&server_register_info->app_uuid, FALSE);
+ if (adv_slot_id < 0) {
+ ERR("failed to get the adv_slot");
+ return -1;
+ }
+
+ server_register_info->adv_slot_id = adv_slot_id;
+ }
+
+ DBG("gatt server:[%d] Assigned adv_slot [%d]", server_register_info->server_if, server_register_info->adv_slot_id);
+
+ 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;
+
+ server_register_info = bt_hal_gatts_find_server_register_info(server_if);
+ if (server_register_info == NULL) {
+ ERR("failed to get server_register_info");
+ return;
+ }
+
+ if (server_register_info->adv_slot_id < 0) {
+ ERR("adv_slot is not allocated");
+ return;
+ }
+
+ if(_bt_hal_is_advertising_in_slot(server_register_info->adv_slot_id) == FALSE) {
+ DBG("advertising is disabled");
+ _bt_hal_free_server_slot(server_register_info->adv_slot_id);
+ server_register_info->adv_slot_id = -1;
+ }
+}
+
+int bt_hal_gatts_get_adv_slot_id(int server_if)
+{
+ struct hal_gatts_server_register_info_t *server_register_info = NULL;
+
+ server_register_info = bt_hal_gatts_find_server_register_info(server_if);
+ if (server_register_info == NULL) {
+ DBG("failed to get server_register_info");
+ return -1;
+ }
+
+ 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;
+}
+