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

Commit f67cc057 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Server support for Characteristic Extended Properties

Test: sl4a GattExtendedPropertiesTest
Bug: 110864501
Change-Id: If04b28f1b90c1f7b5a6f53673f6bd2c4791f28bb
parent 128d1813
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -710,12 +710,18 @@ static void bta_gattc_get_gatt_db_impl(tBTA_GATTC_SERV* p_srvc_cb,
                                charac.value_handle, 0 /* s_handle */,
                                0 /* e_handle */, charac.value_handle,
                                charac.uuid, charac.properties);
      btgatt_db_element_t* characteristic = curr_db_attr;
      curr_db_attr++;

      for (const Descriptor& desc : charac.descriptors) {
        bta_gattc_fill_gatt_db_el(
            curr_db_attr, BTGATT_DB_DESCRIPTOR, desc.handle, 0 /* s_handle */,
            0 /* e_handle */, desc.handle, desc.uuid, 0 /* property */);

        if (desc.uuid == Uuid::From16Bit(GATT_UUID_CHAR_EXT_PROP)) {
          characteristic->extended_properties =
              desc.characteristic_extended_properties;
        }
        curr_db_attr++;
      }
    }
+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ typedef struct {
   * the characteristic.
   */
  uint8_t properties;
  uint16_t extended_properties;

  uint16_t permissions;
} btgatt_db_element_t;

+10 −5
Original line number Diff line number Diff line
@@ -106,12 +106,16 @@ static uint16_t compute_service_size(btgatt_db_element_t* service, int count) {
    if (el->type == BTGATT_DB_PRIMARY_SERVICE ||
        el->type == BTGATT_DB_SECONDARY_SERVICE ||
        el->type == BTGATT_DB_DESCRIPTOR ||
        el->type == BTGATT_DB_INCLUDED_SERVICE)
        el->type == BTGATT_DB_INCLUDED_SERVICE) {
      db_size += 1;
    else if (el->type == BTGATT_DB_CHARACTERISTIC)
    } else if (el->type == BTGATT_DB_CHARACTERISTIC) {
      db_size += 2;
    else

      // if present, Characteristic Extended Properties takes one handle
      if (el->properties & GATT_CHAR_PROP_BIT_EXT_PROP) db_size++;
    } else {
      LOG(ERROR) << __func__ << ": Unknown element type: " << el->type;
    }

  return db_size;
}
@@ -235,8 +239,9 @@ 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, uuid);
      el->attribute_handle =
          gatts_add_characteristic(list.svc_db, el->permissions, el->properties,
                                   el->extended_properties, uuid);
    } else if (el->type == BTGATT_DB_DESCRIPTOR) {
      if (is_gatt_attr_type(uuid)) {
        LOG(ERROR) << __func__
+24 −4
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ void gatts_init_service_db(tGATT_SVC_DB& db, const Uuid& service_uuid,
  Uuid uuid =
      Uuid::From16Bit(is_pri ? GATT_UUID_PRI_SERVICE : GATT_UUID_SEC_SERVICE);
  tGATT_ATTR& attr = allocate_attr_in_db(db, uuid, GATT_PERM_READ);
  attr.p_value.reset((tGATT_ATTR_VALUE*)(new Uuid));
  attr.p_value.reset(new tGATT_ATTR_VALUE);
  attr.p_value->uuid = service_uuid;
}

@@ -231,7 +231,15 @@ static tGATT_STATUS read_attr_value(tGATT_ATTR& attr16, uint16_t offset,
    return GATT_SUCCESS;
  }

  /* characteristic description or characteristic value (again) */
  if (uuid16 == GATT_UUID_CHAR_EXT_PROP) {
    uint16_t char_ext_prop = attr16.p_value->char_ext_prop;
    *p_len = 2;
    UINT16_TO_STREAM(p, char_ext_prop);
    *p_data = p;
    return GATT_SUCCESS;
  }

  /* characteristic descriptor or characteristic value (again) */
  return GATT_PENDING;
}

@@ -342,7 +350,7 @@ uint16_t gatts_add_included_service(tGATT_SVC_DB& db, uint16_t s_handle,

  tGATT_ATTR& attr = allocate_attr_in_db(db, uuid, GATT_PERM_READ);

  attr.p_value.reset((tGATT_ATTR_VALUE*)(new tGATT_INCL_SRVC));
  attr.p_value.reset(new tGATT_ATTR_VALUE);
  attr.p_value->incl_handle.s_handle = s_handle;
  attr.p_value->incl_handle.e_handle = e_handle;
  attr.p_value->incl_handle.service_type = service;
@@ -360,6 +368,7 @@ uint16_t gatts_add_included_service(tGATT_SVC_DB& db, uint16_t s_handle,
 * Parameter        db: database.
 *                  perm: permission (authentication and key size requirements)
 *                  property: property of the characteristic.
 *                  extended_properties: characteristic extended properties.
 *                  p_char: characteristic value information.
 *
 * Returns          Status of te operation.
@@ -367,6 +376,7 @@ 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);

@@ -376,10 +386,20 @@ uint16_t gatts_add_characteristic(tGATT_SVC_DB& db, tGATT_PERM perm,
  tGATT_ATTR& char_decl = allocate_attr_in_db(db, uuid, GATT_PERM_READ);
  tGATT_ATTR& char_val = allocate_attr_in_db(db, char_uuid, perm);

  char_decl.p_value.reset((tGATT_ATTR_VALUE*)(new tGATT_CHAR_DECL));
  char_decl.p_value.reset(new tGATT_ATTR_VALUE);
  char_decl.p_value->char_decl.property = property;
  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;
}

+2 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ typedef union {
  bluetooth::Uuid uuid;        /* service declaration */
  tGATT_CHAR_DECL char_decl;   /* characteristic declaration */
  tGATT_INCL_SRVC incl_handle; /* included service */
  uint16_t char_ext_prop;      /* Characteristic Extended Properties */
} tGATT_ATTR_VALUE;

/* Attribute UUID type
@@ -594,6 +595,7 @@ 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_descr(tGATT_SVC_DB& db, tGATT_PERM perm,
                                     const bluetooth::Uuid& dscp_uuid);