From f8ee7e3a44af4dca3cc110b47490a722c9e6bf2c Mon Sep 17 00:00:00 2001 From: Amit Purwar Date: Tue, 19 Jun 2018 15:53:42 +0530 Subject: [PATCH] Fixed zero length data of descriptor read Change-Id: If1fe3d0ed882ae9ab9dc1b9d808f5f45c17d4fc1 Signed-off-by: Amit Purwar --- bt-api/bt-event-handler.c | 6 +- .../services/gatt/bt-service-gatt.c | 84 ++++++++++++---------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index d1d52d5..a435157 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -3646,7 +3646,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 */ diff --git a/bt-service-adaptation/services/gatt/bt-service-gatt.c b/bt-service-adaptation/services/gatt/bt-service-gatt.c index 365bb55..61c4987 100644 --- a/bt-service-adaptation/services/gatt/bt-service-gatt.c +++ b/bt-service-adaptation/services/gatt/bt-service-gatt.c @@ -3462,6 +3462,7 @@ static void __bt_handle_client_descriptor_read_data( if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS) result = BLUETOOTH_ERROR_INTERNAL; else { + BT_INFO("desc data len:", event_data->data_len); if (event_data->data_len > 0) { /* DEBUG */ for (i = 0; i < event_data->data_len; i++) @@ -3475,55 +3476,60 @@ static void __bt_handle_client_descriptor_read_data( read_val, event_data->data_len, TRUE, NULL, NULL); - /* SVC uuid */ - svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len); + } else { + BT_INFO("Descriptor Read success, but no data!!!"); - data_svc_uuid = g_variant_new_from_data( + data = g_variant_new_from_data( G_VARIANT_TYPE_BYTESTRING, - svc_uuid, - 16, - TRUE, NULL, NULL); + NULL, + 0, + FALSE, NULL, NULL); + } + /* SVC uuid */ + svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len); + + data_svc_uuid = g_variant_new_from_data( + G_VARIANT_TYPE_BYTESTRING, + svc_uuid, + 16, + TRUE, NULL, NULL); - /* Char uuid */ - char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len); + /* Char uuid */ + char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len); - data_char_uuid = g_variant_new_from_data( - G_VARIANT_TYPE_BYTESTRING, - char_uuid, - 16, - TRUE, NULL, NULL); + data_char_uuid = g_variant_new_from_data( + G_VARIANT_TYPE_BYTESTRING, + char_uuid, + 16, + TRUE, NULL, NULL); - /* Desc uuid */ - desc_uuid = g_memdup(&event_data->uuid_status.descr_id.uuid.uuid[0], uuid_len); + /* Desc uuid */ + desc_uuid = g_memdup(&event_data->uuid_status.descr_id.uuid.uuid[0], uuid_len); - data_desc_uuid = g_variant_new_from_data( - G_VARIANT_TYPE_BYTESTRING, - desc_uuid, - 16, - TRUE, NULL, NULL); + data_desc_uuid = g_variant_new_from_data( + G_VARIANT_TYPE_BYTESTRING, + desc_uuid, + 16, + TRUE, NULL, NULL); - param = g_variant_new("(isn@ayin@ayin@ayin@ay)", result, - conn_info->addr, - uuid_len, - data_svc_uuid, - event_data->uuid_status.srvc_id.id.inst_id, - 16, - data_char_uuid, - event_data->uuid_status.char_id.inst_id, - 16, - data_desc_uuid, - event_data->uuid_status.descr_id.inst_id, - event_data->data_len, - data); + param = g_variant_new("(isn@ayin@ayin@ayin@ay)", result, + conn_info->addr, + uuid_len, + data_svc_uuid, + event_data->uuid_status.srvc_id.id.inst_id, + 16, + data_char_uuid, + event_data->uuid_status.char_id.inst_id, + 16, + data_desc_uuid, + event_data->uuid_status.descr_id.inst_id, + event_data->data_len, + data); - /* Send Event */ - _bt_send_event(BT_GATT_CLIENT_EVENT, + /* Send Event */ + _bt_send_event(BT_GATT_CLIENT_EVENT, BLUETOOTH_EVENT_GATT_READ_DESC, param); - } else { - BT_ERR("Descriptor Read success, but no data!!!"); - result = BLUETOOTH_ERROR_INTERNAL; - } } BT_INFO("Send DBUS rpely for GATT Read Descriptor"); /* Send DBUS return */ -- 2.7.4