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 * @return BT_STATUS_SUCCESS on success 101 */ 102 virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr) = 0; 103 104 /** 105 * Stop voice recognition 106 * 107 * @param bd_addr remote device address 108 * @return BT_STATUS_SUCCESS on success 109 */ 110 virtual bt_status_t StopVoiceRecognition(RawAddress* bd_addr) = 0; 111 112 /** 113 * Change HFP related volume on remote headset 114 * 115 * @param type Speaker (+VGS) or Mic (+VGM) 116 * @param volume volume level on scale from 0 to 15, p69, HFP 1.7.1 spec 117 * @param bd_addr remote device address 118 * @return BT_STATUS_SUCCESS on success 119 */ 120 virtual bt_status_t VolumeControl(bthf_volume_type_t type, int volume, 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, int signal, 134 int batt_chg, RawAddress* bd_addr) = 0; 135 136 /** 137 * Response for COPS (Query Operator Selection) command 138 * 139 * @param cops Operator Name, max length 16 char, p32 HFP 1.7.1 spec 140 * @param bd_addr remote device address 141 * @return BT_STATUS_SUCCESS on success 142 */ 143 virtual bt_status_t CopsResponse(const char* cops, RawAddress* bd_addr) = 0; 144 145 /** 146 * Response for CIND (Stanford Indicator Update) command 147 * 148 * @param svc service availability, available or not available 149 * @param num_active number of active calls 150 * @param num_held number of held calls 151 * @param call_setup_state call setup state 152 * @param signal signal strength, 0 to 5, p86 HFP 1.7.1 spec 153 * @param roam roaming state, 1 for roaming, 0 for home, p86 HFP 1.7.1 spec 154 * @param batt_chg AG battery charge, 0 to 5, p87 HFP 1.7.1 spec 155 * @param bd_addr remote device address 156 * @return BT_STATUS_SUCCESS on success 157 */ 158 virtual bt_status_t CindResponse(int svc, int num_active, int num_held, 159 bthf_call_state_t call_setup_state, int signal, int roam, 160 int batt_chg, RawAddress* bd_addr) = 0; 161 162 /** 163 * Pre-formatted AT response, typically in response to unknown AT cmd 164 * 165 * @param rsp formatted AT response 166 * @param bd_addr remote device address 167 * @return BT_STATUS_SUCCESS on success 168 */ 169 virtual bt_status_t FormattedAtResponse(const char* rsp, RawAddress* bd_addr) = 0; 170 171 /** 172 * ok/error response to AT commands 173 * 174 * @param response_code OK or ERROR 175 * @param error_code actual error code depend on use case 176 * @param bd_addr remote device address 177 * @return BT_STATUS_SUCCESS on success 178 */ 179 virtual bt_status_t AtResponse(bthf_at_response_t response_code, int error_code, 180 RawAddress* bd_addr) = 0; 181 182 /** 183 * Response for CLCC (Current List of Calls) command. 184 * Can be iteratively called for each call index 185 * Call index of 0 will be treated as NULL termination (Completes response) 186 * 187 * @param index index of the call 188 * @param dir direction of the call 189 * @param state state of the call 190 * @param mode mode of the call 191 * @param mpty whether the call is multi party 192 * @param number phone number of the call 193 * @param type type of the call 194 * @param bd_addr remote device address 195 * @return BT_STATUS_SUCCESS on success 196 */ 197 virtual bt_status_t ClccResponse(int index, bthf_call_direction_t dir, bthf_call_state_t state, 198 bthf_call_mode_t mode, bthf_call_mpty_type_t mpty, 199 const char* number, bthf_call_addrtype_t type, 200 RawAddress* bd_addr) = 0; 201 202 /** 203 * Notify of a call state change 204 * Each update notifies 205 * 1. Number of active/held/ringing calls 206 * 2. call_state: This denotes the state change that triggered this msg 207 * This will take one of the values from BtHfCallState 208 * 3. number & type: valid only for incoming & waiting call 209 * 210 * @param num_active number of active calls 211 * @param num_held number of held calls 212 * @param call_setup_state current call setup state 213 * @param number phone number of the call 214 * @param type type of the call 215 * @param name caller display name 216 * @param bd_addr remote device address 217 * @return BT_STATUS_SUCCESS on success 218 */ 219 virtual bt_status_t PhoneStateChange(int num_active, int num_held, 220 bthf_call_state_t call_setup_state, const char* number, 221 bthf_call_addrtype_t type, const char* name, 222 RawAddress* bd_addr) = 0; 223 224 /** 225 * Enable SWB 226 * 227 * @param swbCodec SWB Codec 228 * @param enable true to enable, false to disable 229 * @param bd_addr remote device address 230 * @return BT_STATUS_SUCCESS on success 231 */ 232 virtual bt_status_t EnableSwb(bthf_swb_codec_t swbCodec, bool enable, RawAddress* bd_addr) = 0; 233 234 /** 235 * Closes the interface. 236 */ 237 virtual void Cleanup() = 0; 238 239 /** 240 * Enable/Disable SCO-offloading 241 * 242 * @param value true to enable, false to disable 243 * @return BT_STATUS_SUCCESS on success 244 */ 245 virtual bt_status_t SetScoOffloadEnabled(bool value) = 0; 246 247 /** 248 * Whether we are allowed to initiate SCO 249 * 250 * @param value true to allow, false to disallow 251 * @return BT_STATUS_SUCCESS on success 252 */ 253 virtual bt_status_t SetScoAllowed(bool value) = 0; 254 255 /** 256 * Send +BSIR response code to enable/disable in-band ringtone in an active 257 * HFP service level connection 258 * 259 * @param value true for enabled, false for disable 260 * @param bd_addr remote device address 261 */ 262 virtual bt_status_t SendBsir(bool value, RawAddress* bd_addr) = 0; 263 264 /** 265 * Set the current active headset device for SCO audio 266 * 267 * @param active_device_addr remote device address 268 */ 269 virtual bt_status_t SetActiveDevice(RawAddress* active_device_addr) = 0; 270 271 /** 272 * Trigger a debug dump of the Headset Profile 273 */ 274 virtual bt_status_t DebugDump() = 0; 275 }; 276 277 } // namespace headset 278 } // namespace bluetooth 279