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

Commit 1c9e4c30 authored by Andriy Naborskyy's avatar Andriy Naborskyy Committed by Md Shahriar Hossain Sajib
Browse files

ble advertisement address type parameter

use advertisement address type from parameter setting.

Test: atest BluetoothInstrumentationTests
Test: build passes, IOP and BCST
bug: 155993389
Bug: 199827901
Tag: #feature
Change-Id: Id2b7c57ecae11a25c26a6fd22d48d261a6ed3884
parent bbf5511c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ void parseParams(tBTM_BLE_ADV_PARAMS* p_params,
  p_params->secondary_advertising_phy = params.secondary_advertising_phy;
  p_params->scan_request_notification_enable =
      params.scan_request_notification_enable;
  p_params->own_address_type = params.own_address_type;
}

void parsePeriodicParams(tBLE_PERIODIC_ADV_PARAMS* p_periodic_params,
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ struct AdvertiseParameters {
  uint8_t primary_advertising_phy;
  uint8_t secondary_advertising_phy;
  uint8_t scan_request_notification_enable;
  int8_t own_address_type;
};

struct PeriodicAdvertisingParameters {
+18 −4
Original line number Diff line number Diff line
@@ -241,15 +241,23 @@ class BleAdvertisingManagerImpl
  void RegisterAdvertiser(
      base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)> cb)
      override {
    int own_address_type =
        BTM_BleLocalPrivacyEnabled() ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC;
    RegisterAdvertiserImpl(own_address_type, cb);
  }

  void RegisterAdvertiserImpl(
      int own_address_type,
      base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)> cb) {
    AdvertisingInstance* p_inst = &adv_inst[0];
    for (uint8_t i = 0; i < inst_count; i++, p_inst++) {
      if (p_inst->in_use) continue;

      p_inst->in_use = true;
      p_inst->own_address_type = own_address_type;

      // set up periodic timer to update address.
      if (BTM_BleLocalPrivacyEnabled()) {
        p_inst->own_address_type = BLE_ADDR_RANDOM;
      if (own_address_type != BLE_ADDR_PUBLIC) {
        GenerateRpa(Bind(
            [](AdvertisingInstance* p_inst,
               base::Callback<void(uint8_t /* inst_id */, uint8_t /* status */)>
@@ -264,7 +272,6 @@ class BleAdvertisingManagerImpl
            },
            p_inst, cb));
      } else {
        p_inst->own_address_type = BLE_ADDR_PUBLIC;
        p_inst->own_address = *controller_get_interface()->get_address();

        cb.Run(p_inst->inst_id, BTM_BLE_MULTI_ADV_SUCCESS);
@@ -395,10 +402,16 @@ class BleAdvertisingManagerImpl
    c->maxExtAdvEvents = maxExtAdvEvents;
    c->timeout_cb = std::move(timeout_cb);

    int own_address_type =
        BTM_BleLocalPrivacyEnabled() ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC;
    if (params->own_address_type != BLE_ADDR_ANONYMOUS) {
      own_address_type = params->own_address_type;
    }

    // this code is intentionally left formatted this way to highlight the
    // asynchronous flow
    // clang-format off
    c->self->RegisterAdvertiser(Bind(
    c->self->RegisterAdvertiserImpl(own_address_type, Bind(
      [](c_type c, uint8_t advertiser_id, uint8_t status) {
        if (!c->self) {
          LOG(INFO) << "Stack was shut down";
@@ -1048,6 +1061,7 @@ void btm_ble_adv_init() {

  if (BleAdvertiserHciInterface::Get()->QuirkAdvertiserZeroHandle()) {
    // If handle 0 can't be used, register advertiser for it, but never use it.
    // TODO: avoid generating/rotating RPA for it
    BleAdvertisingManager::Get().get()->RegisterAdvertiser(base::DoNothing());
  }
}
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ typedef struct {
  uint8_t primary_advertising_phy;
  uint8_t secondary_advertising_phy;
  uint8_t scan_request_notification_enable;
  int8_t own_address_type;
} tBTM_BLE_ADV_PARAMS;

typedef struct {
+32 −5
Original line number Diff line number Diff line
@@ -192,6 +192,8 @@ class BleAdvertisingManagerTest : public testing::Test {
    start_advertising_set_tx_power = tx_power;
    start_advertising_set_status = status;
  }

  void StartAdvertisingSetWithSpecificAddressType(int8_t own_address_type);
};

TEST_F(BleAdvertisingManagerTest, test_registration) {
@@ -436,10 +438,12 @@ TEST_F(BleAdvertisingManagerTest, test_reenabling_disabled_instance) {

/* This test verifies that the only flow that is currently used on Android, is
 * working correctly in happy case scenario. */
TEST_F(BleAdvertisingManagerTest, test_start_advertising_set) {
void BleAdvertisingManagerTest::StartAdvertisingSetWithSpecificAddressType(
    int8_t own_address_type) {
  std::vector<uint8_t> adv_data;
  std::vector<uint8_t> scan_resp;
  tBTM_BLE_ADV_PARAMS params;
  params.own_address_type = own_address_type;
  tBLE_PERIODIC_ADV_PARAMS periodic_params;
  periodic_params.enable = false;
  std::vector<uint8_t> periodic_data;
@@ -453,9 +457,11 @@ TEST_F(BleAdvertisingManagerTest, test_start_advertising_set) {
  EXPECT_CALL(*hci_mock, SetParameters2(_, _, _, _, _, _, _, _))
      .Times(1)
      .WillOnce(SaveArg<7>(&set_params_cb));
  if (own_address_type != BLE_ADDR_PUBLIC) {
    EXPECT_CALL(*hci_mock, SetRandomAddress(_, _, _))
        .Times(1)
        .WillOnce(SaveArg<2>(&set_address_cb));
  }
  EXPECT_CALL(*hci_mock, SetAdvertisingData(_, _, _, _, _, _))
      .Times(1)
      .WillOnce(SaveArg<5>(&set_data_cb));
@@ -475,7 +481,9 @@ TEST_F(BleAdvertisingManagerTest, test_start_advertising_set) {
  // we are a truly gracious fake controller, let the commands succeed!
  int selected_tx_power = -15;
  set_params_cb.Run(0, selected_tx_power);
  if (own_address_type != BLE_ADDR_PUBLIC) {
    set_address_cb.Run(0);
  }
  set_data_cb.Run(0);
  set_scan_resp_data_cb.Run(0);
  enable_cb.Run(0);
@@ -506,6 +514,21 @@ TEST_F(BleAdvertisingManagerTest, test_start_advertising_set) {
  remove_cb.Run(0);
}

TEST_F(BleAdvertisingManagerTest,
       test_start_advertising_set_default_address_type) {
  StartAdvertisingSetWithSpecificAddressType(BLE_ADDR_ANONYMOUS);
}

TEST_F(BleAdvertisingManagerTest,
       test_start_advertising_set_public_address_type) {
  StartAdvertisingSetWithSpecificAddressType(BLE_ADDR_PUBLIC);
}

TEST_F(BleAdvertisingManagerTest,
       test_start_advertising_set_random_address_type) {
  StartAdvertisingSetWithSpecificAddressType(BLE_ADDR_RANDOM);
}

TEST_F(BleAdvertisingManagerTest, test_start_advertising_set_params_failed) {
  BleAdvertisingManager::Get()->RegisterAdvertiser(
      Bind(&BleAdvertisingManagerTest::RegistrationCb, base::Unretained(this)));
@@ -680,6 +703,7 @@ TEST_F(BleAdvertisingManagerTest,
  std::vector<uint8_t> adv_data;
  std::vector<uint8_t> scan_resp;
  tBTM_BLE_ADV_PARAMS params;
  params.own_address_type = BLE_ADDR_ANONYMOUS;
  params.advertising_event_properties = 0x1 /* connectable */;
  tBLE_PERIODIC_ADV_PARAMS periodic_params;
  periodic_params.enable = false;
@@ -794,6 +818,7 @@ TEST_F(BleAdvertisingManagerTest, test_periodic_adv_disable_on_unregister) {
  std::vector<uint8_t> adv_data;
  std::vector<uint8_t> scan_resp;
  tBTM_BLE_ADV_PARAMS params;
  params.own_address_type = BLE_ADDR_ANONYMOUS;
  params.advertising_event_properties = 0x1 /* connectable */;
  tBLE_PERIODIC_ADV_PARAMS periodic_params;
  periodic_params.enable = true;  // enable periodic advertising
@@ -954,6 +979,7 @@ TEST_F(BleAdvertisingManagerTest, test_duration_update_during_timeout) {
  std::vector<uint8_t> adv_data;
  std::vector<uint8_t> scan_resp;
  tBTM_BLE_ADV_PARAMS params;
  params.own_address_type = BLE_ADDR_ANONYMOUS;
  params.advertising_event_properties = 0x1 /* connectable */;
  params.adv_int_min = params.adv_int_max = 0xA0 /* 100ms */;
  tBLE_PERIODIC_ADV_PARAMS periodic_params;
@@ -1063,6 +1089,7 @@ TEST_F(BleAdvertisingManagerTest, test_cleanup_during_execution) {
  std::vector<uint8_t> adv_data;
  std::vector<uint8_t> scan_resp;
  tBTM_BLE_ADV_PARAMS params;
  params.own_address_type = BLE_ADDR_ANONYMOUS;
  tBLE_PERIODIC_ADV_PARAMS periodic_params;
  periodic_params.enable = false;
  std::vector<uint8_t> periodic_data;