+static void __bt_free_gatt_server_app(struct gatt_server_app *app)
+{
+ g_free(app->app_path);
+ g_free(app);
+}
+
+static void __bt_hal_gatt_free_service_info(struct gatt_service_info *svc_info)
+{
+ if (!svc_info)
+ return;
+
+ g_free(svc_info->serv_path);
+ g_free(svc_info->service_uuid);
+ g_free(svc_info);
+}
+
+void _bt_hal_gatt_server_init(void)
+{
+ assigned_id = 0;
+ memset(instance_id_used, 0x00, sizeof(instance_id_used));
+
+ g_slist_free_full(gatt_server_apps, (GDestroyNotify)__bt_free_gatt_server_app);
+ gatt_server_apps = NULL;
+
+ g_slist_free_full(gatt_services, (GDestroyNotify)__bt_hal_gatt_free_service_info);
+ gatt_services = NULL;
+
+ g_slist_free_full(hal_gatts_server_register_list, g_free);
+ hal_gatts_server_register_list = NULL;
+}
+
+static int __bt_hal_gatt_assign_id(void)
+{
+ int index;
+
+ index = assigned_id + 1;
+
+ if (index >= BT_GATTS_MAX)
+ index = 1;
+
+ while (instance_id_used[index] == TRUE) {
+ if (index == assigned_id) {
+ /* No available ID */
+ ERR("All interface ID is used");
+ return -1;
+ }
+
+ index++;
+
+ if (index >= BT_GATTS_MAX)
+ index = 1;
+ }
+
+ assigned_id = index;
+ instance_id_used[index] = TRUE;
+
+ return assigned_id;
+}
+
+static void __bt_hal_gatt_delete_id(int instance_id)
+{
+ if (instance_id >= BT_GATTS_MAX || instance_id < 0)
+ return;
+
+ instance_id_used[instance_id] = FALSE;
+}
+