1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include "types/bluetooth/uuid.h"
23 #include "types/raw_address.h"
24 
25 namespace bluetooth {
26 namespace ras {
27 
28 struct VendorSpecificCharacteristic {
29   bluetooth::Uuid characteristicUuid_;
30   std::vector<uint8_t> value_;
31   std::vector<uint8_t> reply_value_;
32 };
33 
34 class RasServerCallbacks {
35  public:
36   virtual ~RasServerCallbacks() = default;
37   virtual void OnVendorSpecificReply(
38       const RawAddress& address,
39       const std::vector<VendorSpecificCharacteristic>&
40           vendor_specific_reply) = 0;
41 };
42 
43 class RasServer {
44  public:
45   virtual ~RasServer() = default;
46   virtual void Initialize() = 0;
47   virtual void RegisterCallbacks(RasServerCallbacks* callbacks) = 0;
48   virtual void SetVendorSpecificCharacteristic(
49       const std::vector<VendorSpecificCharacteristic>&
50           vendor_specific_characteristics) = 0;
51   virtual void HandleVendorSpecificReplyComplete(RawAddress address,
52                                                  bool success) = 0;
53   virtual void PushProcedureData(RawAddress address, uint16_t procedure_count,
54                                  bool is_last, std::vector<uint8_t> data) = 0;
55 };
56 
57 RasServer* GetRasServer();
58 
59 class RasClientCallbacks {
60  public:
61   virtual ~RasClientCallbacks() = default;
62   virtual void OnConnected(const RawAddress& address, uint16_t att_handle,
63                            const std::vector<VendorSpecificCharacteristic>&
64                                vendor_specific_characteristics) = 0;
65   virtual void OnWriteVendorSpecificReplyComplete(const RawAddress& address,
66                                                   bool success) = 0;
67   virtual void OnRemoteData(const RawAddress& address,
68                             const std::vector<uint8_t>& data) = 0;
69 };
70 
71 class RasClient {
72  public:
73   virtual ~RasClient() = default;
74   virtual void Initialize() = 0;
75   virtual void RegisterCallbacks(RasClientCallbacks* callbacks) = 0;
76   virtual void Connect(const RawAddress& address) = 0;
77   virtual void SendVendorSpecificReply(
78       const RawAddress& address,
79       const std::vector<VendorSpecificCharacteristic>&
80           vendor_specific_data) = 0;
81 };
82 
83 RasClient* GetRasClient();
84 
85 }  // namespace ras
86 }  // namespace bluetooth
87