From a54217ac66b8270fa93dc75accb334a53dfb9c42 Mon Sep 17 00:00:00 2001 From: "injun.yang" Date: Tue, 2 Jan 2018 15:14:07 +0900 Subject: [PATCH] Enhance debug message When ATT error occured, display gatt handler Change-Id: I7bd5e3bf7ba675bb58e8b65b2b24b649eead0e76 --- bt-api/bt-common.c | 1 + bt-api/bt-gatt-client.c | 36 ++++++++++++++++++++++-------------- bt-service/bt-service-common.c | 1 + include/bluetooth-api.h | 1 + 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index 7c2d5b9..6779baf 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -2152,6 +2152,7 @@ BT_EXPORT_API int bluetooth_get_uuid_name(const char *uuid, char **name) {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"}, {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"}, {"1ab7c24d-185a-45b9-90d4-f7ab1a71949a", "Samsung Health Service"}, + {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"}, {NULL, NULL} }; diff --git a/bt-api/bt-gatt-client.c b/bt-api/bt-gatt-client.c index dfca5e9..555a266 100644 --- a/bt-api/bt-gatt-client.c +++ b/bt-api/bt-gatt-client.c @@ -892,13 +892,13 @@ BT_EXPORT_API int bluetooth_gatt_get_char_descriptor_property( return BLUETOOTH_ERROR_NONE; } -static int __bluetooth_get_att_error_code(GError *error) +static int __bluetooth_get_att_error_code(GError *error, char *handle) { int att_ecode = 0; int len; char *str = NULL; - BT_ERR("Error : %s", error->message); + BT_ERR("Error : %s [%s]", error->message, handle + 15); str = g_strrstr(error->message, "ATT error: 0x"); if (str) { len = strlen(str); @@ -956,18 +956,19 @@ static void __bluetooth_internal_read_cb(GObject *source_object, user_info = _bt_get_user_data(BT_COMMON); if (!user_info) { - g_free(resp_data); if (error) { - BT_ERR("Error : %s", error->message); + BT_ERR("Error : %s [%s]", error->message, resp_data->handle + 15); g_clear_error(&error); + g_free(resp_data); return; } + g_free(resp_data); g_variant_unref(value); return; } if (error) { - att_ecode = __bluetooth_get_att_error_code(error); + att_ecode = __bluetooth_get_att_error_code(error, resp_data->handle); g_clear_error(&error); _bt_common_event_cb(BLUETOOTH_EVENT_GATT_READ_CHAR, @@ -1016,6 +1017,7 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *chr, resp_data = g_malloc0(sizeof(bt_gatt_resp_data_t)); resp_data->user_data = user_data; + resp_data->handle = (char *)chr; builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); @@ -1052,18 +1054,19 @@ static void __bluetooth_internal_write_cb(GObject *source_object, user_info = _bt_get_user_data(BT_COMMON); if (!user_info) { - g_free(resp_data); if (error) { - BT_ERR("Error : %s", error->message); + BT_ERR("Error : %s [%s]", error->message, resp_data->handle + 15); g_clear_error(&error); + g_free(resp_data); return; } + g_free(resp_data); g_variant_unref(value); return; } if (error) { - att_ecode = __bluetooth_get_att_error_code(error); + att_ecode = __bluetooth_get_att_error_code(error, resp_data->handle); g_clear_error(&error); _bt_common_event_cb(BLUETOOTH_EVENT_GATT_WRITE_CHAR, @@ -1187,6 +1190,7 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_by_type( resp_data = g_malloc0(sizeof(bt_gatt_resp_data_t)); resp_data->user_data = user_data; + resp_data->handle = (char *)chr; g_dbus_connection_call(conn, BT_BLUEZ_NAME, chr, GATT_CHAR_INTERFACE, "WriteValuebyType", @@ -1489,18 +1493,19 @@ static void __bluetooth_internal_read_desc_cb(GObject *source_object, user_info = _bt_get_user_data(BT_COMMON); if (!user_info) { - g_free(resp_data); if (error) { - BT_ERR("Error : %s", error->message); + BT_ERR("Error : %s [%s]", error->message, resp_data->handle + 15); g_clear_error(&error); + g_free(resp_data); return; } + g_free(resp_data); g_variant_unref(value); return; } if (error) { - att_ecode = __bluetooth_get_att_error_code(error); + att_ecode = __bluetooth_get_att_error_code(error, resp_data->handle); g_clear_error(&error); _bt_common_event_cb(BLUETOOTH_EVENT_GATT_READ_DESC, @@ -1552,6 +1557,7 @@ BT_EXPORT_API int bluetooth_gatt_read_descriptor_value(const char *desc, resp_data = g_malloc0(sizeof(bt_gatt_resp_data_t)); resp_data->user_data = user_data; + resp_data->handle = (char *)desc; builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); @@ -1591,18 +1597,19 @@ static void __bluetooth_internal_write_desc_cb(GObject *source_object, user_info = _bt_get_user_data(BT_COMMON); if (!user_info) { - g_free(resp_data); if (error) { - BT_ERR("Error : %s", error->message); + BT_ERR("Error : %s [%s]", error->message, resp_data->handle + 15); g_clear_error(&error); + g_free(resp_data); return; } + g_free(resp_data); g_variant_unref(value); return; } if (error) { - att_ecode = __bluetooth_get_att_error_code(error); + att_ecode = __bluetooth_get_att_error_code(error, resp_data->handle); g_clear_error(&error); _bt_common_event_cb(BLUETOOTH_EVENT_GATT_WRITE_DESC, @@ -1662,6 +1669,7 @@ BT_EXPORT_API int bluetooth_gatt_write_descriptor_value(const char *desc, resp_data = g_malloc0(sizeof(bt_gatt_resp_data_t)); resp_data->user_data = user_data; + resp_data->handle = (char *)desc; g_dbus_connection_call(conn, BT_BLUEZ_NAME, desc, GATT_DESC_INTERFACE, "WriteValue", g_variant_new("(@ay@a{sv})", diff --git a/bt-service/bt-service-common.c b/bt-service/bt-service-common.c index 385910c..eb17e87 100644 --- a/bt-service/bt-service-common.c +++ b/bt-service/bt-service-common.c @@ -941,6 +941,7 @@ const char *_bt_convert_uuid_to_string(const char *uuid) {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"}, {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"}, {"1ab7c24d-185a-45b9-90d4-f7ab1a71949a", "Samsung Health Service"}, + {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"}, {NULL, NULL} }; diff --git a/include/bluetooth-api.h b/include/bluetooth-api.h index 8286f5c..47d1a3e 100644 --- a/include/bluetooth-api.h +++ b/include/bluetooth-api.h @@ -1645,6 +1645,7 @@ typedef struct { * Structure for GATT response data */ typedef struct { + char *handle; guint8 *value; guint32 len; gpointer user_data; -- 2.7.4