xref: /aosp_15_r20/external/pigweed/pw_bluetooth_proxy/public/pw_bluetooth_proxy/gatt_notify_channel.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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_write_channel.h"
18 
19 namespace pw::bluetooth::proxy {
20 
21 /// `GattNotifyChannel` supports sending GATT characteristic notifications to a
22 /// remote peer.
23 class GattNotifyChannel : public L2capWriteChannel {
24  public:
25   /// Send a GATT Notify to the remote peer.
26   ///
27   /// @param[in] attribute_value The data to be sent. Data will be copied
28   ///                            before function completes.
29   ///
30   /// @returns @rst
31   ///
32   /// .. pw-status-codes::
33   ///  OK: If notify was successfully queued for send.
34   ///  UNAVAILABLE: If channel could not acquire the resources to queue the send
35   ///               at this time (transient error).
36   ///  INVALID_ARGUMENT: If `attribute_value` is too large.
37   /// @endrst
38   pw::Status Write(pw::span<const uint8_t> attribute_value);
39 
40  protected:
41   static pw::Result<GattNotifyChannel> Create(
42       L2capChannelManager& l2cap_channel_manager,
43       uint16_t connection_handle,
44       uint16_t attribute_handle);
45 
46  private:
47   // TODO: https://pwbug.dev/349602172 - Define ATT CID in pw_bluetooth.
48   static constexpr uint16_t kAttributeProtocolCID = 0x0004;
49 
50   explicit GattNotifyChannel(L2capChannelManager& l2cap_channel_manager,
51                              uint16_t connection_handle,
52                              uint16_t attribute_handle);
53 
54   uint16_t attribute_handle_;
55 };
56 
57 }  // namespace pw::bluetooth::proxy
58