From faabf05e0fb5570b549a09ab997aa55e77bbf828 Mon Sep 17 00:00:00 2001 From: Amit Purwar Date: Tue, 26 Jun 2018 12:35:28 +0530 Subject: [PATCH] Handled multiple gatt char with same uuid in a service Change-Id: Ib0eeeea41a002d5eccde82e75e09f9e1fc75b069 Signed-off-by: Amit Purwar --- bt-oal/bluez_hal/src/bt-hal-gatt-client.c | 144 ++++++++++++--------- .../services/gatt/bt-service-gatt.c | 3 +- 2 files changed, 88 insertions(+), 59 deletions(-) diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-client.c b/bt-oal/bluez_hal/src/bt-hal-gatt-client.c index c30f3f3..568d737 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-client.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-client.c @@ -138,7 +138,6 @@ typedef struct { /* Linked list of connected GATT client connection */ static GSList * hal_gattc_client_info_list = NULL; - static bt_pending_le_conn_info_s *pending_le_conn_info = NULL; static guint pending_le_conn_timer_id = 0; static int bt_conn_id = 0; @@ -543,7 +542,8 @@ static hal_gattc_service_t* _gattc_find_service_from_uuid(hal_gattc_server_info_ } -static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_svc, bt_uuid_t *char_uuid) +static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_svc, bt_uuid_t *char_uuid, + bt_gatt_characteristic_property_t prop) { DBG("+"); @@ -555,7 +555,8 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_s if (info == NULL) continue; - if (!memcmp(&info->chr_uuid, char_uuid, sizeof(bt_uuid_t))) { + if (!memcmp(&info->chr_uuid, char_uuid, sizeof(bt_uuid_t)) && + (info->permission & prop)) { INFO("Found GATT char uuid"); return info; } @@ -1245,6 +1246,7 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id, hal_gattc_server_info_t * conn_info = NULL; hal_gattc_service_t *gattc_service = NULL; GSList *l; + GSList *m; hal_gattc_char_t *gattc_char = NULL; hal_gattc_desc_t *gattc_desc = NULL; char svc_uuid_str[BT_HAL_UUID_STRING_LEN]; @@ -1271,26 +1273,33 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id, DBG("service uuid [%s]", svc_uuid_str); /* find characteristics */ - gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid); - if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); - return BT_STATUS_FAIL; - } + /* a service can have two char with same uuid */ + for (l = gattc_service->gatt_list_chars; l != NULL; l = g_slist_next(l)) { + gattc_char = (hal_gattc_char_t*)l->data; + if (gattc_char == NULL) + continue; - DBG("char path [%s]", gattc_char->chr_path); - _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + if (!memcmp(&gattc_char->chr_uuid, &char_id->uuid, sizeof(bt_uuid_t))) { + INFO("Found GATT char uuid"); + DBG("char path [%s]", gattc_char->chr_path); + _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); + DBG("char uuid [%s]", char_uuid_str); + + /* get descriptor uuid */ + for (m = gattc_char->gatt_list_descs; m != NULL; m = g_slist_next(m)) { + gattc_desc = (hal_gattc_desc_t *)m->data; + if (gattc_desc == NULL) + continue; - /* get descriptor uuid */ - for (l = gattc_char->gatt_list_descs; l != NULL; l = g_slist_next(l)) { - gattc_desc = (hal_gattc_desc_t *)l->data; - status = _hal_gattc_get_descriptor_info(gattc_desc); + status = _hal_gattc_get_descriptor_info(gattc_desc); - /* send event */ - if (BT_STATUS_SUCCESS == status) { - DBG("Sending the success descriptor event"); - _bt_hal_send_client_desc_search_result_event(conn_id, status, srvc_id, - char_id, &gattc_desc->desc_uuid); + /* send event */ + if (BT_STATUS_SUCCESS == status) { + DBG("Sending the success descriptor event"); + _bt_hal_send_client_desc_search_result_event(conn_id, status, srvc_id, + char_id, &gattc_desc->desc_uuid); + } + } } } @@ -1445,7 +1454,8 @@ static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t /* find characteristic */ - gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid); + gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid, + HAL_GATT_CHARACTERISTIC_PROPERTY_READ); if (NULL == gattc_char) { DBG("Failed to get the gatt char"); return BT_STATUS_FAIL; @@ -1561,14 +1571,14 @@ static void __hal_bluetooth_internal_write_cb(GObject *source_object, DBG("-"); } -static bt_status_t __hal_get_write_prop(hal_gatt_write_type_t type, hal_gatt_property_e *prop) +static bt_status_t __hal_get_write_prop(hal_gatt_write_type_t type, bt_gatt_characteristic_property_t *prop) { switch (type) { case HAL_GATT_WRITE_TYPE_WRITE: - *prop = HAL_GATT_PROPERTY_WRITE; + *prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE; break; case HAL_GATT_WRITE_TYPE_WRITE_NO_RESPONSE: - *prop = HAL_GATT_PROPERTY_WRITE_WITHOUT_RESPONSE; + *prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE_NO_RESPONSE; break; default: ERR("Unknow write type : %d", type); @@ -1594,7 +1604,7 @@ static bt_status_t _hal_write_characteristic_value(int conn_id, btgatt_srvc_id_t char svc_uuid_str[BT_HAL_UUID_STRING_LEN]; char char_uuid_str[BT_HAL_UUID_STRING_LEN]; char* char_handle = NULL; - hal_gatt_property_e write_prop = HAL_GATT_PROPERTY_WRITE; + bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE; int ret = BT_STATUS_SUCCESS; DBG("+"); @@ -1624,7 +1634,7 @@ static bt_status_t _hal_write_characteristic_value(int conn_id, btgatt_srvc_id_t DBG("service uuid [%s]", svc_uuid_str); /* find characteristic */ - gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid); + gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid, write_prop); if (NULL == gattc_char) { DBG("Failed to get the gatt char"); return BT_STATUS_FAIL; @@ -1793,6 +1803,7 @@ static bt_status_t _hal_read_descriptor_value(int conn_id, btgatt_srvc_id_t *srv char char_uuid_str[BT_HAL_UUID_STRING_LEN]; char desc_uuid_str[BT_HAL_UUID_STRING_LEN]; char* desc_handle = NULL; + GSList *l; hal_gattc_desc_t *gattc_desc = NULL; @@ -1817,27 +1828,34 @@ static bt_status_t _hal_read_descriptor_value(int conn_id, btgatt_srvc_id_t *srv DBG("service uuid [%s]", svc_uuid_str); /* find characteristic */ - gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid); - if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); - return BT_STATUS_FAIL; - } + /* service can have two char with same uuid */ + for (l = gattc_service->gatt_list_chars; l != NULL; l = g_slist_next(l)) { + gattc_char = (hal_gattc_char_t*)l->data; + if (gattc_char == NULL) + continue; - DBG("char path [%s]", gattc_char->chr_path); - _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + if (!memcmp(&gattc_char->chr_uuid, &char_id->uuid, sizeof(bt_uuid_t))) { + INFO("Found GATT char uuid"); + DBG("char path [%s]", gattc_char->chr_path); + _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); + DBG("char uuid [%s]", char_uuid_str); + + /* find descriptor */ + gattc_desc = _gattc_find_desc_from_uuid(gattc_char, &desc_id->uuid); + if (gattc_desc) { + DBG("desc path [%s]", gattc_desc->desc_path); + _bt_hal_convert_uuid_type_to_string(desc_uuid_str, gattc_desc->desc_uuid.uu); + DBG("desc uuid [%s]", desc_uuid_str); + break; + } + } + } - /* find descriptor */ - gattc_desc = _gattc_find_desc_from_uuid(gattc_char, &desc_id->uuid); if (NULL == gattc_desc) { DBG("Failed to get the gatt desc"); return BT_STATUS_FAIL; } - DBG("desc path [%s]", gattc_desc->desc_path); - _bt_hal_convert_uuid_type_to_string(desc_uuid_str, gattc_desc->desc_uuid.uu); - DBG("desc uuid [%s]", desc_uuid_str); - g_conn = _bt_hal_get_system_gconn(); if (NULL == g_conn) { ERR("_bt_gdbus_get_system_gconn returned NULL"); @@ -1964,8 +1982,9 @@ static bt_status_t _hal_write_descriptor_value(int conn_id, btgatt_srvc_id_t *sr char char_uuid_str[BT_HAL_UUID_STRING_LEN]; char desc_uuid_str[BT_HAL_UUID_STRING_LEN]; char* desc_handle = NULL; - hal_gatt_property_e write_prop = HAL_GATT_PROPERTY_WRITE; + bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE; int ret = BT_STATUS_SUCCESS; + GSList *l; DBG("+"); @@ -1994,27 +2013,34 @@ static bt_status_t _hal_write_descriptor_value(int conn_id, btgatt_srvc_id_t *sr DBG("service uuid [%s]", svc_uuid_str); /* find characteristic */ - gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid); - if (NULL == gattc_char) { - DBG("Failed to get the gatt char"); - return BT_STATUS_FAIL; - } + /* service can have two char with same uuid */ + for (l = gattc_service->gatt_list_chars; l != NULL; l = g_slist_next(l)) { + gattc_char = (hal_gattc_char_t*)l->data; + if (gattc_char == NULL) + continue; - DBG("char path [%s]", gattc_char->chr_path); - _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); - DBG("char uuid [%s]", char_uuid_str); + if (!memcmp(&gattc_char->chr_uuid, &char_id->uuid, sizeof(bt_uuid_t))) { + INFO("Found GATT char uuid"); + DBG("char path [%s]", gattc_char->chr_path); + _bt_hal_convert_uuid_type_to_string(char_uuid_str, gattc_char->chr_uuid.uu); + DBG("char uuid [%s]", char_uuid_str); + + /* find descriptor */ + gattc_desc = _gattc_find_desc_from_uuid(gattc_char, &descr_id->uuid); + if (gattc_desc) { + DBG("desc path [%s]", gattc_desc->desc_path); + _bt_hal_convert_uuid_type_to_string(desc_uuid_str, gattc_desc->desc_uuid.uu); + DBG("desc uuid [%s]", desc_uuid_str); + break; + } + } + } - /* find descriptor */ - gattc_desc = _gattc_find_desc_from_uuid(gattc_char, &descr_id->uuid); if (NULL == gattc_desc) { - DBG("Failed to get the gatt char"); + DBG("Failed to get the gatt desc"); return BT_STATUS_FAIL; } - DBG("desc path [%s]", gattc_desc->desc_path); - _bt_hal_convert_uuid_type_to_string(desc_uuid_str, gattc_desc->desc_uuid.uu); - DBG("char uuid [%s]", desc_uuid_str); - g_conn = _bt_hal_get_system_gconn(); if (NULL == g_conn) { ERR("_bt_gdbus_get_system_gconn returned NULL"); @@ -2163,7 +2189,8 @@ static bt_status_t _hal_register_for_notification(int client_if, /* find characteristic */ - gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid); + gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid, + HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY); if (NULL == gattc_char) { DBG("Failed to get the gatt char"); return BT_STATUS_FAIL; @@ -2328,7 +2355,8 @@ static bt_status_t _hal_deregister_for_notification(int client_if, /* find characteristic */ - gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid); + gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid, + HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY); if (NULL == gattc_char) { DBG("Failed to get the gatt char"); return BT_STATUS_FAIL; diff --git a/bt-service-adaptation/services/gatt/bt-service-gatt.c b/bt-service-adaptation/services/gatt/bt-service-gatt.c index e5c306c..d56b9b1 100644 --- a/bt-service-adaptation/services/gatt/bt-service-gatt.c +++ b/bt-service-adaptation/services/gatt/bt-service-gatt.c @@ -3208,7 +3208,8 @@ static void __bt_handle_client_characteristic_search_result( svc_info->chars = g_slist_append(svc_info->chars, char_info); } else { /* If found, then return */ - BT_INFO("Characteristic browsed is already presesnt"); + BT_INFO("update char property as Characteristic browsed is already present"); + char_info->props |= event_data->char_prop; } } else { /* If Not success: Means Charc browse is completed */ -- 2.7.4