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

Commit f14a0bf5 authored by Bill Schilit's avatar Bill Schilit Committed by Automerger Merge Worker
Browse files

Add support for rewritting RssiWrapper packets in TestModel. am: e469672e am: 2aa0f94d

parents 5359a095 2aa0f94d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ void PhyLayerFactory::UnregisterAllPhyLayers() {

void PhyLayerFactory::Send(
    const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
    uint32_t id) {
    uint32_t id, [[maybe_unused]] uint32_t device_id) {
  // Convert from a Builder to a View
  auto bytes = std::make_shared<std::vector<uint8_t>>();
  bluetooth::packet::BitInserter i(*bytes);
@@ -69,11 +69,11 @@ void PhyLayerFactory::Send(
      model::packets::LinkLayerPacketView::Create(packet_view);
  ASSERT(link_layer_packet_view.IsValid());

  Send(link_layer_packet_view, id);
  Send(link_layer_packet_view, id, device_id);
}

void PhyLayerFactory::Send(model::packets::LinkLayerPacketView packet,
                           uint32_t id) {
                           uint32_t id, [[maybe_unused]] uint32_t device_id) {
  for (const auto& phy : phy_layers_) {
    if (id != phy->GetId()) {
      phy->Receive(packet);
@@ -118,11 +118,11 @@ PhyLayerImpl::~PhyLayerImpl() {}

void PhyLayerImpl::Send(
    const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet) {
  factory_->Send(packet, GetId());
  factory_->Send(packet, GetId(), GetDeviceId());
}

void PhyLayerImpl::Send(model::packets::LinkLayerPacketView packet) {
  factory_->Send(packet, GetId());
  factory_->Send(packet, GetId(), GetDeviceId());
}

void PhyLayerImpl::Unregister() { factory_->UnregisterPhyLayer(GetId()); }
+5 −3
Original line number Diff line number Diff line
@@ -54,12 +54,14 @@ class PhyLayerFactory {
 protected:
  virtual void Send(
      std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
      uint32_t id);
  virtual void Send(model::packets::LinkLayerPacketView packet, uint32_t id);
      uint32_t phy_id, uint32_t device_id);
  virtual void Send(
      model::packets::LinkLayerPacketView packet,
      uint32_t phy_id, uint32_t device_id);
  std::list<std::shared_ptr<PhyLayer>> phy_layers_;

 private:
  Phy::Type phy_type_;
  std::list<std::shared_ptr<PhyLayer>> phy_layers_;
  uint32_t next_id_{1};
  const uint32_t factory_id_;
};
+13 −8
Original line number Diff line number Diff line
@@ -98,10 +98,14 @@ void TestModel::Del(size_t dev_index) {

size_t TestModel::AddPhy(Phy::Type phy_type) {
  size_t factory_id = phys_.size();
  phys_.emplace_back(phy_type, factory_id);
  phys_.push_back(std::move(CreatePhy(phy_type, factory_id)));
  return factory_id;
}

std::unique_ptr<PhyLayerFactory> TestModel::CreatePhy(Phy::Type phy_type, size_t factory_id) {
  return std::make_unique<PhyLayerFactory>(phy_type, factory_id);
}

void TestModel::DelPhy(size_t phy_index) {
  if (phy_index >= phys_.size()) {
    LOG_WARN("Unknown phy at index %zu", phy_index);
@@ -109,7 +113,7 @@ void TestModel::DelPhy(size_t phy_index) {
  }
  schedule_task_(
      model_user_id_, std::chrono::milliseconds(0),
      [this, phy_index]() { phys_[phy_index].UnregisterAllPhyLayers(); });
      [this, phy_index]() { phys_[phy_index]->UnregisterAllPhyLayers(); });
}

void TestModel::AddDeviceToPhy(size_t dev_index, size_t phy_index) {
@@ -122,7 +126,7 @@ void TestModel::AddDeviceToPhy(size_t dev_index, size_t phy_index) {
    return;
  }
  auto dev = devices_[dev_index];
  dev->RegisterPhyLayer(phys_[phy_index].GetPhyLayer(
  dev->RegisterPhyLayer(phys_[phy_index]->GetPhyLayer(
      [dev](model::packets::LinkLayerPacketView packet) {
        dev->IncomingPacket(std::move(packet));
      },
@@ -141,8 +145,8 @@ void TestModel::DelDeviceFromPhy(size_t dev_index, size_t phy_index) {
  schedule_task_(model_user_id_, std::chrono::milliseconds(0),
                 [this, dev_index, phy_index]() {
                   devices_[dev_index]->UnregisterPhyLayer(
                       phys_[phy_index].GetType(),
                       phys_[phy_index].GetFactoryId());
                       phys_[phy_index]->GetType(),
                       phys_[phy_index]->GetFactoryId());
                 });
}

@@ -154,7 +158,7 @@ void TestModel::AddLinkLayerConnection(std::shared_ptr<Device> dev,
  AsyncUserId user_id = get_user_id_();

  for (size_t i = 0; i < phys_.size(); i++) {
    if (phy_type == phys_[i].GetType()) {
    if (phy_type == phys_[i]->GetType()) {
      AddDeviceToPhy(index, i);
    }
  }
@@ -175,7 +179,7 @@ void TestModel::AddRemote(const std::string& server, int port,
  AddLinkLayerConnection(dev, phy_type);
}

void TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) {
size_t TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) {
  size_t index = Add(std::static_pointer_cast<Device>(dev));

  uint8_t raw[] = {0xda, 0x4c, 0x10, 0xde, 0x17, uint8_t(index)};  // Da HCI dev
@@ -197,6 +201,7 @@ void TestModel::AddHciConnection(std::shared_ptr<HciDevice> dev) {
        user_id, std::chrono::milliseconds(0),
        [this, index, user_id]() { OnConnectionClosed(index, user_id); });
  });
  return index;
}

void TestModel::OnConnectionClosed(size_t index, AsyncUserId user_id) {
@@ -232,7 +237,7 @@ const std::string& TestModel::List() {
  list_string_ += " Phys: \r\n";
  for (size_t i = 0; i < phys_.size(); i++) {
    list_string_ += "  " + std::to_string(i) + ":";
    list_string_ += phys_[i].ToString() + " \r\n";
    list_string_ += phys_[i]->ToString() + " \r\n";
  }
  return list_string_;
}
+7 −3
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ class TestModel {
      std::function<void(AsyncTaskId)> cancel,
      std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)>
          connect_to_remote);
  ~TestModel();
  virtual ~TestModel();

  TestModel(TestModel& model) = delete;
  TestModel& operator=(const TestModel& model) = delete;
@@ -65,6 +65,9 @@ class TestModel {
  // Add phy, return its index
  size_t AddPhy(Phy::Type phy_type);

  // Allow derived classes to use custom phy layer
  virtual std::unique_ptr<PhyLayerFactory> CreatePhy(Phy::Type phy_type, size_t phy_index);

  // Remove phy by index
  void DelPhy(size_t phy_index);

@@ -76,7 +79,8 @@ class TestModel {

  // Handle incoming remote connections
  void AddLinkLayerConnection(std::shared_ptr<Device> dev, Phy::Type phy_type);
  void AddHciConnection(std::shared_ptr<HciDevice> dev);
  // Add an HCI device, return its index
  size_t AddHciConnection(std::shared_ptr<HciDevice> dev);

  // Handle closed remote connections (both hci & link layer)
  void OnConnectionClosed(size_t index, AsyncUserId user_id);
@@ -100,7 +104,7 @@ class TestModel {
  void Reset();

 private:
  std::vector<PhyLayerFactory> phys_;
  std::vector<std::unique_ptr<PhyLayerFactory>> phys_;
  std::vector<std::shared_ptr<Device>> devices_;
  std::string list_string_;