Increases the number of gatt attributes 55/249955/2
authorWootak Jung <wootak.jung@samsung.com>
Fri, 18 Dec 2020 00:13:03 +0000 (09:13 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Fri, 18 Dec 2020 00:22:05 +0000 (09:22 +0900)
There is a conflict in att handle number
in case many characteristics are added like below

/com/1/service11/characteristic22/descriptor33
/com/1/service15/characteristic33

Change-Id: I30c79e9ca9588a6b65648797b9dee42b867cbd85
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-oal/bluez_hal/src/bt-hal-gatt-server.c

index 6336fbf..2f093c3 100644 (file)
@@ -65,9 +65,12 @@ static GDBusNodeInfo *manager_node_info = NULL;
 static guint manager_id;
 
 /* Global handles which needs to be incremented during each addition */
-static int gatt_service_handle = 10;
-static int gatt_char_handle = 20;
-static int gatt_desc_handle = 30;
+#define SERVICE_HANDLE_NUM 100
+#define CHAR_HANDLE_NUM 200
+#define DESC_HANDLE_NUM 300
+static int gatt_service_handle = SERVICE_HANDLE_NUM;
+static int gatt_char_handle = CHAR_HANDLE_NUM;
+static int gatt_desc_handle = DESC_HANDLE_NUM;
 
 struct gatt_service_info {
        gchar *serv_path;
@@ -2160,16 +2163,21 @@ static int __bt_hal_add_service_to_dbus(char *app_path, int slot, btgatt_srvc_id
        hal_gatt_service_added *user_data = NULL;
        DBG("Service add to DBUS slot [%d]", slot);
 
-       node_info = __bt_gatt_create_method_node_info(
-                       service_introspection_xml);
-
-       if (node_info == NULL)
-               return BT_STATUS_FAIL;
-
        DBG("Add new GATT Service: Current GATT Service handle [%d]", gatt_service_handle);
+       if (gatt_service_handle >= CHAR_HANDLE_NUM) {
+               ERR("Exceeded the number of service");
+               return BT_STATUS_FAIL;
+       }
        path = g_strdup_printf("%s"GATT_SERV_OBJECT_PATH"%d", app_path, ++gatt_service_handle);
        DBG("gatt service path is [%s]", path);
 
+       node_info = __bt_gatt_create_method_node_info(
+                       service_introspection_xml);
+       if (node_info == NULL) {
+               g_free(path);
+               return BT_STATUS_FAIL;
+       }
+
        object_id = g_dbus_connection_register_object(g_conn, path,
                        node_info->interfaces[0],
                        &serv_interface_vtable,
@@ -2535,16 +2543,21 @@ static bt_status_t gatt_server_add_characteristic(int slot, int service_handle,
        if (serv_info == NULL)
                return BT_STATUS_FAIL;
 
-       node_info = __bt_gatt_create_method_node_info(
-                       characteristics_introspection_xml);
-
-       if (node_info == NULL)
-               return BT_STATUS_FAIL;
-
        DBG("Add new GATT characteristic: Current GATT char handle [%d]", gatt_char_handle);
+       if (gatt_char_handle >= DESC_HANDLE_NUM) {
+               ERR("Exceeded the number of characteristic");
+               return BT_STATUS_FAIL;
+       }
        path = g_strdup_printf("%s/characteristic%d", serv_info->serv_path, ++gatt_char_handle);
        DBG("gatt characteristic path is [%s]", path);
 
+       node_info = __bt_gatt_create_method_node_info(
+                       characteristics_introspection_xml);
+       if (node_info == NULL) {
+               g_free(path);
+               return BT_STATUS_FAIL;
+       }
+
        app_id = g_malloc0(sizeof(int));
        *app_id = slot;