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 focre_cvsd whether force to use fallback CVSD codec 67 * @return BT_STATUS_SUCCESS on success 68 */ 69 virtual bt_status_t ConnectAudio(RawAddress* bd_addr, bool force_cvsd) = 0; 70 71 /** 72 * Close the audio connection 73 * 74 * @param bd_addr remote device address 75 * @return BT_STATUS_SUCCESS on success 76 */ 77 virtual bt_status_t DisconnectAudio(RawAddress* bd_addr) = 0; 78 79 /** 80 * Checks whether the device support echo cancellation and/or noise reduction 81 * via the AT+BRSF bitmask 82 * 83 * @param bd_addr remote device address 84 * @return BT_STATUS_SUCCESS on success 85 */ 86 virtual bt_status_t isNoiseReductionSupported(RawAddress* bd_addr) = 0; 87 88 /** 89 * Checks whether the device supports voice recognition via the AT+BRSF 90 * bitmask 91 * 92 * @param bd_addr remote device address 93 * @return BT_STATUS_SUCCESS on success 94 */ 95 virtual bt_status_t isVoiceRecognitionSupported(RawAddress* bd_addr) = 0; 96 97 /** start voice recognition */ 98 /** 99 * Start voice recognition 100 * @param bd_addr remote device address 101 * @return BT_STATUS_SUCCESS on success 102 */ 103 virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr) = 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, 122 RawAddress* bd_addr) = 0; 123 124 /** 125 * Combined device status change notification 126 * 127 * @param ntk_state Network state, available or not available 128 * @param svc_type Service type, roaming or home 129 * @param signal Signal strength, 0 to 5, p86, HFP 1.7.1 spec 130 * @param batt_chg Battery level of the phone, 0 to 5, p87, HFP 1.7.1 spec 131 * @param bd_addr remote device address 132 * @return BT_STATUS_SUCCESS on success 133 */ 134 virtual bt_status_t DeviceStatusNotification(bthf_network_state_t ntk_state, 135 bthf_service_type_t svc_type, 136 int signal, int batt_chg, 137 RawAddress* bd_addr) = 0; 138 139 /** 140 * Response for COPS (Query Operator Selection) command 141 * 142 * @param cops Operator Name, max length 16 char, p32 HFP 1.7.1 spec 143 * @param bd_addr remote device address 144 * @return BT_STATUS_SUCCESS on success 145 */ 146 virtual bt_status_t CopsResponse(const char* cops, RawAddress* bd_addr) = 0; 147 148 /** 149 * Response for CIND (Stanford Indicator Update) command 150 * 151 * @param svc service availability, available or not available 152 * @param num_active number of active calls 153 * @param num_held number of held calls 154 * @param call_setup_state call setup state 155 * @param signal signal strength, 0 to 5, p86 HFP 1.7.1 spec 156 * @param roam roaming state, 1 for roaming, 0 for home, p86 HFP 1.7.1 spec 157 * @param batt_chg AG battery charge, 0 to 5, p87 HFP 1.7.1 spec 158 * @param bd_addr remote device address 159 * @return BT_STATUS_SUCCESS on success 160 */ 161 virtual bt_status_t CindResponse(int svc, int num_active, int num_held, 162 bthf_call_state_t call_setup_state, 163 int signal, int roam, int batt_chg, 164 RawAddress* bd_addr) = 0; 165 166 /** 167 * Pre-formatted AT response, typically in response to unknown AT cmd 168 * 169 * @param rsp formatted AT response 170 * @param bd_addr remote device address 171 * @return BT_STATUS_SUCCESS on success 172 */ 173 virtual bt_status_t FormattedAtResponse(const char* rsp, 174 RawAddress* bd_addr) = 0; 175 176 /** 177 * ok/error response to AT commands 178 * 179 * @param response_code OK or ERROR 180 * @param error_code actual error code depend on use case 181 * @param bd_addr remote device address 182 * @return BT_STATUS_SUCCESS on success 183 */ 184 virtual bt_status_t AtResponse(bthf_at_response_t response_code, 185 int error_code, RawAddress* bd_addr) = 0; 186 187 /** 188 * Response for CLCC (Current List of Calls) command. 189 * Can be iteratively called for each call index 190 * Call index of 0 will be treated as NULL termination (Completes response) 191 * 192 * @param index index of the call 193 * @param dir direction of the call 194 * @param state state of the call 195 * @param mode mode of the call 196 * @param mpty whether the call is multi party 197 * @param number phone number of the call 198 * @param type type of the call 199 * @param bd_addr remote device address 200 * @return BT_STATUS_SUCCESS on success 201 */ 202 virtual bt_status_t ClccResponse( 203 int index, bthf_call_direction_t dir, bthf_call_state_t state, 204 bthf_call_mode_t mode, bthf_call_mpty_type_t mpty, const char* number, 205 bthf_call_addrtype_t type, RawAddress* bd_addr) = 0; 206 207 /** 208 * Notify of a call state change 209 * Each update notifies 210 * 1. Number of active/held/ringing calls 211 * 2. call_state: This denotes the state change that triggered this msg 212 * This will take one of the values from BtHfCallState 213 * 3. number & type: valid only for incoming & waiting call 214 * 215 * @param num_active number of active calls 216 * @param num_held number of held calls 217 * @param call_setup_state current call setup state 218 * @param number phone number of the call 219 * @param type type of the call 220 * @param name caller display name 221 * @param bd_addr remote device address 222 * @return BT_STATUS_SUCCESS on success 223 */ 224 virtual bt_status_t PhoneStateChange(int num_active, int num_held, 225 bthf_call_state_t call_setup_state, 226 const char* number, 227 bthf_call_addrtype_t type, 228 const char* name, 229 RawAddress* bd_addr) = 0; 230 231 /** 232 * Closes the interface. 233 */ 234 virtual void Cleanup() = 0; 235 236 /** 237 * Enable/Disable SCO-offloading 238 * 239 * @param value true to enable, false to disable 240 * @return BT_STATUS_SUCCESS on success 241 */ 242 virtual bt_status_t SetScoOffloadEnabled(bool value) = 0; 243 244 /** 245 * Whether we are allowed to initiate SCO 246 * 247 * @param value true to allow, false to disallow 248 * @return BT_STATUS_SUCCESS on success 249 */ 250 virtual bt_status_t SetScoAllowed(bool value) = 0; 251 252 /** 253 * Send +BSIR response code to enable/disable in-band ringtone in an active 254 * HFP service level connection 255 * 256 * @param value true for enabled, false for disable 257 * @param bd_addr remote device address 258 */ 259 virtual bt_status_t SendBsir(bool value, RawAddress* bd_addr) = 0; 260 261 /** 262 * Set the current active headset device for SCO audio 263 * 264 * @param active_device_addr remote device address 265 */ 266 virtual bt_status_t SetActiveDevice(RawAddress* active_device_addr) = 0; 267 }; 268 269 } // namespace headset 270 } // namespace bluetooth 271