src/connectivity/bluetooth/core/bt-host/gap/bredr_connection_manager.cc
// Build connection state for a new connection and begin interrogation. L2CAP is not enabled for
// this link but pairing is allowed before interrogation completes.
Build connection state for a new connection and begin interrogation. L2CAP is not enabled for
this link but pairing is allowed before interrogation completes.
Build connection state for a new connection and begin interrogation . L2CAP is not enabled for this link but pairing is allowed before interrogation completes .
void BrEdrConnectionManager::InitializeConnection(DeviceAddress addr,
                                                  hci::ConnectionHandle connection_handle) {
  auto link = hci::Connection::CreateACL(connection_handle, hci::Connection::Role::kMaster,
                                         local_address_, addr, hci_);
  Peer* const peer = FindOrInitPeer(addr);
  ZX_DEBUG_ASSERT(!FindConnectionById(peer->identifier()));
  peer->MutBrEdr().SetConnectionState(ConnectionState::kInitializing);
  auto request_node = connection_requests_.extract(peer->identifier());
  std::optional<BrEdrConnection::Request> request =
      request_node ? std::move(request_node.mapped()) : std::optional<BrEdrConnection::Request>();
  const hci::ConnectionHandle handle = link->handle();
  auto send_auth_request_cb = [this, handle]() {
    this->SendAuthenticationRequested(handle, [handle](auto status) {
      bt_is_error(status, WARN, "gap-bredr", "authentication requested command failed for %#.4x",
                  handle);
    });
  };
  BrEdrConnection& connection =
      connections_
          .try_emplace(handle, this, peer->identifier(), std::move(link),
                       std::move(send_auth_request_cb), cache_, std::move(request))
          .first->second;
  connection.pairing_state().SetPairingDelegate(pairing_delegate_);
  auto self = weak_ptr_factory_.GetWeakPtr();
  interrogator_.Start(peer->identifier(), handle, [peer, self, handle](auto status) {
    if (!self) {
      return;
    }
    if (bt_is_error(status, WARN, "gap-bredr", "interrogate failed, dropping connection")) {
      self->Disconnect(peer->identifier());
      return;
    }
    bt_log(TRACE, "gap-bredr", "interrogation complete for %#.4x", handle);
    self->CompleteConnectionSetup(peer, handle);
  });
  if (pending_request_.has_value() && addr == pending_request_->peer_address()) {
    pending_request_.reset();
  }
  TryCreateNextConnection();
}
void BrEdrConnectionManager :: InitializeConnection ( DeviceAddress addr , hci :: ConnectionHandle connection_handle ) { auto link = hci :: Connection :: CreateACL ( connection_handle , hci :: Connection :: Role :: kMaster , local_address_ , addr , hci_ ) ; Peer * const peer = FindOrInitPeer ( addr ) ; ZX_DEBUG_ASSERT ( ! FindConnectionById ( peer -> identifier ( ) ) ) ; peer -> MutBrEdr ( ) . SetConnectionState ( ConnectionState :: kInitializing ) ; auto request_node = connection_requests_ . extract ( peer -> identifier ( ) ) ; std :: optional < BrEdrConnection :: Request > request = request_node ? std :: move ( request_node . mapped ( ) ) : std :: optional < BrEdrConnection :: Request > ( ) ; const hci :: ConnectionHandle handle = link -> handle ( ) ; auto send_auth_request_cb = [ this , handle ] ( ) { this -> SendAuthenticationRequested ( handle , [ handle ] ( auto status ) { bt_is_error ( status , WARN , " " , " " , handle ) ; } ) ; } ; BrEdrConnection & connection = connections_ . try_emplace ( handle , this , peer -> identifier ( ) , std :: move ( link ) , std :: move ( send_auth_request_cb ) , cache_ , std :: move ( request ) ) . first -> second ; connection . pairing_state ( ) . SetPairingDelegate ( pairing_delegate_ ) ; auto self = weak_ptr_factory_ . GetWeakPtr ( ) ; interrogator_ . Start ( peer -> identifier ( ) , handle , [ peer , self , handle ] ( auto status ) { if ( ! self ) { return ; } if ( bt_is_error ( status , WARN , " " , " " ) ) { self -> Disconnect ( peer -> identifier ( ) ) ; return ; } bt_log ( TRACE , " " , " " , handle ) ; self -> CompleteConnectionSetup ( peer , handle ) ; } ) ; if ( pending_request_ . has_value ( ) && addr == pending_request_ -> peer_address ( ) ) { pending_request_ . reset ( ) ; } TryCreateNextConnection ( ) ; }
Build connection state for a new connection and begin interrogation.
Build connection state for a new connection and begin interrogation .
// TODO(BT-288): support non-master connections. // We should never have more than one link to a given peer // The controller has completed the HCI connection procedure, so the connection request can no // longer be failed by a lower layer error. Now tie error reporting of the request to the lifetime // of the connection state object (BrEdrConnection RAII). // Interrogate this peer to find out its version/capabilities. // If this connection was locally requested, requester(s) are notified by the disconnection. // If this was our in-flight request, close it