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 <cstdint> 18 19 #include "pw_bluetooth_proxy/internal/l2cap_channel.h" 20 21 namespace pw::bluetooth::proxy { 22 23 /// `GattNotifyChannel` supports sending GATT characteristic notifications to a 24 /// remote peer. 25 class GattNotifyChannel : public L2capChannel { 26 public: 27 GattNotifyChannel(const GattNotifyChannel& other) = delete; 28 GattNotifyChannel& operator=(const GattNotifyChannel& other) = delete; 29 GattNotifyChannel(GattNotifyChannel&&) = default; 30 // Move assignment operator allows channels to be erased from pw_containers. 31 GattNotifyChannel& operator=(GattNotifyChannel&& other) = default; 32 ~GattNotifyChannel() override; 33 34 /// Return the attribute handle of this GattNotify channel. attribute_handle()35 uint16_t attribute_handle() const { return attribute_handle_; } 36 37 // @deprecated 38 // TODO: https://pwbug.dev/379337272 - Delete this once all downstreams 39 // have transitioned to Write(MultiBuf) for this channel type. 40 Status Write(pw::span<const uint8_t> attribute_value) override; 41 42 // Also make visible Write(MultiBuf) 43 // TODO: https://pwbug.dev/379337272 - Can delete when Write(span) is deleted. 44 using L2capChannel::Write; 45 46 protected: 47 static pw::Result<GattNotifyChannel> Create( 48 L2capChannelManager& l2cap_channel_manager, 49 uint16_t connection_handle, 50 uint16_t attribute_handle, 51 ChannelEventCallback&& event_fn); 52 DoHandlePduFromController(pw::span<uint8_t>)53 bool DoHandlePduFromController(pw::span<uint8_t>) override { 54 // Forward all packets to host. 55 return false; 56 } 57 HandlePduFromHost(pw::span<uint8_t>)58 bool HandlePduFromHost(pw::span<uint8_t>) override { 59 // Forward all packets to controller. 60 return false; 61 } 62 DoClose()63 void DoClose() override {} 64 65 private: 66 // TODO: https://pwbug.dev/379337272 - Move to true once this channel uses 67 // payload queue. Delete once all downstreams have transitioned to 68 // Write(MultiBuf) for this channel type. UsesPayloadQueue()69 bool UsesPayloadQueue() override { return false; } 70 71 // TODO: https://pwbug.dev/349602172 - Define ATT CID in pw_bluetooth. 72 static constexpr uint16_t kAttributeProtocolCID = 0x0004; 73 74 explicit GattNotifyChannel(L2capChannelManager& l2cap_channel_manager, 75 uint16_t connection_handle, 76 uint16_t attribute_handle, 77 ChannelEventCallback&& event_fn); 78 79 uint16_t attribute_handle_; 80 }; 81 82 } // namespace pw::bluetooth::proxy 83