From: h.sandeep Date: Wed, 24 May 2017 00:00:17 +0000 (+0530) Subject: GATT-Clinet: Fix the Write and read dbus reply parameter mismatch. X-Git-Tag: accepted/tizen/unified/20170613.194514~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git;a=commitdiff_plain;h=5290c7434584777940721b761076ee027b9807a3 GATT-Clinet: Fix the Write and read dbus reply parameter mismatch. Change-Id: Id2deb6feca75ba54e39cd5cad8b09a8488562f63 Signed-off-by: h.sandeep --- diff --git a/bt-api/bt-gatt-client.c b/bt-api/bt-gatt-client.c index 9e0f92a..872b21f 100644 --- a/bt-api/bt-gatt-client.c +++ b/bt-api/bt-gatt-client.c @@ -884,6 +884,7 @@ static void __bluetooth_internal_read_cb(GObject *source_object, GByteArray *gp_byte_array = NULL; GVariantIter *iter; guint8 g_byte; + gint att_error_code; int ret = BLUETOOTH_ERROR_NONE; BT_DBG("+"); @@ -910,9 +911,22 @@ static void __bluetooth_internal_read_cb(GObject *source_object, } char_value.char_handle = user_data; - gp_byte_array = g_byte_array_new(); - g_variant_get(value, "(ay)", &iter); + g_variant_get(value, "(yay)", &att_error_code, &iter); + + if (att_error_code != 0) { + if (user_info) { + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_READ_CHAR, + att_error_code, NULL, + user_info->cb, user_info->user_data); + } + g_free(char_value.char_handle); + g_variant_unref(value); + g_variant_iter_free(iter); + return; + } + + gp_byte_array = g_byte_array_new(); while (g_variant_iter_loop(iter, "y", &g_byte)) g_byte_array_append(gp_byte_array, &g_byte, 1); @@ -957,8 +971,8 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *character g_variant_new("q", offset)); /* Device Object path*/ -// g_variant_builder_add(builder, "{sv}", "device", -// g_variant_new_object("o", NULL)); +// g_variant_builder_add(builder, "{sv}", "device", +// g_variant_new_object("o", NULL)); g_dbus_connection_call(conn, BT_BLUEZ_NAME, @@ -966,7 +980,7 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *character GATT_CHAR_INTERFACE, "ReadValue", g_variant_new("(a{sv})", builder), - G_VARIANT_TYPE("(ay)"), + G_VARIANT_TYPE("(yay)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, @@ -977,6 +991,48 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *character return BLUETOOTH_ERROR_NONE; } +static void __bluetooth_internal_write_cb(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + bt_user_info_t *user_info; + GDBusConnection *system_gconn = NULL; + GVariant *value; + int result = BLUETOOTH_ERROR_NONE; + guint8 att_ecode = 0; + + user_info = _bt_get_user_data(BT_COMMON); + + system_gconn = _bt_gdbus_get_system_gconn(); + value = g_dbus_connection_call_finish(system_gconn, res, &error); + + if (error) { + BT_ERR("Error : %s \n", error->message); + g_clear_error(&error); + result = BLUETOOTH_ERROR_INTERNAL; + } else { + g_variant_get(value, "(y)", &att_ecode); + if (att_ecode) { + result = att_ecode; + BT_ERR("ATT Error code: %d \n", att_ecode); + } + } + + if (user_info) { + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_WRITE_CHAR, + result, NULL, + user_info->cb, user_info->user_data); + } else { + BT_ERR("user info is null"); + } + + if (value) + g_variant_unref(value); + + return; +} + BT_EXPORT_API int bluetooth_gatt_set_characteristics_value( const char *char_handle, const guint8 *value, int length) { @@ -1009,20 +1065,24 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value( g_variant_new_uint16(offset)); /* Device Object path*/ -// g_variant_builder_add(builder2, "{sv}", "device", -// g_variant_new_object("o", NULL)); +// g_variant_builder_add(builder2, "{sv}", "device", +// g_variant_new_object("o", NULL)); options = g_variant_new("a{sv}", builder2); - g_dbus_connection_call_sync(conn, - BT_BLUEZ_NAME, - char_handle, - GATT_CHAR_INTERFACE, - "WriteValue", - g_variant_new("(@ay@a{sv})", val, options), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); + g_dbus_connection_call(conn, + BT_BLUEZ_NAME, + char_handle, + GATT_CHAR_INTERFACE, + "WriteValue", + g_variant_new("(@ay@a{sv})", + val, options), + G_VARIANT_TYPE("(y)"), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, + (GAsyncReadyCallback)__bluetooth_internal_write_cb, + NULL); + if (error) { BT_ERR("Set value Failed: %s", error->message); @@ -1037,48 +1097,6 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value( return BLUETOOTH_ERROR_NONE; } -static void __bluetooth_internal_write_cb(GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - GError *error = NULL; - bt_user_info_t *user_info; - GDBusConnection *system_gconn = NULL; - GVariant *value; - int result = BLUETOOTH_ERROR_NONE; - guint8 att_ecode = 0; - - user_info = _bt_get_user_data(BT_COMMON); - - system_gconn = _bt_gdbus_get_system_gconn(); - value = g_dbus_connection_call_finish(system_gconn, res, &error); - - if (error) { - BT_ERR("Error : %s \n", error->message); - g_clear_error(&error); - result = BLUETOOTH_ERROR_INTERNAL; - } else { - g_variant_get(value, "(y)", &att_ecode); - if (att_ecode) { - result = att_ecode; - BT_ERR("ATT Error code: %d \n", att_ecode); - } - } - - if (user_info) { - _bt_common_event_cb(BLUETOOTH_EVENT_GATT_WRITE_CHAR, - result, NULL, - user_info->cb, user_info->user_data); - } else { - BT_ERR("user info is null"); - } - - if (value) - g_variant_unref(value); - - return; -} - BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_by_type( const char *char_handle, const guint8 *value, int length, guint8 write_type) { @@ -1111,8 +1129,8 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_by_type( g_variant_new_uint16(offset)); /* Device Object path*/ -// g_variant_builder_add(builder2, "{sv}", "device", -// g_variant_new_object("o", NULL)); +// g_variant_builder_add(builder2, "{sv}", "device", +// g_variant_new_object("o", NULL)); options = g_variant_new("a{sv}", builder2); @@ -1168,8 +1186,8 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_request( g_variant_new_uint16(offset)); /* Device Object path*/ -// g_variant_builder_add(builder2, "{sv}", "device", -// g_variant_new_object("o", NULL)); +// g_variant_builder_add(builder2, "{sv}", "device", +// g_variant_new_object("o", NULL)); options = g_variant_new("a{sv}", builder2); @@ -1180,7 +1198,7 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_request( "WriteValue", g_variant_new("(@ay@a{sv})", val, options), - NULL, + G_VARIANT_TYPE("(y)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback)__bluetooth_internal_write_cb, @@ -1411,6 +1429,7 @@ static void __bluetooth_internal_read_desc_cb(GObject *source_object, GByteArray *gp_byte_array = NULL; GVariantIter *iter; guint8 g_byte; + gint att_error_code; BT_DBG("+"); user_info = _bt_get_user_data(BT_COMMON); @@ -1431,9 +1450,21 @@ static void __bluetooth_internal_read_desc_cb(GObject *source_object, return; } - gp_byte_array = g_byte_array_new(); - g_variant_get(value, "(ay)", &iter); + g_variant_get(value, "(yay)", &att_error_code, &iter); + + if (att_error_code != 0) { + if (user_info) { + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_READ_DESC, + att_error_code, NULL, + user_info->cb, user_info->user_data); + } + g_free(char_value.handle); + g_variant_unref(value); + g_variant_iter_free(iter); + return; + } + gp_byte_array = g_byte_array_new(); while (g_variant_iter_loop(iter, "y", &g_byte)) g_byte_array_append(gp_byte_array, &g_byte, 1); @@ -1487,7 +1518,7 @@ BT_EXPORT_API int bluetooth_gatt_read_descriptor_value(const char *char_descript GATT_DESC_INTERFACE, "ReadValue", g_variant_new("(a{sv})", builder), - G_VARIANT_TYPE("(ay)"), + G_VARIANT_TYPE("(yay)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, @@ -1572,8 +1603,8 @@ BT_EXPORT_API int bluetooth_gatt_write_descriptor_value( g_variant_new_uint16(offset)); /* Device Object path*/ -// g_variant_builder_add(builder2, "{sv}", "device", -// g_variant_new_object("o", NULL)); +// g_variant_builder_add(builder2, "{sv}", "device", +// g_variant_new_object("o", NULL)); options = g_variant_new("a{sv}", builder2);