Fix issue where StartNotify method comes before gatt connected 11/321311/1 accepted/tizen/unified/20250320.120245 accepted/tizen/unified/x/20250320.221634
authorSohyeon Choi <shss.choi@samsung.com>
Tue, 18 Mar 2025 05:27:42 +0000 (14:27 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 18 Mar 2025 23:54:51 +0000 (08:54 +0900)
Change-Id: I1ecbb81d92473145f16a081b08564772363d2e31
Signed-off-by: Sohyeon Choi <shss.choi@samsung.com>
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-oal/bluez_hal/src/bt-hal-gatt-server.c

index d394ab557f09aa6975b4f4624c6ea4f8c61a1b40..2ed3828a67d59edd0033dadfa9140585d339c13c 100644 (file)
@@ -222,6 +222,7 @@ static GSList * hal_gatts_server_register_list;
 static int assigned_id = 0;
 static gboolean instance_id_used[BT_GATTS_MAX];
 static guint manager_id[BT_GATTS_MAX];
+static int start_notify_pending_count = 0;
 static int acquire_notify_pending_count = 0;
 static int write_value_pending_count = 0;
 
@@ -1449,9 +1450,31 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
 
                conn_info = __bt_find_remote_gatt_client_info(addr);
+               if (conn_info == NULL) {
+                       ERR("Client info not found. This method call will be called again shortly");
+                       if (start_notify_pending_count > 5) {
+                               ERR("Client info still not found (count %d). Ignoring this method call", start_notify_pending_count);
+                               start_notify_pending_count = 0;
+                               goto done;
+                       }
 
-               if (svc_info == NULL || conn_info == NULL
-                       || event_cb == NULL)
+                       struct method_call_info *info = g_malloc0(sizeof(struct method_call_info));
+                       info->connection = connection;
+                       info->sender = g_strdup(sender);
+                       info->object_path = g_strdup(object_path);
+                       info->interface_name = g_strdup(interface_name);
+                       info->method_name = g_strdup(method_name);
+                       info->parameters = g_variant_ref(parameters);
+                       info->invocation = invocation;
+                       info->user_data = user_data;
+
+                       g_timeout_add(100, __bt_pending_method_call, info);
+                       start_notify_pending_count++;
+                       return;
+               }
+               start_notify_pending_count = 0;
+
+               if (svc_info == NULL || event_cb == NULL)
                        return;
 
                /* Send HAL event */
@@ -1712,6 +1735,8 @@ static gboolean __bt_pending_method_call(gpointer data)
        struct method_call_info *info = data;
 
        DBG("The method call was called again");
+       if (g_strcmp0(info->method_name, "StartNotify") == 0)
+               DBG("StartNotify pending count [%d]", start_notify_pending_count);
        if (g_strcmp0(info->method_name, "WriteValue") == 0)
                DBG("WriteValue pending count [%d]", write_value_pending_count);
        if (g_strcmp0(info->method_name, "AcquireNotify") == 0)