Fixed disable notification for acquire notification
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-event-handler.c
index d1d52d5..105d1cc 100644 (file)
@@ -34,6 +34,7 @@
 #include "bt-event-handler.h"
 #include "bt-gatt-client.h"
 #include "bt-request-sender.h"
+#include "bt-gatt-server.h"
 
 #define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
 #define BT_RELIABLE_DISABLE_TIME 300 /* 300 ms */
@@ -2124,7 +2125,7 @@ void __bt_map_client_event_filter(GDBusConnection *connection,
 
                folders_struct.size = g_variant_iter_n_children(iter);
                folders_struct.names = (char**) g_malloc0(folders_struct.size * sizeof(*(folders_struct.names)));
-               BT_DBG("g_variant_iter_n_children: %d", folders_struct.size);
+               BT_DBG("g_variant_iter_n_children: %lli", (long long int)folders_struct.size);
                GVariantIter* res = NULL;
                int i = 0;
                while (g_variant_iter_loop(iter, "a{sv}", &res)) {
@@ -2209,7 +2210,7 @@ void __bt_map_client_event_filter(GDBusConnection *connection,
                messages_struct.size = g_variant_iter_n_children(iter);
                messages_struct.message_items = (bt_map_client_message_item_t*)
                        g_malloc(messages_struct.size * sizeof(*(messages_struct.message_items)));
-               BT_DBG("g_variant_iter_n_children: %d", messages_struct.size);
+               BT_DBG("g_variant_iter_n_children: %lli", (long long int)messages_struct.size);
 
                char *object = NULL;
                GVariantIter *properites = NULL;
@@ -2279,7 +2280,7 @@ void __bt_map_client_event_filter(GDBusConnection *connection,
                                } else if (strcmp(key, "Size") == 0) {
                                        g_variant_get(value, "t", &value_int);
                                        messages_struct.message_items[i].size = value_int;
-                                       BT_DBG("  Size: %d", value_int);
+                                       BT_DBG("  Size: %llu", (unsigned long long int)value_int);
                                } else if (strcmp(key, "Text") == 0) {
                                        g_variant_get(value, "b", &value_bool);
                                        messages_struct.message_items[i].is_text = value_bool ? 1 : 0;
@@ -2291,7 +2292,7 @@ void __bt_map_client_event_filter(GDBusConnection *connection,
                                } else if (strcmp(key, "AttachmentSize") == 0) {
                                        g_variant_get(value, "t", &value_int);
                                        messages_struct.message_items[i].attachment_size = value_int;
-                                       BT_DBG("  AttachmentSize: %d", value_int);
+                                       BT_DBG("  AttachmentSize: %llu", (unsigned long long int)value_int);
                                } else if (strcmp(key, "Priority") == 0) {
                                        g_variant_get(value, "b", &value_bool);
                                        messages_struct.message_items[i].is_priority = value_bool ? 1 : 0;
@@ -2477,7 +2478,7 @@ void __bt_pbap_client_event_filter(GDBusConnection *connection,
                for (i = 0; i < count; i++)
                        BT_DBG("%s", list[i]);
 
-               BT_DBG("address: %s, result: %d, count: %d, success: %d",
+               BT_DBG("address: %s, result: %d, count: %zd, success: %d",
                                        address, result, count, success);
 
                _bt_convert_addr_string_to_type(vc_list.btaddr.addr,
@@ -3507,10 +3508,17 @@ static void __bt_gatt_client_event_filter(GDBusConnection *connection,
                BT_INFO("GATT Client Char value changed in remote Server [%s]", address);
                BT_INFO("GATT Client Char Val len: [%d]", char_prop.val_len);
 
-               /* Copy Data */
-               memcpy(&char_prop.value, g_variant_get_data(data_var), char_prop.val_len);
+               if (char_prop.val_len > 0) {
+                       /* Copy Data */
+                       memcpy(&char_prop.value, g_variant_get_data(data_var), char_prop.val_len);
+               }
+
                memcpy(&char_prop.prop.uuid, g_variant_get_data(char_uuid_var), 16);
 
+               /* Copy SVC data */
+               memcpy(&char_prop.svc_prop.uuid, g_variant_get_data(svc_uuid_var), 16);
+               char_prop.svc_prop.instance_id = svc_inst;
+
                /* DEBUG */
                for (i = 0; i < char_prop.val_len; i++)
                        BT_INFO("Data[%d] = [0x%x]", i, char_prop.value[i]);
@@ -3646,7 +3654,11 @@ static void __bt_gatt_client_event_filter(GDBusConnection *connection,
                BT_DBG("GATT Client Descriptor Val len: [%d]", desc_prop.val_len);
 
                /* Copy Data */
-               memcpy(&desc_prop.value, g_variant_get_data(data_var), desc_prop.val_len);
+               if (desc_prop.val_len > 0) {
+                       BT_INFO("Get the desc read data");
+                       memcpy(&desc_prop.value, g_variant_get_data(data_var), desc_prop.val_len);
+               }
+
                memcpy(&desc_prop.prop.uuid, g_variant_get_data(desc_uuid_var), 16);
 
                /* Copy Char Data */
@@ -3834,7 +3846,15 @@ static void __bt_gatt_server_event_filter(GDBusConnection *connection,
                _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
                                result, &read_info,
                                event_info->cb, event_info->user_data);
-       } else if (strcasecmp(signal_name, BT_GATT_SERVER_NOTIFICATION_COMPLETED) == 0) {
+       } else if (strcasecmp(signal_name, BT_GATT_SERVER_ACQUIRE_WRITE) == 0) {
+
+               bluetooth_gatt_server_send_acquire_write_response(parameters);
+
+       } else if (strcasecmp(signal_name, BT_GATT_SERVER_ACQUIRE_NOTIFICATION) == 0) {
+
+               bluetooth_gatt_server_send_acquire_notify_response(parameters, event_info);
+
+       }  else if (strcasecmp(signal_name, BT_GATT_SERVER_NOTIFICATION_COMPLETED) == 0) {
                const char *address = NULL;
                bluetooth_device_address_t dev_address = { {0} };
                bluetooth_gatt_server_indicate_confirmed_info_t info;
@@ -3878,6 +3898,9 @@ static void __bt_gatt_server_event_filter(GDBusConnection *connection,
                BT_INFO("GATT Server: Notification Enabled?? Handle: [%d] address [%s] Is Enabled [%d] result [%d]",
                                info.handle, address, info.notification, result);
 
+               if (info.notification == FALSE)
+                       cleanup_gatt_acquire_fd(info.handle);
+
                _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
                                result, &info,
                                event_info->cb, event_info->user_data);
@@ -4017,7 +4040,7 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       connection_type = _bt_gdbus_get_system_gconn();
+       connection_type = _bt_get_system_private_conn();
        if (connection_type == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -4058,7 +4081,7 @@ int _bt_unregister_event(int event_type)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       connection_type = _bt_gdbus_get_system_gconn();
+       connection_type = _bt_get_system_private_conn();
 
        event_list = g_slist_remove(event_list, (void *)cb_data);
 
@@ -4106,7 +4129,7 @@ void _bt_register_name_owner_changed(void)
 {
        GDBusConnection *connection_type;
 
-       connection_type = _bt_gdbus_get_system_gconn();
+       connection_type = _bt_get_system_private_conn();
        if (connection_type == NULL) {
                BT_ERR("Unable to get the bus");
                return;
@@ -4121,7 +4144,7 @@ void _bt_unregister_name_owner_changed(void)
 {
        GDBusConnection *connection_type;
 
-       connection_type = _bt_gdbus_get_system_gconn();
+       connection_type = _bt_get_system_private_conn();
        if (connection_type != NULL && owner_sig_id > 0) {
                g_dbus_connection_signal_unsubscribe(connection_type,
                                                        owner_sig_id);
@@ -4137,11 +4160,11 @@ static void __bt_gatt_get_uuid_from_path(char *path, char **service_uuid)
        GVariant *ret = NULL;
        GVariant *value = NULL;
 
-       g_conn = _bt_gdbus_get_system_gconn();
+       g_conn = _bt_get_system_private_conn();
        ret_if(g_conn == NULL);
 
        proxy = g_dbus_proxy_new_sync(g_conn,
-                               G_DBUS_PROXY_FLAGS_NONE, NULL,
+                               G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
                                BT_BLUEZ_NAME,
                                path,
                                BT_PROPERTIES_INTERFACE,
@@ -4259,7 +4282,7 @@ int _bt_register_manager_subscribe_signal(gboolean subscribe)
        static guint service_added_id = 0;
        static guint interface_removed_id = 0;
 
-       g_conn = _bt_gdbus_get_system_gconn();
+       g_conn = _bt_get_system_private_conn();
        if (g_conn == NULL)
                return BLUETOOTH_ERROR_INTERNAL;