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

Commit 1efed489 authored by Myles Watson's avatar Myles Watson
Browse files

RootCanal: Add full advertisement

Copy the complete advertising data.
Remove an unused function from the LinkLayerController.
Update the tests.

Tag: #gd-refactor
Bug: 145832107
Test: cert/run --host
Change-Id: I272a0690dac2b3b3dcd3fde2dbe1356406c780bd
parent 8587817f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ class SimpleHalTest(GdBaseTestClass):

            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_A_Cert!'))  # TODO: Fix and remove !
            gap_name.data = list(bytes(b'Im_A_Cert'))

            self.send_cert_hci_command(
                hci_packets.LeSetExtendedAdvertisingDataBuilder(
@@ -210,7 +210,7 @@ class SimpleHalTest(GdBaseTestClass):

            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_The_DUT!'))  # TODO: Fix and remove !
            gap_name.data = list(bytes(b'Im_The_DUT'))

            self.send_dut_hci_command(
                hci_packets.LeSetExtendedAdvertisingDataBuilder(
@@ -306,7 +306,7 @@ class SimpleHalTest(GdBaseTestClass):

            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_A_Cert!'))  # TODO: Fix and remove !
            gap_name.data = list(bytes(b'Im_A_Cert'))

            self.send_cert_hci_command(
                hci_packets.LeSetExtendedAdvertisingDataBuilder(
+2 −2
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ class DirectHciTest(GdBaseTestClass):
            hci_packets.LeSetExtendedAdvertisingRandomAddressBuilder(advertising_handle, '0C:05:04:03:02:01'))
        gap_name = hci_packets.GapData()
        gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
        gap_name.data = list(bytes(b'Im_A_Cert!'))  # TODO: Fix and remove !
        gap_name.data = list(bytes(b'Im_A_Cert'))

        self.send_hal_hci_command(
            hci_packets.LeSetExtendedAdvertisingDataBuilder(
@@ -288,7 +288,7 @@ class DirectHciTest(GdBaseTestClass):

        gap_name = hci_packets.GapData()
        gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
        gap_name.data = list(bytes(b'Im_A_Cert!'))  # TODO: Fix and remove !
        gap_name.data = list(bytes(b'Im_A_Cert'))

        self.send_hal_hci_command(
            hci_packets.LeSetExtendedAdvertisingDataBuilder(
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ class LeAdvertisingManagerTest(GdBaseTestClass):
            # DUT Advertises
            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_The_DUT!'))
            gap_name.data = list(bytes(b'Im_The_DUT'))
            gap_data = le_advertising_facade.GapDataMsg(data=bytes(gap_name.Serialize()))
            config = le_advertising_facade.AdvertisingConfig(
                advertisement=[gap_data],
+3 −2
Original line number Diff line number Diff line
@@ -1445,8 +1445,9 @@ void DualModeController::LeSetAdvertisingData(CommandPacketView command) {
  auto command_view = gd_hci::LeSetAdvertisingDataView::Create(
      gd_hci::LeAdvertisingCommandView::Create(command));
  auto payload = command.GetPayload();
  std::vector<uint8_t> payload_bytes{payload.begin() + 1,
                                     payload.begin() + *payload.begin()};
  auto data_size = *payload.begin();
  auto first_data = payload.begin() + 1;
  std::vector<uint8_t> payload_bytes{first_data, first_data + data_size};
  ASSERT_LOG(command_view.IsValid(), "%s command.size() = %zu",
             gd_hci::OpCodeText(command.GetOpCode()).c_str(), command.size());
  ASSERT(command_view.GetPayload().size() == 32);
+9 −13
Original line number Diff line number Diff line
@@ -776,7 +776,8 @@ void LinkLayerController::IncomingLeAdvertisementPacket(
    raw_builder_ptr->AddOctets1(static_cast<uint8_t>(
        bluetooth::hci::SubeventCode::EXTENDED_ADVERTISING_REPORT));
    raw_builder_ptr->AddOctets1(0x01);  // num reports
    raw_builder_ptr->AddOctets1(static_cast<uint8_t>(adv_type));
    raw_builder_ptr->AddOctets1(0x01);  // Connectable
    raw_builder_ptr->AddOctets1(0x00);  // Reserved
    raw_builder_ptr->AddOctets1(static_cast<uint8_t>(address_type));
    raw_builder_ptr->AddAddress(address);
    raw_builder_ptr->AddOctets1(1);     // Primary_PHY
@@ -784,14 +785,13 @@ void LinkLayerController::IncomingLeAdvertisementPacket(
    raw_builder_ptr->AddOctets1(0xFF);  // Advertising_SID - not provided
    raw_builder_ptr->AddOctets1(0x7F);  // Tx_Power - Not available
    raw_builder_ptr->AddOctets1(GetRssi());
    raw_builder_ptr->AddOctets1(0);  // Periodic_Advertising_Interval - None
    raw_builder_ptr->AddOctets2(0);  // Periodic_Advertising_Interval - None
    raw_builder_ptr->AddOctets1(0);  // Direct_Address_Type - PUBLIC
    raw_builder_ptr->AddAddress(Address::kEmpty);  // Direct_Address
    raw_builder_ptr->AddOctets1(ad.size());
    raw_builder_ptr->AddOctets(ad);
    auto packet = bluetooth::hci::EventPacketBuilder::Create(
        bluetooth::hci::EventCode::LE_META_EVENT, std::move(raw_builder_ptr));
    send_event_(std::move(packet));
    send_event_(bluetooth::hci::EventPacketBuilder::Create(
        bluetooth::hci::EventCode::LE_META_EVENT, std::move(raw_builder_ptr)));
  }

  // Active scanning
@@ -1084,19 +1084,18 @@ void LinkLayerController::IncomingPageResponsePacket(
void LinkLayerController::TimerTick() {
  if (inquiry_timer_task_id_ != kInvalidTaskId) Inquiry();
  LeAdvertising();
  Connections();
}

void LinkLayerController::LeAdvertising() {
  if (!le_advertising_enable_) {
    return;
  }
  steady_clock::time_point now = steady_clock::now();
  if (duration_cast<milliseconds>(now - last_le_advertisement_) <
  steady_clock::time_point right_now = steady_clock::now();
  if (duration_cast<milliseconds>(right_now - last_le_advertisement_) <
      milliseconds(200)) {
    return;
  }
  last_le_advertisement_ = now;
  last_le_advertisement_ = right_now;

  auto own_address_type = static_cast<model::packets::AddressType>(
      properties_.GetLeAdvertisingOwnAddressType());
@@ -1111,13 +1110,10 @@ void LinkLayerController::LeAdvertising() {
      advertising_address, Address::kEmpty, own_address_type,
      static_cast<model::packets::AdvertisementType>(own_address_type),
      properties_.GetLeAdvertisement());
  LOG_INFO("%zu length", properties_.GetLeAdvertisement().size());
  SendLeLinkLayerPacket(std::move(to_send));
}

void LinkLayerController::Connections() {
  // TODO: Keep connections alive?
}

void LinkLayerController::RegisterEventChannel(
    const std::function<
        void(std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>& callback) {
Loading