• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 HIMSA II K/S - www.himsa.com.
3  * Represented by EHIMA - www.ehima.com
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "btm_iso_api_types.h"
26 
27 namespace bluetooth {
28 namespace hci {
29 namespace iso_manager {
30 struct CigCallbacks {
31   virtual ~CigCallbacks() = default;
32   virtual void OnSetupIsoDataPath(uint8_t status, uint16_t conn_handle,
33                                   uint8_t cig_id) = 0;
34   virtual void OnRemoveIsoDataPath(uint8_t status, uint16_t conn_handle,
35                                    uint8_t cig_id) = 0;
36   virtual void OnIsoLinkQualityRead(
37       uint8_t conn_handle, uint8_t cig_id, uint32_t txUnackedPackets,
38       uint32_t txFlushedPackets, uint32_t txLastSubeventPackets,
39       uint32_t retransmittedPackets, uint32_t crcErrorPackets,
40       uint32_t rxUnreceivedPackets, uint32_t duplicatePackets) = 0;
41 
42   virtual void OnCisEvent(uint8_t event, void* data) = 0;
43   virtual void OnCigEvent(uint8_t event, void* data) = 0;
44 };
45 
46 struct BigCallbacks {
47   virtual ~BigCallbacks() = default;
48   virtual void OnSetupIsoDataPath(uint8_t status, uint16_t conn_handle,
49                                   uint8_t big_id) = 0;
50   virtual void OnRemoveIsoDataPath(uint8_t status, uint16_t conn_handle,
51                                    uint8_t big_id) = 0;
52 
53   virtual void OnBigEvent(uint8_t event, void* data) = 0;
54 };
55 }  // namespace iso_manager
56 
57 class IsoManager {
58  public:
59   IsoManager();
60   IsoManager(const IsoManager&) = delete;
61   IsoManager& operator=(const IsoManager&) = delete;
62 
63   virtual ~IsoManager();
64 
GetInstance()65   static IsoManager* GetInstance() {
66     static IsoManager* instance = new IsoManager();
67     return instance;
68   }
69 
70   /**
71    * Set CIG and CIS related callbacks
72    *
73    * <p> Shall be set by the Le Audio Unicaster implementation
74    *
75    * @param callbacks CigCallbacks implementation
76    */
77   virtual void RegisterCigCallbacks(iso_manager::CigCallbacks* callbacks) const;
78 
79   /**
80    * Set BIG related callbacks
81    *
82    * <p> Shall be set by the Le Audio Broadcaster implementation
83    *
84    * @param callbacks BigCallbacks implementation
85    */
86   virtual void RegisterBigCallbacks(iso_manager::BigCallbacks* callbacks) const;
87 
88   /**
89    * Creates connected isochronous group (CIG) according to given params.
90    *
91    * @param cig_id connected isochronous group id
92    * @param cig_params CIG parameters
93    */
94   virtual void CreateCig(uint8_t cig_id,
95                          struct iso_manager::cig_create_params cig_params);
96 
97   /**
98    * Reconfigures connected isochronous group (CIG) according to given params.
99    *
100    * @param cig_id connected isochronous group id
101    * @param cig_params CIG parameters
102    */
103   virtual void ReconfigureCig(uint8_t cig_id,
104                               struct iso_manager::cig_create_params cig_params);
105 
106   /**
107    * Initiates removing of connected isochronous group (CIG).
108    *
109    * @param cig_id connected isochronous group id
110    * @param force do not check if CIG exist
111    */
112   virtual void RemoveCig(uint8_t cig_id, bool force = false);
113 
114   /**
115    * Initiates creation of connected isochronous stream (CIS).
116    *
117    * @param conn_params A set of cis and acl connection handles
118    */
119   virtual void EstablishCis(
120       struct iso_manager::cis_establish_params conn_params);
121 
122   /**
123    * Initiates disconnection of connected isochronous stream (CIS).
124    *
125    * @param conn_handle CIS connection handle
126    * @param reason HCI reason for disconnection
127    */
128   virtual void DisconnectCis(uint16_t conn_handle, uint8_t reason);
129 
130   /**
131    * Initiates creation of isochronous data path for connected isochronous
132    * stream.
133    *
134    * @param conn_handle handle of BIS or CIS connection
135    * @param path_params iso data path parameters
136    */
137   virtual void SetupIsoDataPath(
138       uint16_t conn_handle,
139       struct iso_manager::iso_data_path_params path_params);
140 
141   /**
142    * Initiates removal of isochronous data path for connected isochronous
143    * stream.
144    *
145    * @param conn_handle handle of BIS or CIS connection
146    * @param data_path_dir iso data path direction
147    */
148   virtual void RemoveIsoDataPath(uint16_t conn_handle, uint8_t data_path_dir);
149 
150   /**
151    * Reads the ISO link quality. OnIsoLinkQualityRead callback is invoked only
152    * if read is successful.
153    *
154    * @param conn_handle handle of ISO connection
155    */
156   virtual void ReadIsoLinkQuality(uint16_t conn_handle);
157 
158   /**
159    * Sends iso data to the controller
160    *
161    * @param conn_handle handle of BIS or CIS connection
162    * @param data data buffer. The ownership of data is not being transferred.
163    * @param data_len data buffer length
164    */
165   virtual void SendIsoData(uint16_t conn_handle, const uint8_t* data,
166                            uint16_t data_len);
167 
168   /**
169    * Creates the Broadcast Isochronous Group
170    *
171    * @param big_id host assigned BIG identifier
172    * @param big_params BIG parameters
173    */
174   virtual void CreateBig(uint8_t big_id,
175                          struct iso_manager::big_create_params big_params);
176 
177   /**
178    * Terminates the Broadcast Isochronous Group
179    *
180    * @param big_id host assigned BIG identifier
181    * @param reason termination reason data
182    */
183   virtual void TerminateBig(uint8_t big_id, uint8_t reason);
184 
185   /* Below are defined handlers called by the legacy code in btu_hcif.cc */
186 
187   /**
188    * Handles Iso Data packets from the controller
189    *
190    * @param p_msg raw data packet. The ownership of p_msg is not being
191    * transferred.
192    */
193   virtual void HandleIsoData(void* p_msg);
194 
195   /**
196    * Handles disconnect HCI event
197    *
198    * <p> This callback can be called with handles other than ISO connection
199    * handles.
200    *
201    * @param conn_handle connection handle
202    * @param reason HCI reason for disconnection
203    */
204   virtual void HandleDisconnect(uint16_t conn_handle, uint8_t reason);
205 
206   /**
207    * Handles HCI event for the number of completed packets
208    *
209    * @param p raw packet buffer for the event. The ownership of p is not being
210    * transferred.
211    * @param evt_len event packet buffer length
212    */
213   virtual void HandleNumComplDataPkts(uint8_t* p, uint8_t evt_len);
214   virtual void HandleGdNumComplDataPkts(uint16_t handle, uint16_t credits);
215 
216   /**
217    * Handle CIS and BIG related HCI events
218    *
219    * @param sub_code ble subcode for the HCI event
220    * @param params raw packet buffer for the event. The ownership of params is
221    * not being transferred
222    * @param length event packet buffer length
223    */
224   virtual void HandleHciEvent(uint8_t sub_code, uint8_t* params,
225                               uint16_t length);
226 
227   /**
228    * Starts the IsoManager module
229    */
230   void Start();
231 
232   /**
233    * Stops the IsoManager module
234    */
235   void Stop();
236 
237   /**
238    * Dumps the IsoManager module state
239    */
240   void Dump(int fd);
241 
242  private:
243   struct impl;
244   std::unique_ptr<impl> pimpl_;
245 };
246 
247 }  // namespace hci
248 }  // namespace bluetooth
249