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