• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 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 #pragma once
16 
17 #include "pw_bluetooth_proxy/internal/l2cap_channel.h"
18 #include "pw_bluetooth_proxy/l2cap_channel_common.h"
19 
20 namespace pw::bluetooth::proxy {
21 
22 class BasicL2capChannel : public L2capChannel {
23  public:
24   // TODO: https://pwbug.dev/360929142 - Take the MTU. Signaling channels would
25   // provide MTU_SIG.
26   static pw::Result<BasicL2capChannel> Create(
27       L2capChannelManager& l2cap_channel_manager,
28       multibuf::MultiBufAllocator* rx_multibuf_allocator,
29       uint16_t connection_handle,
30       AclTransportType transport,
31       uint16_t local_cid,
32       uint16_t remote_cid,
33       OptionalPayloadReceiveCallback&& payload_from_controller_fn,
34       OptionalPayloadReceiveCallback&& payload_from_host_fn,
35       ChannelEventCallback&& event_fn);
36 
37   BasicL2capChannel(const BasicL2capChannel& other) = delete;
38   BasicL2capChannel& operator=(const BasicL2capChannel& other) = delete;
39   BasicL2capChannel(BasicL2capChannel&&) = default;
40   // Move assignment operator allows channels to be erased from pw_containers.
41   BasicL2capChannel& operator=(BasicL2capChannel&& other) = default;
42   ~BasicL2capChannel() override;
43 
44   // Overridden here to do additional length checks.
45   StatusWithMultiBuf Write(multibuf::MultiBuf&& payload) override;
46 
47  protected:
48   explicit BasicL2capChannel(
49       L2capChannelManager& l2cap_channel_manager,
50       multibuf::MultiBufAllocator* rx_multibuf_allocator,
51       uint16_t connection_handle,
52       AclTransportType transport,
53       uint16_t local_cid,
54       uint16_t remote_cid,
55       OptionalPayloadReceiveCallback&& payload_from_controller_fn,
56       OptionalPayloadReceiveCallback&& payload_from_host_fn,
57       ChannelEventCallback&& event_fn);
58 
59   bool HandlePduFromHost(pw::span<uint8_t> bframe) override;
60 
DoClose()61   void DoClose() override {}
62 
63  private:
64   bool DoHandlePduFromController(pw::span<uint8_t> bframe) override;
65 
66   // TODO: https://pwbug.dev/379337272 - Delete this once all channels have
67   // transitioned to payload_queue_.
UsesPayloadQueue()68   bool UsesPayloadQueue() override { return true; }
69 
70   [[nodiscard]] std::optional<H4PacketWithH4> GenerateNextTxPacket()
71       PW_EXCLUSIVE_LOCKS_REQUIRED(send_queue_mutex()) override;
72 };
73 
74 }  // namespace pw::bluetooth::proxy
75