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

Commit 39a4eebe authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "RootCanal: Refactor PHY abstraction"

parents 1c347ca0 b1d18dd3
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ Return<void> BluetoothHci::initialize_impl(
      [this](AsyncTaskId task) { async_manager_.CancelAsyncTask(task); });

  // Add the controller as a device in the model.
  size_t controller_index = test_model_.Add(controller_);
  size_t controller_index = test_model_.AddDevice(controller_);
  size_t low_energy_phy_index =
      test_model_.AddPhy(rootcanal::Phy::Type::LOW_ENERGY);
  size_t classic_phy_index = test_model_.AddPhy(rootcanal::Phy::Type::BR_EDR);
@@ -227,11 +227,11 @@ Return<void> BluetoothHci::initialize_impl(
  } else {
    // This should be configurable in the future.
    LOG_INFO("Adding Beacons so the scan list is not empty.");
    test_channel_.Add({"beacon", "be:ac:10:00:00:01", "1000"});
    test_channel_.AddDevice({"beacon", "be:ac:10:00:00:01", "1000"});
    test_model_.AddDeviceToPhy(controller_index + 1, low_energy_phy_index);
    test_channel_.Add({"beacon", "be:ac:10:00:00:02", "1000"});
    test_channel_.AddDevice({"beacon", "be:ac:10:00:00:02", "1000"});
    test_model_.AddDeviceToPhy(controller_index + 2, low_energy_phy_index);
    test_channel_.Add(
    test_channel_.AddDevice(
        {"scripted_beacon", "5b:ea:c1:00:00:03",
         "/data/vendor/bluetooth/bluetooth_sim_ble_playback_file",
         "/data/vendor/bluetooth/bluetooth_sim_ble_playback_events"});
+2 −1
Original line number Diff line number Diff line
@@ -96,7 +96,8 @@ cc_library_static {
        "model/hci/hci_socket_transport.cc",
        "model/setup/async_manager.cc",
        "model/setup/device_boutique.cc",
        "model/setup/phy_layer_factory.cc",
        "model/setup/phy_layer.cc",
        "model/setup/phy_device.cc",
        "model/setup/test_channel_transport.cc",
        "model/setup/test_command_handler.cc",
        "model/setup/test_model.cc",
+4 −3
Original line number Diff line number Diff line
@@ -41,12 +41,13 @@ std::string DualModeController::GetTypeString() const {
  return "Simulated Bluetooth Controller";
}

void DualModeController::IncomingPacket(
    model::packets::LinkLayerPacketView incoming, int8_t rssi) {
void DualModeController::ReceiveLinkLayerPacket(
    model::packets::LinkLayerPacketView incoming, Phy::Type /*type*/,
    int8_t rssi) {
  link_layer_controller_.IncomingPacket(incoming, rssi);
}

void DualModeController::TimerTick() { link_layer_controller_.TimerTick(); }
void DualModeController::Tick() { link_layer_controller_.Tick(); }

void DualModeController::Close() {
  link_layer_controller_.Close();
+4 −3
Original line number Diff line number Diff line
@@ -66,10 +66,11 @@ class DualModeController
  // Device methods.
  virtual std::string GetTypeString() const override;

  virtual void IncomingPacket(model::packets::LinkLayerPacketView incoming,
  virtual void ReceiveLinkLayerPacket(
      model::packets::LinkLayerPacketView incoming, Phy::Type type,
      int8_t rssi) override;

  virtual void TimerTick() override;
  virtual void Tick() override;
  virtual void Close() override;

  // Route commands and data from the stack.
+11 −25
Original line number Diff line number Diff line
@@ -55,16 +55,10 @@ class BaseController : public DualModeController {
  }
  ~BaseController() = default;

  void RegisterLLChannel(
      std::function<void(std::shared_ptr<std::vector<uint8_t>>)> const&
          send_ll) {
    send_ll_ = send_ll;
  }

  void Start() {
    if (timer_task_id_ == kInvalidTaskId) {
      timer_task_id_ = async_manager_.ExecAsyncPeriodically(
          0, 0ms, 5ms, [this]() { this->TimerTick(); });
          0, 0ms, 5ms, [this]() { this->Tick(); });
    }
  }

@@ -75,18 +69,7 @@ class BaseController : public DualModeController {
    }
  }

  virtual void SendLinkLayerPacket(
      std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
      Phy::Type /*phy_type*/, int8_t /*tx_power*/) override {
    auto bytes = std::make_shared<std::vector<uint8_t>>();
    bluetooth::packet::BitInserter inserter(*bytes);
    bytes->reserve(packet->size());
    packet->Serialize(inserter);
    send_ll_(bytes);
  }

 private:
  std::function<void(std::shared_ptr<std::vector<uint8_t>>)> send_ll_{};
  AsyncManager async_manager_{};
  AsyncTaskId timer_task_id_{kInvalidTaskId};

@@ -168,11 +151,12 @@ PYBIND11_MODULE(lib_rootcanal_python3, m) {
              hci::Type::ISO,
              py::bytes(reinterpret_cast<char*>(data->data()), data->size()));
        });
    controller->RegisterLLChannel(
        [=](std::shared_ptr<std::vector<uint8_t>> data) {
    controller->RegisterLinkLayerChannel([=](std::vector<uint8_t> const& data,
                                             Phy::Type /*type*/,
                                             int8_t /*tx_power*/) {
      pybind11::gil_scoped_acquire acquire;
      ll_handler(
              py::bytes(reinterpret_cast<char*>(data->data()), data->size()));
          py::bytes(reinterpret_cast<const char*>(data.data()), data.size()));
    });
    return controller;
  }));
@@ -229,7 +213,9 @@ PYBIND11_MODULE(lib_rootcanal_python3, m) {
          std::cerr << "Dropping malformed LL packet" << std::endl;
          return;
        }
        controller->IncomingPacket(std::move(packet), rssi);
        // TODO: pass correct phy information to ReceiveLinkLayerPacket.
        controller->ReceiveLinkLayerPacket(std::move(packet),
                                           Phy::Type::LOW_ENERGY, rssi);
      });
}

Loading