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

Commit af030e03 authored by Myles Watson's avatar Myles Watson Committed by Hansong Zhang
Browse files

RootCanal: Add LeExtendedAdvertising, Connection

Bug: 148096951
Test: ./cert/run_device_cert.sh && ./cert/run_cert_facade_only.sh
Change-Id: I50098d8dd670422266b97c16424793d3e8b6eedb
parent f7424297
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -2781,9 +2781,9 @@ packet LeSetExtendedAdvertisingLegacyParameters : LeAdvertisingCommand (op_code
  advertising_filter_policy : AdvertisingFilterPolicy,
  _reserved_ : 6,
  advertising_tx_power : 8, // -127 to +20, 0x7F - no preference
  primary_advertising_phy : PrimaryPhyType,
  _fixed_ = 0x1 : 8, // PrimaryPhyType LE_1M
  _reserved_ : 8, // secondary_advertising_max_skip
  _reserved_ : 8, // secondary_advertising_phy
  _fixed_ = 0x1 : 8, // secondary_advertising_phy LE_1M
  advertising_sid : 8, // SID subfield from the ADI field of the PDU
  scan_request_notification_enable : Enable,
}
@@ -3029,6 +3029,9 @@ packet LeExtendedCreateConnection : LeConnectionManagementCommand (op_code = LE_
  phy_scan_parameters : LeCreateConnPhyScanParameters[],
}

packet LeExtendedCreateConnectionStatus : CommandStatus (command_op_code = LE_EXTENDED_CREATE_CONNECTION) {
}

