• 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 <raw_address.h>
20 
21 #include "bluetooth_headset_callbacks.h"
22 #include "bt_hf.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    * @return BT_STATUS_SUCCESS on success
66    */
67   virtual bt_status_t ConnectAudio(RawAddress* bd_addr) = 0;
68 
69   /**
70    * Close the audio connection
71    *
72    * @param bd_addr remote device address
73    * @return BT_STATUS_SUCCESS on success
74    */
75   virtual bt_status_t DisconnectAudio(RawAddress* bd_addr) = 0;
76 
77   /**
78    * Checks whether the device support echo cancellation and/or noise reduction
79    * via the AT+BRSF bitmask
80    *
81    * @param bd_addr remote device address
82    * @return BT_STATUS_SUCCESS on success
83    */
84   virtual bt_status_t isNoiseReductionSupported(RawAddress* bd_addr) = 0;
85 
86   /**
87    * Checks whether the device supports voice recognition via the AT+BRSF
88    * bitmask
89    *
90    * @param bd_addr remote device address
91    * @return BT_STATUS_SUCCESS on success
92    */
93   virtual bt_status_t isVoiceRecognitionSupported(RawAddress* bd_addr) = 0;
94 
95   /** start voice recognition */
96   /**
97    * Start voice recognition
98    * @param bd_addr remote device address
99    * @return BT_STATUS_SUCCESS on success
100    */
101   virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr) = 0;
102 
103   /**
104    * Stop voice recognition
105    *
106    * @param bd_addr remote device address
107    * @return BT_STATUS_SUCCESS on success
108    */
109   virtual bt_status_t StopVoiceRecognition(RawAddress* bd_addr) = 0;
110 
111   /**
112    * Change HFP related volume on remote headset
113    *
114    * @param type Speaker (+VGS) or Mic (+VGM)
115    * @param volume volume level on scale from 0 to 15, p69, HFP 1.7.1 spec
116    * @param bd_addr remote device address
117    * @return BT_STATUS_SUCCESS on success
118    */
119   virtual bt_status_t VolumeControl(bthf_volume_type_t type, int volume,
120                                     RawAddress* bd_addr) = 0;
121 
122   /**
123    * Combined device status change notification
124    *
125    * @param ntk_state Network state, available or not available
126    * @param svc_type Service type, roaming or home
127    * @param signal Signal strength, 0 to 5, p86, HFP 1.7.1 spec
128    * @param batt_chg Battery level of the phone, 0 to 5, p87, HFP 1.7.1 spec
129    * @param bd_addr remote device address
130    * @return BT_STATUS_SUCCESS on success
131    */
132   virtual bt_status_t DeviceStatusNotification(bthf_network_state_t ntk_state,
133                                                bthf_service_type_t svc_type,
134                                                int signal, int batt_chg,
135                                                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,
161                                    int signal, int roam, int batt_chg,
162                                    RawAddress* bd_addr) = 0;
163 
164   /**
165    * Pre-formatted AT response, typically in response to unknown AT cmd
166    *
167    * @param rsp formatted AT response
168    * @param bd_addr remote device address
169    * @return BT_STATUS_SUCCESS on success
170    */
171   virtual bt_status_t FormattedAtResponse(const char* rsp,
172                                           RawAddress* bd_addr) = 0;
173 
174   /**
175    * ok/error response to AT commands
176    *
177    * @param response_code OK or ERROR
178    * @param error_code actual error code depend on use case
179    * @param bd_addr remote device address
180    * @return BT_STATUS_SUCCESS on success
181    */
182   virtual bt_status_t AtResponse(bthf_at_response_t response_code,
183                                  int error_code, RawAddress* bd_addr) = 0;
184 
185   /**
186    * Response for CLCC (Current List of Calls) command.
187    * Can be iteratively called for each call index
188    * Call index of 0 will be treated as NULL termination (Completes response)
189    *
190    * @param index index of the call
191    * @param dir direction of the call
192    * @param state state of the call
193    * @param mode mode of the call
194    * @param mpty whether the call is multi party
195    * @param number phone number of the call
196    * @param type type of the call
197    * @param bd_addr remote device address
198    * @return BT_STATUS_SUCCESS on success
199    */
200   virtual bt_status_t ClccResponse(
201       int index, bthf_call_direction_t dir, bthf_call_state_t state,
202       bthf_call_mode_t mode, bthf_call_mpty_type_t mpty, const char* number,
203       bthf_call_addrtype_t type, RawAddress* bd_addr) = 0;
204 
205   /**
206    * Notify of a call state change
207    *  Each update notifies
208    *    1. Number of active/held/ringing calls
209    *    2. call_state: This denotes the state change that triggered this msg
210    *                   This will take one of the values from BtHfCallState
211    *    3. number & type: valid only for incoming & waiting call
212    *
213    * @param num_active number of active calls
214    * @param num_held number of held calls
215    * @param call_setup_state current call setup state
216    * @param number phone number of the call
217    * @param type type of the call
218    * @param name caller display name
219    * @param bd_addr remote device address
220    * @return BT_STATUS_SUCCESS on success
221    */
222   virtual bt_status_t PhoneStateChange(int num_active, int num_held,
223                                        bthf_call_state_t call_setup_state,
224                                        const char* number,
225                                        bthf_call_addrtype_t type,
226                                        const char* name,
227                                        RawAddress* bd_addr) = 0;
228 
229   /**
230    * Closes the interface.
231    */
232   virtual void Cleanup() = 0;
233 
234   /**
235    * Whether we are allowed to initiate SCO
236    *
237    * @param value true to allow, false to disallow
238    * @return BT_STATUS_SUCCESS on success
239    */
240   virtual bt_status_t SetScoAllowed(bool value) = 0;
241 
242   /**
243    * Send +BSIR response code to enable/disable in-band ringtone in an active
244    * HFP service level connection
245    *
246    * @param value true for enabled, false for disable
247    * @param bd_addr remote device address
248    */
249   virtual bt_status_t SendBsir(bool value, RawAddress* bd_addr) = 0;
250 
251   /**
252    * Set the current active headset device for SCO audio
253    *
254    * @param active_device_addr remote device address
255    */
256   virtual bt_status_t SetActiveDevice(RawAddress* active_device_addr) = 0;
257 };
258 
259 }  // namespace headset
260 }  // namespace bluetooth
261