1 /*
2  * Copyright (C) 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 <bluetooth/log.h>
20 #include <hardware/bluetooth.h>
21 
22 #include <bitset>
23 #include <sstream>
24 
25 namespace bluetooth::le_audio {
26 
27 class GmapClient {
28 public:
29   void AddFromStorage(const RawAddress& addr, const uint8_t role, const uint16_t role_handle,
30                       const uint8_t UGT_feature, const uint16_t UGT_feature_handle);
31 
32   void DebugDump(std::stringstream& stream);
33 
34   static bool IsGmapClientEnabled();
35 
36   static void UpdateGmapOffloaderSupport(bool value);
37 
GmapClient(const RawAddress & addr)38   GmapClient(const RawAddress& addr) : role_handle_(0), UGT_feature_handle_(0), addr_(addr) {}
39 
40   bool parseAndSaveGmapRole(uint16_t len, const uint8_t* value);
41 
42   bool parseAndSaveUGTFeature(uint16_t len, const uint8_t* value);
43 
44   std::bitset<8> getRole();
45 
46   uint16_t getRoleHandle();
47 
48   void setRoleHandle(uint16_t handle);
49 
50   std::bitset<8> getUGTFeature();
51 
52   uint16_t getUGTFeatureHandle();
53 
54   void setUGTFeatureHandle(uint16_t handle);
55 
56   constexpr static uint16_t kGmapRoleLen = 1;
57   constexpr static uint16_t kGmapUGTFeatureLen = 1;
58 
59 private:
60   static bool is_offloader_support_gmap_;
61   std::bitset<8> role_;
62   uint16_t role_handle_;
63   std::bitset<8> UGT_feature_;
64   uint16_t UGT_feature_handle_;
65   RawAddress addr_;
66 };
67 }  // namespace bluetooth::le_audio
68