packet LePeriodicAdvertisingCreateSync : LeAdvertisingCommand (op_code = LE_PERIODIC_ADVERTISING_CREATE_SYNC) {
  _payload_,  // placeholder (unimplemented)
}
+4 −6
Original line number Diff line number Diff line
@@ -485,7 +485,7 @@ DEFINE_AND_INSTANTIATE_LeSetExtendedAdvertisingDataCompleteReflectionTest(le_set

std::vector<uint8_t> le_set_extended_advertising_parameters_set_0{
    0x36, 0x20, 0x19, 0x00, 0x13, 0x00, 0x90, 0x01, 0x00, 0xc2, 0x01, 0x00, 0x07, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x01, 0x00, 0x00 /*0x01*/, 0x01, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x01, 0x00, 0x01, 0x01, 0x00,
};
TEST(HciPacketsTest, testLeSetExtendedAdvertisingParametersLegacySet0) {
  std::shared_ptr<std::vector<uint8_t>> packet_bytes =
@@ -502,14 +502,13 @@ TEST(HciPacketsTest, testLeSetExtendedAdvertisingParametersLegacySet0) {
  ASSERT_EQ(PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, view.GetPeerAddressType());
  ASSERT_EQ(Address::kEmpty, view.GetPeerAddress());
  ASSERT_EQ(AdvertisingFilterPolicy::ALL_DEVICES, view.GetAdvertisingFilterPolicy());
  ASSERT_EQ(PrimaryPhyType::LE_1M, view.GetPrimaryAdvertisingPhy());
  ASSERT_EQ(1, view.GetAdvertisingSid());
  ASSERT_EQ(Enable::DISABLED, view.GetScanRequestNotificationEnable());
}

std::vector<uint8_t> le_set_extended_advertising_parameters_set_1{
    0x36, 0x20, 0x19, 0x01, 0x13, 0x00, 0x90, 0x01, 0x00, 0xc2, 0x01, 0x00, 0x07, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x01, 0x00, 0x00 /*0x01*/, 0x01, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x01, 0x00, 0x01, 0x01, 0x00,
};
TEST(HciPacketsTest, testLeSetExtendedAdvertisingParametersSet1) {
  std::shared_ptr<std::vector<uint8_t>> packet_bytes =
@@ -526,7 +525,6 @@ TEST(HciPacketsTest, testLeSetExtendedAdvertisingParametersSet1) {
  ASSERT_EQ(PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, view.GetPeerAddressType());
  ASSERT_EQ(Address::kEmpty, view.GetPeerAddress());
  ASSERT_EQ(AdvertisingFilterPolicy::ALL_DEVICES, view.GetAdvertisingFilterPolicy());
  ASSERT_EQ(PrimaryPhyType::LE_1M, view.GetPrimaryAdvertisingPhy());
  ASSERT_EQ(1, view.GetAdvertisingSid());
  ASSERT_EQ(Enable::DISABLED, view.GetScanRequestNotificationEnable());
}
+2 −3
Original line number Diff line number Diff line
@@ -210,8 +210,7 @@ struct LeAdvertisingManager::impl {
          LeSetExtendedAdvertisingLegacyParametersBuilder::Create(
              id, legacy_properties, config.interval_min, config.interval_max, config.channel_map,
              config.own_address_type, config.peer_address_type, config.peer_address, config.filter_policy,
              config.tx_power, (config.use_le_coded_phy ? PrimaryPhyType::LE_CODED : PrimaryPhyType::LE_1M), config.sid,
              config.enable_scan_request_notifications),
              config.tx_power, config.sid, config.enable_scan_request_notifications),
          common::BindOnce(impl::check_status<LeSetExtendedAdvertisingParametersCompleteView>), module_handler_);
    } else {
      uint8_t legacy_properties = (config.connectable ? 0x1 : 0x00) | (config.scannable ? 0x2 : 0x00) |
+120 −1
Original line number Diff line number Diff line
@@ -205,7 +205,16 @@ DualModeController::DualModeController(const std::string& properties_filename, u
  SET_HANDLER(OpCode::LE_MULTI_ADVT, LeVendorMultiAdv);
  SET_HANDLER(OpCode::LE_ADV_FILTER, LeAdvertisingFilter);
  SET_HANDLER(OpCode::LE_ENERGY_INFO, LeEnergyInfo);
  SET_HANDLER(OpCode::LE_EXTENDED_SCAN_PARAMS, LeExtendedScanParams);
  SET_HANDLER(OpCode::LE_SET_EXTENDED_ADVERTISING_RANDOM_ADDRESS,
              LeSetExtendedAdvertisingRandomAddress);
  SET_HANDLER(OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS,
              LeSetExtendedAdvertisingParameters);
  SET_HANDLER(OpCode::LE_SET_EXTENDED_ADVERTISING_DATA,
              LeSetExtendedAdvertisingData);
  SET_HANDLER(OpCode::LE_SET_EXTENDED_ADVERTISING_SCAN_RESPONSE,
              LeSetExtendedAdvertisingScanResponse);
  SET_HANDLER(OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE,
              LeSetExtendedAdvertisingEnable);
  SET_HANDLER(OpCode::LE_READ_REMOTE_FEATURES, LeReadRemoteFeatures);
  SET_HANDLER(OpCode::READ_REMOTE_VERSION_INFORMATION,
              ReadRemoteVersionInformation);
@@ -219,6 +228,8 @@ DualModeController::DualModeController(const std::string& properties_filename, u
  SET_HANDLER(OpCode::LE_SET_EXTENDED_SCAN_PARAMETERS,
              LeSetExtendedScanParameters);
  SET_HANDLER(OpCode::LE_SET_EXTENDED_SCAN_ENABLE, LeSetExtendedScanEnable);
  SET_HANDLER(OpCode::LE_EXTENDED_CREATE_CONNECTION,
              LeExtendedCreateConnection);
  SET_HANDLER(OpCode::LE_SET_PRIVACY_MODE, LeSetPrivacyMode);
  // Testing Commands
  SET_HANDLER(OpCode::READ_LOOPBACK_MODE, ReadLoopbackMode);
@@ -1738,6 +1749,42 @@ void DualModeController::LeSetExtendedScanEnable(CommandPacketView command) {
  send_event_(std::move(packet));
}

void DualModeController::LeExtendedCreateConnection(CommandPacketView command) {
  auto command_view = gd_hci::LeExtendedCreateConnectionView::Create(
      gd_hci::LeConnectionManagementCommandView::Create(command));
  ASSERT(command_view.IsValid());
  ASSERT_LOG(command_view.GetInitiatingPhys() == 1, "Only LE_1M is supported");
  auto params = command_view.GetPhyScanParameters();
  link_layer_controller_.SetLeScanInterval(params[0].scan_interval_);
  link_layer_controller_.SetLeScanWindow(params[0].scan_window_);
  auto initiator_filter_policy = command_view.GetInitiatorFilterPolicy();
  link_layer_controller_.SetLeInitiatorFilterPolicy(
      static_cast<uint8_t>(initiator_filter_policy));

  if (initiator_filter_policy ==
      gd_hci::InitiatorFilterPolicy::USE_PEER_ADDRESS) {
    link_layer_controller_.SetLePeerAddressType(
        static_cast<uint8_t>(command_view.GetPeerAddressType()));
    link_layer_controller_.SetLePeerAddress(command_view.GetPeerAddress());
  }
  link_layer_controller_.SetLeAddressType(
      static_cast<uint8_t>(command_view.GetOwnAddressType()));
  link_layer_controller_.SetLeConnectionIntervalMin(
      params[0].conn_interval_min_);
  link_layer_controller_.SetLeConnectionIntervalMax(
      params[0].conn_interval_max_);
  link_layer_controller_.SetLeConnectionLatency(params[0].conn_latency_);
  link_layer_controller_.SetLeSupervisionTimeout(
      params[0].supervision_timeout_);
  link_layer_controller_.SetLeMinimumCeLength(params[0].min_ce_length_);
  link_layer_controller_.SetLeMaximumCeLength(params[0].max_ce_length_);

  auto status = link_layer_controller_.SetLeConnect(true);

  send_event_(bluetooth::hci::LeExtendedCreateConnectionStatusBuilder::Create(
      status, kNumCommandPackets));
}

void DualModeController::LeSetPrivacyMode(CommandPacketView command) {
  auto command_view = gd_hci::LeSetPrivacyModeView::Create(
      gd_hci::LeSecurityCommandView::Create(command));
@@ -1843,6 +1890,78 @@ void DualModeController::LeEnergyInfo(CommandPacketView command) {
      static_cast<uint16_t>(OpCode::LE_ENERGY_INFO));
}

void DualModeController::LeSetExtendedAdvertisingRandomAddress(
    CommandPacketView command) {
  auto command_view = gd_hci::LeSetExtendedAdvertisingRandomAddressView::Create(
      gd_hci::LeAdvertisingCommandView::Create(command));
  ASSERT(command_view.IsValid());
  properties_.SetLeAddress(command_view.GetAdvertisingRandomAddress());
  send_event_(
      bluetooth::hci::LeSetExtendedAdvertisingRandomAddressCompleteBuilder::
          Create(kNumCommandPackets, ErrorCode::SUCCESS));
}

void DualModeController::LeSetExtendedAdvertisingParameters(
    CommandPacketView command) {
  auto command_view =
      gd_hci::LeSetExtendedAdvertisingLegacyParametersView::Create(
          gd_hci::LeAdvertisingCommandView::Create(command));
  // TODO: Support non-legacy parameters
  ASSERT(command_view.IsValid());
  properties_.SetLeAdvertisingParameters(
      command_view.GetPrimaryAdvertisingIntervalMin(),
      command_view.GetPrimaryAdvertisingIntervalMax(),
      static_cast<uint8_t>(bluetooth::hci::AdvertisingEventType::ADV_IND),
      static_cast<uint8_t>(command_view.GetOwnAddressType()),
      static_cast<uint8_t>(command_view.GetPeerAddressType()),
      command_view.GetPeerAddress(),
      command_view.GetPrimaryAdvertisingChannelMap(),
      static_cast<uint8_t>(command_view.GetAdvertisingFilterPolicy()));

  send_event_(
      bluetooth::hci::LeSetExtendedAdvertisingParametersCompleteBuilder::Create(
          kNumCommandPackets, ErrorCode::SUCCESS, 0xa5));
}

void DualModeController::LeSetExtendedAdvertisingData(
    CommandPacketView command) {
  auto command_view = gd_hci::LeSetExtendedAdvertisingDataView::Create(
      gd_hci::LeAdvertisingCommandView::Create(command));
  ASSERT(command_view.IsValid());
  auto raw_command_view = gd_hci::LeSetExtendedAdvertisingDataRawView::Create(
      gd_hci::LeAdvertisingCommandView::Create(command));
  ASSERT(raw_command_view.IsValid());
  properties_.SetLeAdvertisement(raw_command_view.GetAdvertisingData());
  auto packet =
      bluetooth::hci::LeSetExtendedAdvertisingDataCompleteBuilder::Create(
          kNumCommandPackets, ErrorCode::SUCCESS);
  send_event_(std::move(packet));
}

void DualModeController::LeSetExtendedAdvertisingScanResponse(
    CommandPacketView command) {
  auto command_view = gd_hci::LeSetExtendedAdvertisingScanResponseView::Create(
      gd_hci::LeAdvertisingCommandView::Create(command));
  ASSERT(command_view.IsValid());
  properties_.SetLeScanResponse(std::vector<uint8_t>(
      command_view.GetPayload().begin() + 1, command_view.GetPayload().end()));
  send_event_(
      bluetooth::hci::LeSetExtendedAdvertisingScanResponseCompleteBuilder::
          Create(kNumCommandPackets, ErrorCode::SUCCESS));
}

void DualModeController::LeSetExtendedAdvertisingEnable(
    CommandPacketView command) {
  auto command_view = gd_hci::LeSetExtendedAdvertisingEnableView::Create(
      gd_hci::LeAdvertisingCommandView::Create(command));
  ASSERT(command_view.IsValid());
  auto status = link_layer_controller_.SetLeAdvertisingEnable(
      command_view.GetEnable() == gd_hci::Enable::ENABLED);
  send_event_(
      bluetooth::hci::LeSetExtendedAdvertisingEnableCompleteBuilder::Create(
          kNumCommandPackets, status));
}

void DualModeController::LeExtendedScanParams(CommandPacketView command) {
  auto command_view = gd_hci::LeExtendedScanParamsView::Create(
      gd_hci::LeScanningCommandView::Create(command));
+18 −0
Original line number Diff line number Diff line
@@ -436,12 +436,30 @@ class DualModeController : public Device {
  // 7.8.40
  void LeClearResolvingList(CommandPacketView args);

  // 7.8.52
  void LeSetExtendedAdvertisingRandomAddress(CommandPacketView args);

  // 7.8.53
  void LeSetExtendedAdvertisingParameters(CommandPacketView args);

  // 7.8.54
  void LeSetExtendedAdvertisingData(CommandPacketView args);

  // 7.8.55
  void LeSetExtendedAdvertisingScanResponse(CommandPacketView args);

  // 7.8.56
  void LeSetExtendedAdvertisingEnable(CommandPacketView args);

  // 7.8.64
  void LeSetExtendedScanParameters(CommandPacketView args);

  // 7.8.65
  void LeSetExtendedScanEnable(CommandPacketView args);

  // 7.8.66
  void LeExtendedCreateConnection(CommandPacketView args);

  // 7.8.77
  void LeSetPrivacyMode(CommandPacketView args);