Fix gatt info index mismatch issue 44/237944/1
authorWootak Jung <wootak.jung@samsung.com>
Tue, 7 Jul 2020 00:55:50 +0000 (09:55 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 7 Jul 2020 01:05:02 +0000 (10:05 +0900)
numapps index is not instance id

Change-Id: I771e4c63596ef385973bc3864c94d75a59693d2b
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-service/services/gatt/bt-service-gatt.c

index 59c5867..500b004 100644 (file)
@@ -779,13 +779,13 @@ int _bt_unregister_server_instance(const char *sender, int adv_handle)
        int apps[MAX_APPS_SUPPORTED];
        int server_instance;
        int k;
+       bt_service_app_info_t *info = NULL;
 
        memset(&apps, -1, sizeof(apps));
 
        if (adv_handle == 0) {
                BT_DBG("Its a direct GATT Server app request to unregister");
                /* Unregister server instance for each app with same sender (case: GATT Server with multiple adv handle) */
-               bt_service_app_info_t *info = NULL;
 
                for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
                        info = &numapps[k];
@@ -813,18 +813,24 @@ int _bt_unregister_server_instance(const char *sender, int adv_handle)
                        BT_ERR("No allocated server instance to be removed");
                        return BLUETOOTH_ERROR_INVALID_PARAM;
                }
-               if (!numapps[server_instance].service_handles) {
-                       BT_INFO("There are no Service handles with this app, safe to unregister");
-                       /* Unregister server instance only if this sender does not have any gatt services in it */
-                       result = __bt_unregister_gatt_server_instance(server_instance);
-               } else {
-                       numapps[server_instance].adv_handle = 0;
-                       memset(numapps[server_instance].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
-                       numapps[server_instance].adv_data_len = 0;
-                       memset(numapps[server_instance].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
-                       numapps[server_instance].scan_rsp_len = 0;
+
+               for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
+                       info = &numapps[k];
+                       if (info->instance_id == server_instance) {
+                               if (info->service_handles == NULL) {
+                                       BT_INFO("There are no Service handles with this app, safe to unregister");
+                                       /* Unregister server instance only if this sender does not have any gatt services in it */
+                                       result = __bt_unregister_gatt_server_instance(server_instance);
+                               } else {
+                                       info->adv_handle = 0;
+                                       memset(info->adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
+                                       info->adv_data_len = 0;
+                                       memset(info->scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
+                                       info->scan_rsp_len = 0;
+                               }
+                               return result;
+                       }
                }
-               return result;
        }
 
        /* Unregister all apps one by one */
@@ -2370,6 +2376,8 @@ int _bt_gatt_server_delete_service(char *sender, int service_handle, int instanc
        int ret = OAL_STATUS_SUCCESS;
        GSList *l;
        int *handle = NULL;
+       int k;
+       bt_service_app_info_t *info = NULL;
 
        ret = gatts_delete_service(instance_id, service_handle);
        if (ret != OAL_STATUS_SUCCESS) {
@@ -2378,14 +2386,20 @@ int _bt_gatt_server_delete_service(char *sender, int service_handle, int instanc
        }
 
        /* Remove the Service Handle */
-       for (l = numapps[instance_id].service_handles; l != NULL;) {
-               handle = l->data;
-               l = g_slist_next(l);
-               if (handle && *handle == service_handle) {
-                       BT_INFO("Remove Service handle [%d]", *handle);
-                       numapps[instance_id].service_handles = g_slist_remove(numapps[instance_id].service_handles, handle);
-                       g_free(handle);
-                       handle = NULL;
+       for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
+               info = &numapps[k];
+               if (info->instance_id == instance_id) {
+                       for (l = info->service_handles; l != NULL; ) {
+                               handle = l->data;
+                               l = g_slist_next(l);
+                               if (handle && *handle == service_handle) {
+                                       BT_INFO("Remove Service handle [%d]", *handle);
+                                       info->service_handles = g_slist_remove(info->service_handles, handle);
+                                       g_free(handle);
+                                       handle = NULL;
+                               }
+                       }
+                       break;
                }
        }