src/connectivity/bluetooth/core/bt-host/gap/bredr_connection_manager.cc
// Finish connection setup after a successful interrogation.
Finish connection setup after a successful interrogation.
Finish connection setup after a successful interrogation .
void BrEdrConnectionManager::CompleteConnectionSetup(Peer* peer, hci::ConnectionHandle handle) {
  auto self = weak_ptr_factory_.GetWeakPtr();
  auto connections_iter = connections_.find(handle);
  if (connections_iter == connections_.end()) {
    bt_log(WARN, "gap-bredr", "Connection to complete not found, handle: %#.4x", handle);
    return;
  }
  BrEdrConnection& conn_state = connections_iter->second;
  if (conn_state.peer_id() != peer->identifier()) {
    bt_log(WARN, "gap-bredr",
           "Connection %#.4x is no longer to peer %s (now to %s), ignoring interrogation result",
           handle, bt_str(peer->identifier()), bt_str(conn_state.peer_id()));
    return;
  }
  hci::Connection* const connection = &conn_state.link();
  auto error_handler = [self, peer_id = peer->identifier(), connection = connection->WeakPtr()] {
    if (!self || !connection)
      return;
    bt_log(WARN, "gap-bredr", "Link error received, closing connection %#.4x",
           connection->handle());
    self->Disconnect(peer_id);
  };
  auto security_callback = [](hci::ConnectionHandle handle, sm::SecurityLevel level, auto cb) {
    bt_log(INFO, "gap-bredr", "Ignoring security upgrade request; not implemented");
    cb(sm::Status(HostError::kNotSupported));
  };
  data_domain_->AddACLConnection(handle, connection->role(), error_handler,
                                 std::move(security_callback));
  peer->MutBrEdr().SetConnectionState(ConnectionState::kConnected);
  if (discoverer_.search_count()) {
    data_domain_->OpenL2capChannel(
        handle, l2cap::kSDP, l2cap::ChannelParameters(),
        [self, peer_id = peer->identifier()](auto channel) {
          if (!self)
            return;
          if (!channel) {
            bt_log(ERROR, "gap", "failed to create l2cap channel for SDP (peer id: %s)",
                   bt_str(peer_id));
            return;
          }
          auto client = sdp::Client::Create(std::move(channel));
          self->discoverer_.StartServiceDiscovery(peer_id, std::move(client));
        });
  }
  conn_state.Start(*data_domain_);
}
void BrEdrConnectionManager :: CompleteConnectionSetup ( Peer * peer , hci :: ConnectionHandle handle ) { auto self = weak_ptr_factory_ . GetWeakPtr ( ) ; auto connections_iter = connections_ . find ( handle ) ; if ( connections_iter == connections_ . end ( ) ) { bt_log ( WARN , " " , " " , handle ) ; return ; } BrEdrConnection & conn_state = connections_iter -> second ; if ( conn_state . peer_id ( ) != peer -> identifier ( ) ) { bt_log ( WARN , " " , " " , handle , bt_str ( peer -> identifier ( ) ) , bt_str ( conn_state . peer_id ( ) ) ) ; return ; } hci :: Connection * const connection = & conn_state . link ( ) ; auto error_handler = [ self , peer_id = peer -> identifier ( ) , connection = connection -> WeakPtr ( ) ] { if ( ! self || ! connection ) return ; bt_log ( WARN , " " , " " , connection -> handle ( ) ) ; self -> Disconnect ( peer_id ) ; } ; auto security_callback = [ ] ( hci :: ConnectionHandle handle , sm :: SecurityLevel level , auto cb ) { bt_log ( INFO , " " , " " ) ; cb ( sm :: Status ( HostError :: kNotSupported ) ) ; } ; data_domain_ -> AddACLConnection ( handle , connection -> role ( ) , error_handler , std :: move ( security_callback ) ) ; peer -> MutBrEdr ( ) . SetConnectionState ( ConnectionState :: kConnected ) ; if ( discoverer_ . search_count ( ) ) { data_domain_ -> OpenL2capChannel ( handle , l2cap :: kSDP , l2cap :: ChannelParameters ( ) , [ self , peer_id = peer -> identifier ( ) ] ( auto channel ) { if ( ! self ) return ; if ( ! channel ) { bt_log ( ERROR , " " , " " , bt_str ( peer_id ) ) ; return ; } auto client = sdp :: Client :: Create ( std :: move ( channel ) ) ; self -> discoverer_ . StartServiceDiscovery ( peer_id , std :: move ( client ) ) ; } ) ; } conn_state . Start ( * data_domain_ ) ; }
Finish connection setup after a successful interrogation.
Finish connection setup after a successful interrogation .
// TODO(37650): Implement this callback as a call to InitiatePairing(). // Register with L2CAP to handle services on the ACL signaling channel.