Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d07bcac authored by HsingYuan Lo's avatar HsingYuan Lo
Browse files

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
parent 57d6a111
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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__
+27 −10
Original line number Diff line number Diff line
@@ -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,16 +390,34 @@ 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;
}

  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;
}

/*******************************************************************************
+2 −1
Original line number Diff line number Diff line
@@ -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(