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

Commit 5fc5174d authored by Rahul Arya's avatar Rahul Arya
Browse files

[Non-Discoverable Mode] Selectively hide Device Name characteristic

When in non-discoverable mode, this characteristic should not be
readable (5.3 Vol 3C 12.1 Device Name Characteristic)

Bug: 254314964
Test: compiles
Change-Id: I4f9441eb099269e2c99a45ff7e505d71ed76d914
parent dfc15dd9
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -318,6 +318,18 @@ bool BTM_IsAuthenticated(const RawAddress& bd_addr, tBT_TRANSPORT transport) {
  return (flags & BTM_SEC_AUTHENTICATED) != 0;
}

bool BTM_CanReadDiscoverableCharacteristics(const RawAddress& bd_addr) {
  auto p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec != nullptr) {
    return p_dev_rec->can_read_discoverable;
  } else {
    LOG_ERROR(
        "BTM_CanReadDiscoverableCharacteristics invoked for an invalid "
        "BD_ADDR");
    return false;
  }
}

/*******************************************************************************
 *
 * Function         BTM_GetSecurityFlagsByTransport
+1 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ bool BTM_IsEncrypted(const RawAddress& bd_addr, tBT_TRANSPORT transport);
bool BTM_IsLinkKeyAuthed(const RawAddress& bd_addr, tBT_TRANSPORT transport);
bool BTM_IsLinkKeyKnown(const RawAddress& bd_addr, tBT_TRANSPORT transport);
bool BTM_IsAuthenticated(const RawAddress& bd_addr, tBT_TRANSPORT transport);
bool BTM_CanReadDiscoverableCharacteristics(const RawAddress& bd_addr);

/*******************************************************************************
 *
+21 −21
Original line number Diff line number Diff line
@@ -436,7 +436,7 @@ void gap_attr_db_init(void) {
      {.uuid = name_uuid,
       .type = BTGATT_DB_CHARACTERISTIC,
       .properties = GATT_CHAR_PROP_BIT_READ,
     .permissions = GATT_PERM_READ},
       .permissions = GATT_PERM_READ_IF_ENCRYPTED_OR_DISCOVERABLE},
      {.uuid = icon_uuid,
       .type = BTGATT_DB_CHARACTERISTIC,
       .properties = GATT_CHAR_PROP_BIT_READ,
+13 −0
Original line number Diff line number Diff line
@@ -123,6 +123,19 @@ static tGATT_STATUS gatts_check_attr_readability(const tGATT_ATTR& attr,
    return GATT_INSUF_KEY_SIZE;
  }

  if (perm & GATT_PERM_READ_IF_ENCRYPTED_OR_DISCOVERABLE) {
    if (sec_flag.can_read_discoverable_characteristics) {
      // no checks here
    } else {
      if (!sec_flag.is_link_key_known || !sec_flag.is_encrypted) {
        return GATT_INSUF_AUTHENTICATION;
      }
      if (key_size < min_key_size) {
        return GATT_INSUF_KEY_SIZE;
      }
    }
  }

  if (read_long && attr.uuid.Is16Bit()) {
    switch (attr.uuid.As16Bit()) {
      case GATT_UUID_PRI_SERVICE:
+4 −0
Original line number Diff line number Diff line
@@ -93,6 +93,10 @@ typedef struct {
  bool is_link_key_known;
  bool is_link_key_authed;
  bool is_encrypted;
  // whether we connected to the peer, or if it
  // connected to a discoverable advertisement (affects
  // GAP permissions)
  bool can_read_discoverable_characteristics;
} tGATT_SEC_FLAG;

/* Find Information Response Type
Loading