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

Commit 158b3d29 authored by Yun-Hao Chung's avatar Yun-Hao Chung
Browse files

Floss: Add address type to device property

This adds device address type, e.g. public, random, to the device
property and makes sure it is propogated to the upper layer whenever the
value is updated.

Currently this is only used by Floss but we can remove the ifdef flag to
make it universal.

Bug: 290872223
Test: mma -j
Test: tested it with the next patch: pair an LE device and a classic
device manually and verify the address type shown in btclient is matched
with the bt_config.conf.

Change-Id: Ie89bacd1f238a58d7731ec826e20f1f8d0957211
parent 49c88fbd
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ using bluetooth::Uuid;
#define BTIF_STORAGE_PATH_VERSION "ProductVersion"

#define BTIF_STORAGE_KEY_RESTRICTED "Restricted"
#define BTIF_STORAGE_KEY_ADDR_TYPE "AddrType"

/* This is a local property to add a device found */
#define BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP 0xFF
@@ -397,6 +398,15 @@ static int cfg2prop(const RawAddress* remote_bd_addr, bt_property_t* prop) {
      }
    } break;

    case BT_PROPERTY_REMOTE_ADDR_TYPE: {
      int val;

      if (prop->len >= (int)sizeof(uint8_t)) {
        ret = btif_config_get_int(bdstr, BTIF_STORAGE_KEY_ADDR_TYPE, &val);
        *(uint8_t*)prop->val = (uint8_t)val;
      }
    } break;

    default:
      BTIF_TRACE_ERROR("Unknow prop type:%d", prop->type);
      return false;
@@ -1154,6 +1164,15 @@ bt_status_t btif_storage_load_bonded_devices(void) {
              &remote_properties[num_props]) == BT_STATUS_SUCCESS) {
        num_props++;
      }

      // Floss needs address type for diagnosis API
      uint8_t addr_type;
      if (btif_storage_get_remote_prop(
              p_remote_addr, BT_PROPERTY_REMOTE_ADDR_TYPE, &addr_type,
              sizeof(addr_type),
              &remote_properties[num_props]) == BT_STATUS_SUCCESS) {
        num_props++;
      }
#endif

      btif_storage_get_remote_prop(p_remote_addr, BT_PROPERTY_REMOTE_MODEL_NUM,
@@ -1431,10 +1450,26 @@ bt_status_t btif_in_fetch_bonded_ble_device(
  return BT_STATUS_FAIL;
}

void btif_storage_invoke_addr_type_update(const RawAddress& remote_bd_addr,
                                          const tBLE_ADDR_TYPE& addr_type) {
  bt_property_t prop;
  prop.type = BT_PROPERTY_REMOTE_ADDR_TYPE;
  prop.val = (tBLE_ADDR_TYPE*)&addr_type;
  prop.len = sizeof(tBLE_ADDR_TYPE);
  GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb(
      BT_STATUS_SUCCESS, remote_bd_addr, 1, &prop);
}

bt_status_t btif_storage_set_remote_addr_type(const RawAddress* remote_bd_addr,
                                              tBLE_ADDR_TYPE addr_type) {
  int ret = btif_config_set_int(remote_bd_addr->ToString(), "AddrType",
                                (int)addr_type);

#if TARGET_FLOSS
  // Floss needs to get address type for diagnosis API.
  btif_storage_invoke_addr_type_update(*remote_bd_addr, addr_type);
#endif

  return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}

@@ -1443,6 +1478,12 @@ void btif_storage_set_remote_addr_type(const RawAddress& remote_bd_addr,
  if (!btif_config_set_int(remote_bd_addr.ToString(), "AddrType",
                           static_cast<int>(addr_type)))
    LOG_ERROR("Unable to set storage property");
  else {
#if TARGET_FLOSS
    // Floss needs to get address type for diagnosis API.
    btif_storage_invoke_addr_type_update(remote_bd_addr, addr_type);
#endif
  }
}

void btif_storage_set_remote_device_type(const RawAddress& remote_bd_addr,
+7 −0
Original line number Diff line number Diff line
@@ -394,6 +394,13 @@ typedef enum {
   */
  BT_PROPERTY_REMOTE_MODEL_NUM,

  /**
   * Description - Address type of the remote device - PUBLIC or REMOTE
   * Access mode - GET.
   * Data Type - uint8_t.
   */
  BT_PROPERTY_REMOTE_ADDR_TYPE,

  BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
} bt_property_type_t;