From c0076a0dffd470a90a0f95c039de4d9a155377fd Mon Sep 17 00:00:00 2001 From: HsingYuan Lo Date: Thu, 17 Sep 2020 16:54:04 +0800 Subject: [PATCH] Refactor adding ext prop descriptor In oder to make db hash easier for unit testing 1. Creare a new API to add ext prop descriptor 2. Move the extended properties check to gatt_api.cc Test: compile Tag: #refactor Bug: 110864501 Change-Id: I7afd748e3cd6f6588a30c0f255da4f2ab4b9376c --- stack/gatt/gatt_api.cc | 11 ++++++++--- stack/gatt/gatt_db.cc | 37 +++++++++++++++++++++++++++---------- stack/gatt/gatt_int.h | 3 ++- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/stack/gatt/gatt_api.cc b/stack/gatt/gatt_api.cc index 2d93e611c..d55e197e5 100644 --- a/stack/gatt/gatt_api.cc +++ b/stack/gatt/gatt_api.cc @@ -239,9 +239,14 @@ uint16_t GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t* service, return GATT_INTERNAL_ERROR; } - el->attribute_handle = - gatts_add_characteristic(list.svc_db, el->permissions, el->properties, - el->extended_properties, uuid); + el->attribute_handle = gatts_add_characteristic( + list.svc_db, el->permissions, el->properties, uuid); + + // add characteristic extended properties descriptor if needed + if (el->properties & GATT_CHAR_PROP_BIT_EXT_PROP) { + gatts_add_char_ext_prop_descr(list.svc_db, el->extended_properties); + } + } else if (el->type == BTGATT_DB_DESCRIPTOR) { if (is_gatt_attr_type(uuid)) { LOG(ERROR) << __func__ diff --git a/stack/gatt/gatt_db.cc b/stack/gatt/gatt_db.cc index d4adbe325..f56e93dd5 100644 --- a/stack/gatt/gatt_db.cc +++ b/stack/gatt/gatt_db.cc @@ -376,7 +376,6 @@ uint16_t gatts_add_included_service(tGATT_SVC_DB& db, uint16_t s_handle, ******************************************************************************/ uint16_t gatts_add_characteristic(tGATT_SVC_DB& db, tGATT_PERM perm, tGATT_CHAR_PROP property, - uint16_t extended_properties, const Uuid& char_uuid) { Uuid uuid = Uuid::From16Bit(GATT_UUID_CHAR_DECLARE); @@ -391,20 +390,38 @@ uint16_t gatts_add_characteristic(tGATT_SVC_DB& db, tGATT_PERM perm, char_decl.p_value->char_decl.char_val_handle = char_val.handle; char_val.gatt_type = BTGATT_DB_CHARACTERISTIC; - if (property & GATT_CHAR_PROP_BIT_EXT_PROP) { - Uuid char_ext_prop_uuid = Uuid::From16Bit(GATT_UUID_CHAR_EXT_PROP); - tGATT_ATTR& char_ext_prop = - allocate_attr_in_db(db, char_ext_prop_uuid, GATT_PERM_READ); - char_ext_prop.p_value.reset(new tGATT_ATTR_VALUE); - char_ext_prop.p_value->char_ext_prop = extended_properties; - char_ext_prop.gatt_type = BTGATT_DB_DESCRIPTOR; - } - return char_val.handle; } /******************************************************************************* * + * Function gatts_add_char_ext_prop_descr + * + * Description add a characteristics extended properties descriptor. + * + * Parameter db: database pointer. + * extended_properties: characteristic descriptors values. + * + * Returns Status of the operation. + * + ******************************************************************************/ +uint16_t gatts_add_char_ext_prop_descr( + tGATT_SVC_DB& db, uint16_t extended_properties) { + Uuid descr_uuid = Uuid::From16Bit(GATT_UUID_CHAR_EXT_PROP); + + VLOG(1) << StringPrintf("gatts_add_char_ext_prop_descr uuid=%s", + descr_uuid.ToString().c_str()); + + tGATT_ATTR& char_dscptr = allocate_attr_in_db(db, descr_uuid, GATT_PERM_READ); + char_dscptr.gatt_type = BTGATT_DB_DESCRIPTOR; + char_dscptr.p_value.reset(new tGATT_ATTR_VALUE); + char_dscptr.p_value->char_ext_prop = extended_properties; + + return char_dscptr.handle; +} + +/******************************************************************************* + * * Function gatts_add_char_descr * * Description This function add a characteristics descriptor. diff --git a/stack/gatt/gatt_int.h b/stack/gatt/gatt_int.h index 5728b857a..258c2513d 100644 --- a/stack/gatt/gatt_int.h +++ b/stack/gatt/gatt_int.h @@ -596,8 +596,9 @@ extern uint16_t gatts_add_included_service(tGATT_SVC_DB& db, uint16_t s_handle, const bluetooth::Uuid& service); extern uint16_t gatts_add_characteristic(tGATT_SVC_DB& db, tGATT_PERM perm, tGATT_CHAR_PROP property, - uint16_t extended_properties, const bluetooth::Uuid& char_uuid); +extern uint16_t gatts_add_char_ext_prop_descr(tGATT_SVC_DB& db, + uint16_t extended_properties); extern uint16_t gatts_add_char_descr(tGATT_SVC_DB& db, tGATT_PERM perm, const bluetooth::Uuid& dscp_uuid); extern tGATT_STATUS gatts_db_read_attr_value_by_type( -- 2.11.0