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

Commit 3ee550bf authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge "RootCanal: Send AuthenticationComplete only for initiator"

parents fbbe72c6 df123ce0
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -763,8 +763,8 @@ void LinkLayerController::IncomingIoCapabilityRequestPacket(
            incoming.GetDestinationAddress(), incoming.GetSourceAddress(),
            static_cast<uint8_t>(
                ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE)));
    security_manager_.AuthenticationRequest(incoming.GetSourceAddress(),
                                            handle);
    security_manager_.AuthenticationRequest(incoming.GetSourceAddress(), handle,
                                            false);
    security_manager_.SetPinRequested(peer);
    send_event_(bluetooth::hci::PinCodeRequestBuilder::Create(
        incoming.GetSourceAddress()));
@@ -787,7 +787,7 @@ void LinkLayerController::IncomingIoCapabilityRequestPacket(

  bool pairing_started = security_manager_.AuthenticationInProgress();
  if (!pairing_started) {
    security_manager_.AuthenticationRequest(peer, handle);
    security_manager_.AuthenticationRequest(peer, handle, false);
    StartSimplePairing(peer);
  }

@@ -1496,7 +1496,7 @@ void LinkLayerController::IncomingPinRequestPacket(
    }
  } else {
    LOG_INFO("Incoming authentication request %s", peer.ToString().c_str());
    security_manager_.AuthenticationRequest(peer, handle);
    security_manager_.AuthenticationRequest(peer, handle, false);
  }
  auto current_peer = security_manager_.GetAuthenticationAddress();
  security_manager_.SetRemotePin(peer, request.GetPinCode());
@@ -1766,10 +1766,12 @@ void LinkLayerController::AuthenticateRemoteStage2(const Address& peer) {
  uint16_t handle = security_manager_.GetAuthenticationHandle();
  ASSERT(security_manager_.GetAuthenticationAddress() == peer);
  // Check key in security_manager_ ?
  if (security_manager_.IsInitiator()) {
    auto packet = bluetooth::hci::AuthenticationCompleteBuilder::Create(
        ErrorCode::SUCCESS, handle);
    send_event_(std::move(packet));
  }
}

ErrorCode LinkLayerController::LinkKeyRequestReply(
    const Address& peer, const std::array<uint8_t, 16>& key) {
@@ -1793,7 +1795,7 @@ ErrorCode LinkLayerController::LinkKeyRequestNegativeReply(
  }

  if (properties_.GetSecureSimplePairingSupported()) {
    security_manager_.AuthenticationRequest(address, handle);
    security_manager_.AuthenticationRequest(address, handle, false);

    ScheduleTask(milliseconds(5),
                 [this, address]() { StartSimplePairing(address); });
@@ -2054,7 +2056,7 @@ ErrorCode LinkLayerController::SendKeypressNotification(

void LinkLayerController::HandleAuthenticationRequest(const Address& address,
                                                      uint16_t handle) {
    security_manager_.AuthenticationRequest(address, handle);
  security_manager_.AuthenticationRequest(address, handle, true);
  auto packet = bluetooth::hci::LinkKeyRequestBuilder::Create(address);
  send_event_(std::move(packet));
}
+5 −1
Original line number Diff line number Diff line
@@ -59,10 +59,12 @@ const std::array<uint8_t, 16>& SecurityManager::GetKey(
  return key_store_.at(addr.ToString());
}

void SecurityManager::AuthenticationRequest(const Address& addr, uint16_t handle) {
void SecurityManager::AuthenticationRequest(const Address& addr,
                                            uint16_t handle, bool initiator) {
  authenticating_ = true;
  current_handle_ = handle;
  peer_address_ = addr;
  initiator_ = initiator;
  peer_pin_requested_ = false;
  peer_pin_received_ = false;
  host_pin_received_ = false;
@@ -76,6 +78,8 @@ bool SecurityManager::AuthenticationInProgress() {
  return authenticating_;
}

bool SecurityManager::IsInitiator() { return initiator_; }

uint16_t SecurityManager::GetAuthenticationHandle() {
  return current_handle_;
}
+4 −1
Original line number Diff line number Diff line
@@ -72,10 +72,12 @@ class SecurityManager {

  const std::array<uint8_t, 16>& GetKey(const Address& addr) const;

  void AuthenticationRequest(const Address& addr, uint16_t handle);
  void AuthenticationRequest(const Address& addr, uint16_t handle,
                             bool initiator);
  void AuthenticationRequestFinished();

  bool AuthenticationInProgress();
  bool IsInitiator();
  uint16_t GetAuthenticationHandle();
  Address GetAuthenticationAddress();

@@ -120,6 +122,7 @@ class SecurityManager {
  bool authenticating_{false};
  uint16_t current_handle_{};
  Address peer_address_{};
  bool initiator_{false};
};

}  // namespace test_vendor_lib