• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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.h"
20 #include "bluetooth_headset_callbacks.h"
21 #include "bt_hf.h"
22 #include "types/raw_address.h"
23 
24 namespace bluetooth {
25 namespace headset {
26 
27 /**
28  * Programming interface for Headset profiles in the Fluoride stack
29  * Thread-safe
30  */
31 class Interface {
32 public:
33   virtual ~Interface() = default;
34   /**
35    * Register the BtHf callbacks
36    *
37    * @param callbacks callbacks for the user of the native stack
38    * @param max_hf_clients maximum number of headset clients
39    * @param inband_ringing_enabled whether inband ringtone is enabled
40    * @return BT_STATUS_SUCCESS on success
41    */
42   virtual bt_status_t Init(Callbacks* callbacks, int max_hf_clients,
43                            bool inband_ringing_enabled) = 0;
44 
45   /**
46    * Connect to headset
47    *
48    * @param bd_addr remote device address
49    * @return BT_STATUS_SUCCESS on success
50    */
51   virtual bt_status_t Connect(RawAddress* bd_addr) = 0;
52 
53   /**
54    * Disconnect from headset
55    *
56    * @param bd_addr remote device address
57    * @return BT_STATUS_SUCCESS on success
58    */
59   virtual bt_status_t Disconnect(RawAddress* bd_addr) = 0;
60 
61   /**
62    * Create an audio connection
63    *
64    * @param bd_addr remote device address
65    * @param disabled_codecs bitset of disabled BTM_SCO_CODECs
66    * @return BT_STATUS_SUCCESS on success
67    */
68   virtual bt_status_t ConnectAudio(RawAddress* bd_addr, int disabled_codecs) = 0;
69 
70   /**
71    * Close the audio connection
72    *
73    * @param bd_addr remote device address
74    * @return BT_STATUS_SUCCESS on success
75    */
76   virtual bt_status_t DisconnectAudio(RawAddress* bd_addr) = 0;
77 
78   /**
79    * Checks whether the device support echo cancellation and/or noise reduction
80    * via the AT+BRSF bitmask
81    *
82    * @param bd_addr remote device address
83    * @return BT_STATUS_SUCCESS on success
84    */
85   virtual bt_status_t isNoiseReductionSupported(RawAddress* bd_addr) = 0;
86 
87   /**
88    * Checks whether the device supports voice recognition via the AT+BRSF
89    * bitmask
90    *
91    * @param bd_addr remote device address
92    * @return BT_STATUS_SUCCESS on success
93    */
94   virtual bt_status_t isVoiceRecognitionSupported(RawAddress* bd_addr) = 0;
95 
96   /** start voice recognition */
97   /**
98    * Start voice recognition
99    * @param bd_addr remote device address
100    * @param sendResult whether a BVRA response should be sent
101    * @return BT_STATUS_SUCCESS on success
102    */
103   virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr, bool sendResult) = 0;
104 
105   /**
106    * Stop voice recognition
107    *
108    * @param bd_addr remote device address
109    * @return BT_STATUS_SUCCESS on success
110    */
111   virtual bt_status_t StopVoiceRecognition(RawAddress* bd_addr) = 0;
112 
113   /**
114    * Change HFP related volume on remote headset
115    *
116    * @param type Speaker (+VGS) or Mic (+VGM)
117    * @param volume volume level on scale from 0 to 15, p69, HFP 1.7.1 spec
118    * @param bd_addr remote device address
119    * @return BT_STATUS_SUCCESS on success
120    */
121   virtual bt_status_t VolumeControl(bthf_volume_type_t type, int volume, RawAddress* bd_addr) = 0;
122 
123   /**
124    * Combined device status change notification
125    *
126    * @param ntk_state Network state, available or not available
127    * @param svc_type Service type, roaming or home
128    * @param signal Signal strength, 0 to 5, p86, HFP 1.7.1 spec
129    * @param batt_chg Battery level of the phone, 0 to 5, p87, HFP 1.7.1 spec
130    * @param bd_addr remote device address
131    * @return BT_STATUS_SUCCESS on success
132    */
133   virtual bt_status_t DeviceStatusNotification(bthf_network_state_t ntk_state,
134                                                bthf_service_type_t svc_type, int signal,
135                                                int batt_chg, RawAddress* bd_addr) = 0;
136 
137   /**
138    * Response for COPS (Query Operator Selection) command
139    *
140    * @param cops Operator Name, max length 16 char, p32 HFP 1.7.1 spec
141    * @param bd_addr remote device address
142    * @return BT_STATUS_SUCCESS on success
143    */
144   virtual bt_status_t CopsResponse(const char* cops, RawAddress* bd_addr) = 0;
145 
146   /**
147    * Response for CIND (Stanford Indicator Update) command
148    *
149    * @param svc service availability, available or not available
150    * @param num_active number of active calls
151    * @param num_held number of held calls
152    * @param call_setup_state call setup state
153    * @param signal signal strength, 0 to 5, p86 HFP 1.7.1 spec
154    * @param roam roaming state, 1 for roaming, 0 for home, p86 HFP 1.7.1 spec
155    * @param batt_chg AG battery charge, 0 to 5, p87 HFP 1.7.1 spec
156    * @param bd_addr remote device address
157    * @return BT_STATUS_SUCCESS on success
158    */
159   virtual bt_status_t CindResponse(int svc, int num_active, int num_held,
160                                    bthf_call_state_t call_setup_state, int signal, int roam,
161                                    int batt_chg, RawAddress* bd_addr) = 0;
162 
163   /**
164    * Pre-formatted AT response, typically in response to unknown AT cmd
165    *
166    * @param rsp formatted AT response
167    * @param bd_addr remote device address
168    * @return BT_STATUS_SUCCESS on success
169    */
170   virtual bt_status_t FormattedAtResponse(const char* rsp, RawAddress* bd_addr) = 0;
171 
172   /**
173    * ok/error response to AT commands
174    *
175    * @param response_code OK or ERROR
176    * @param error_code actual error code depend on use case
177    * @param bd_addr remote device address
178    * @return BT_STATUS_SUCCESS on success
179    */
180   virtual bt_status_t AtResponse(bthf_at_response_t response_code, int error_code,
181                                  RawAddress* bd_addr) = 0;
182 
183   /**
184    * Response for CLCC (Current List of Calls) command.
185    * Can be iteratively called for each call index
186    * Call index of 0 will be treated as NULL termination (Completes response)
187    *
188    * @param index index of the call
189    * @param dir direction of the call
190    * @param state state of the call
191    * @param mode mode of the call
192    * @param mpty whether the call is multi party
193    * @param number phone number of the call
194    * @param type type of the call
195    * @param bd_addr remote device address
196    * @return BT_STATUS_SUCCESS on success
197    */
198   virtual bt_status_t ClccResponse(int index, bthf_call_direction_t dir, bthf_call_state_t state,
199                                    bthf_call_mode_t mode, bthf_call_mpty_type_t mpty,
200                                    const char* number, bthf_call_addrtype_t type,
201                                    RawAddress* bd_addr) = 0;
202 
203   /**
204    * Notify of a call state change
205    *  Each update notifies
206    *    1. Number of active/held/ringing calls
207    *    2. call_state: This denotes the state change that triggered this msg
208    *                   This will take one of the values from BtHfCallState
209    *    3. number & type: valid only for incoming & waiting call
210    *
211    * @param num_active number of active calls
212    * @param num_held number of held calls
213    * @param call_setup_state current call setup state
214    * @param number phone number of the call
215    * @param type type of the call
216    * @param name caller display name
217    * @param bd_addr remote device address
218    * @return BT_STATUS_SUCCESS on success
219    */
220   virtual bt_status_t PhoneStateChange(int num_active, int num_held,
221                                        bthf_call_state_t call_setup_state, const char* number,
222                                        bthf_call_addrtype_t type, const char* name,
223                                        RawAddress* bd_addr) = 0;
224 
225   /**
226    * Enable SWB
227    *
228    * @param swbCodec SWB Codec
229    * @param enable true to enable, false to disable
230    * @param bd_addr remote device address
231    * @return BT_STATUS_SUCCESS on success
232    */
233   virtual bt_status_t EnableSwb(bthf_swb_codec_t swbCodec, bool enable, RawAddress* bd_addr) = 0;
234 
235   /**
236    * Closes the interface.
237    */
238   virtual void Cleanup() = 0;
239 
240   /**
241    * Enable/Disable SCO-offloading
242    *
243    * @param value true to enable, false to disable
244    * @return BT_STATUS_SUCCESS on success
245    */
246   virtual bt_status_t SetScoOffloadEnabled(bool value) = 0;
247 
248   /**
249    * Whether we are allowed to initiate SCO
250    *
251    * @param value true to allow, false to disallow
252    * @return BT_STATUS_SUCCESS on success
253    */
254   virtual bt_status_t SetScoAllowed(bool value) = 0;
255 
256   /**
257    * Send +BSIR response code to enable/disable in-band ringtone in an active
258    * HFP service level connection
259    *
260    * @param value true for enabled, false for disable
261    * @param bd_addr remote device address
262    */
263   virtual bt_status_t SendBsir(bool value, RawAddress* bd_addr) = 0;
264 
265   /**
266    * Set the current active headset device for SCO audio
267    *
268    * @param active_device_addr remote device address
269    */
270   virtual bt_status_t SetActiveDevice(RawAddress* active_device_addr) = 0;
271 
272   /**
273    * Trigger a debug dump of the Headset Profile
274    */
275   virtual bt_status_t DebugDump() = 0;
276 };
277 
278 }  // namespace headset
279 }  // namespace bluetooth
280