From 8be593a40f32cf0245157f62c313ea02658204a7 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Thu, 6 Feb 2020 18:19:52 +0900 Subject: [PATCH] Seperate GATT unregister instance function If client ID has the same value with server ID, then the abnormal unregisteration can be occured. This patchset prevents that issue. Change-Id: Idaf156848587d1c7bd75fc697445804065fbedb0 Signed-off-by: DoHyun Pyun --- .../services/gatt/bt-service-gatt.c | 55 +++++++++------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/bt-service-adaptation/services/gatt/bt-service-gatt.c b/bt-service-adaptation/services/gatt/bt-service-gatt.c index 4e113b5..5bcae15 100644 --- a/bt-service-adaptation/services/gatt/bt-service-gatt.c +++ b/bt-service-adaptation/services/gatt/bt-service-gatt.c @@ -241,7 +241,8 @@ static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info); static void __bt_free_service_info(bt_gatt_service_info_t *service_info); -static int __bt_do_unregister_gatt_instance(int instance_id); +static int __bt_unregister_gatt_client_instance(int client_if); + static void __bt_service_reset_gatt_data(void); #ifdef TIZEN_GATT_CLIENT @@ -299,11 +300,16 @@ static void __bt_handle_server_instance_registered(event_gatts_register_t *data) static void __bt_gatt_event_handler(int event_type, gpointer event_data); +typedef enum { + BT_GATT_SERVER = 1, + BT_GATT_CLIENT, +} bt_gatt_type_e; + void _bt_check_adv_app_termination(const char *name) { bt_service_app_info_t *app = NULL; int k; - int apps[MAX_APPS_SUPPORTED]; + int apps[MAX_APPS_SUPPORTED] = { 0, }; ret_if(NULL == name); @@ -316,7 +322,6 @@ void _bt_check_adv_app_termination(const char *name) if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) { BT_DBG("Match found, name: %s", name); - /* TODO 1: If App has both GATT client / server role? */ /* TODO 2: Need to manage app info as list, not array. This loop always run for MAX count if any apps are terminated. */ @@ -336,20 +341,24 @@ void _bt_check_adv_app_termination(const char *name) _bt_set_advertising(app->sender, app->adv_handle, FALSE, FALSE); } - apps[app->instance_id] = 1; /* App holds a GATT client Instance */ + apps[app->instance_id] = BT_GATT_SERVER; /* App holds a GATT server Instance */ } else if (app->client_id != -1) { /* GATT client */ - apps[app->client_id] = 1; /* App holds a GATT server Instance */ + apps[app->client_id] = BT_GATT_CLIENT; /* App holds a GATT client Instance */ } } } /* Unregister all apps one by one */ for (k = 1; k < MAX_APPS_SUPPORTED; k++) { - if (apps[k] == 1) { - BT_INFO("Unregister app[%d]", k); - /* Unregister client or server instance */ - __bt_do_unregister_gatt_instance(k); + if (apps[k] == BT_GATT_SERVER) { + BT_INFO("Unregister server app[%d]", k); + /* Unregister server instance */ + __bt_unregister_gatt_server_instance(k); + } else if (apps[k] == BT_GATT_CLIENT) { + BT_INFO("Unregister client app[%d]", k); + /* Unregister client instance */ + __bt_unregister_gatt_client_instance(k); } } } @@ -636,36 +645,16 @@ void _bt_get_previous_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int *len, } } -static int __bt_do_unregister_gatt_instance(int instance_id) +static int __bt_unregister_gatt_client_instance(int client_if) { int ret = OAL_STATUS_SUCCESS; int k; - BT_INFO("DeAllocate server or client instance ID [%d]", instance_id); + BT_INFO("DeAllocate client instance ID [%d]", client_if); /* Reset data: instance_id parameter could be either for GATT Server or for GATT client */ for (k = 1; k < MAX_APPS_SUPPORTED; k++) { - if (numapps[k].instance_id == instance_id) { - BT_INFO("This is a GATT server app, unregister: Slot [%d] vacant", k); - numapps[k].is_initialized = FALSE; - numapps[k].instance_id = -1; - numapps[k].adv_handle = 0; - numapps[k].adv_instance = -1; - memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender)); - memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid)); - memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX); - memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX); - numapps[k].adv_data_len = 0; - numapps[k].scan_rsp_len = 0; - - /* Its a GATT Server Instance */ - ret = gatts_unregister(instance_id); - if (ret != OAL_STATUS_SUCCESS) { - BT_ERR("DeAllocate server instance with stack Fail ret: %d", ret); - return BLUETOOTH_ERROR_INTERNAL; - } - break; - } else if (numapps[k].client_id == instance_id) { + if (numapps[k].client_id == client_if) { BT_INFO("This is a GATT client app, unregister: Slot [%d] vacant", k); numapps[k].client_id = -1; numapps[k].is_initialized = FALSE; @@ -674,7 +663,7 @@ static int __bt_do_unregister_gatt_instance(int instance_id) memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t)); /* Its a GATT Client Instance */ - ret = gattc_deregister(instance_id); + ret = gattc_deregister(client_if); if (ret != OAL_STATUS_SUCCESS) { BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret); return BLUETOOTH_ERROR_INTERNAL; -- 2.7.4