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

Commit 9af7bacd authored by Myles Watson's avatar Myles Watson
Browse files

RootCanal: Create Connection Cancel

Bug: 163818400
Test: cert/run --host
Tag: #gd-refactor
Change-Id: I2817cd8659b2db6237b533f634953313c7ca1943
parent ca90aba4
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ DualModeController::DualModeController(const std::string& properties_filename, u
  SET_HANDLER(OpCode::LE_SET_SCAN_ENABLE, LeSetScanEnable);
  SET_HANDLER(OpCode::LE_CREATE_CONNECTION, LeCreateConnection);
  SET_HANDLER(OpCode::CREATE_CONNECTION, CreateConnection);
  SET_HANDLER(OpCode::CREATE_CONNECTION_CANCEL, CreateConnectionCancel);
  SET_HANDLER(OpCode::DISCONNECT, Disconnect);
  SET_HANDLER(OpCode::LE_CREATE_CONNECTION_CANCEL, LeConnectionCancel);
  SET_HANDLER(OpCode::LE_READ_CONNECT_LIST_SIZE, LeReadConnectListSize);
@@ -1604,6 +1605,20 @@ void DualModeController::CreateConnection(CommandPacketView command) {
  send_event_(std::move(packet));
}

void DualModeController::CreateConnectionCancel(CommandPacketView command) {
  auto command_view = gd_hci::CreateConnectionCancelView::Create(
      gd_hci::ConnectionManagementCommandView::Create(command));
  ASSERT(command_view.IsValid());

  Address address = command_view.GetBdAddr();

  auto status = link_layer_controller_.CreateConnectionCancel(address);

  auto packet = bluetooth::hci::CreateConnectionCancelCompleteBuilder::Create(
      kNumCommandPackets, status, address);
  send_event_(std::move(packet));
}

void DualModeController::Disconnect(CommandPacketView command) {
  auto command_view = gd_hci::DisconnectView::Create(
      gd_hci::ConnectionManagementCommandView::Create(command));
@@ -1623,16 +1638,9 @@ void DualModeController::LeConnectionCancel(CommandPacketView command) {
  auto command_view = gd_hci::LeCreateConnectionCancelView::Create(
      gd_hci::LeConnectionManagementCommandView::Create(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.SetLeConnect(false);
  auto packet = bluetooth::hci::LeCreateConnectionCancelCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS);
  send_event_(std::move(packet));
  /* For testing Jakub's patch:  Figure out a neat way to call this without
     recompiling.  I'm thinking about a bad device. */
  /*
  SendCommandCompleteOnlyStatus(OpCode::LE_CREATE_CONNECTION_CANCEL,
                                ErrorCode::COMMAND_DISALLOWED);
  */
  ErrorCode status = link_layer_controller_.SetLeConnect(false);
  send_event_(bluetooth::hci::LeCreateConnectionCancelCompleteBuilder::Create(
      kNumCommandPackets, status));
}

void DualModeController::LeReadConnectListSize(CommandPacketView command) {
+3 −0
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ class DualModeController : public Device {
  // 7.1.6
  void Disconnect(CommandPacketView args);

  // 7.1.7
  void CreateConnectionCancel(CommandPacketView args);

  // 7.1.8
  void AcceptConnectionRequest(CommandPacketView args);

+3 −0
Original line number Diff line number Diff line
@@ -208,6 +208,9 @@ class LinkLayerController {
    le_address_type_ = le_address_type;
  }
  ErrorCode SetLeConnect(bool le_connect) {
    if (le_connect_ == le_connect) {
      return ErrorCode::COMMAND_DISALLOWED;
    }
    le_connect_ = le_connect;
    return ErrorCode::SUCCESS;
  }