xref: /aosp_15_r20/external/pigweed/pw_bluetooth_sapphire/host/hci/sco_connection.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include "pw_bluetooth_sapphire/internal/host/hci/sco_connection.h"
16 
17 #include "pw_bluetooth_sapphire/internal/host/transport/transport.h"
18 
19 namespace bt::hci {
20 
ScoConnection(hci_spec::ConnectionHandle handle,const DeviceAddress & local_address,const DeviceAddress & peer_address,const hci::Transport::WeakPtr & hci)21 ScoConnection::ScoConnection(hci_spec::ConnectionHandle handle,
22                              const DeviceAddress& local_address,
23                              const DeviceAddress& peer_address,
24                              const hci::Transport::WeakPtr& hci)
25     : Connection(handle,
26                  local_address,
27                  peer_address,
28                  hci,
29                  [handle, hci] {
30                    ScoConnection::OnDisconnectionComplete(handle, hci);
31                  }),
32       WeakSelf(this) {
33   // The connection is registered & unregistered with ScoDataChannel by
34   // sco::ScoConnection.
35 }
36 
OnDisconnectionComplete(hci_spec::ConnectionHandle handle,const hci::Transport::WeakPtr & hci)37 void ScoConnection::OnDisconnectionComplete(
38     hci_spec::ConnectionHandle handle, const hci::Transport::WeakPtr& hci) {
39   // ScoDataChannel only exists if HCI SCO is supported by the controller.
40   if (hci->sco_data_channel()) {
41     // The packet count must be cleared after sco::ScoConnection unregisters the
42     // connection.
43     hci->sco_data_channel()->ClearControllerPacketCount(handle);
44   }
45 }
46 
47 }  // namespace bt::hci
48