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_headset_callbacks.h" 20 #include "bt_hf.h" 21 22 namespace bluetooth { 23 namespace headset { 24 25 /** 26 * Programming interface for Headset profiles in the Fluoride stack 27 * Thread-safe 28 */ 29 class Interface { 30 public: 31 virtual ~Interface() = default; 32 /** 33 * Register the BtHf callbacks 34 * 35 * @param callbacks callbacks for the user of the native stack 36 * @param max_hf_clients maximum number of headset clients 37 * @param inband_ringing_enabled whether inband ringtone is enabled 38 * @return BT_STATUS_SUCCESS on success 39 */ 40 virtual bt_status_t Init(Callbacks* callbacks, int max_hf_clients, 41 bool inband_ringing_enabled) = 0; 42 43 /** 44 * Connect to headset 45 * 46 * @param bd_addr remote device address 47 * @return BT_STATUS_SUCCESS on success 48 */ 49 virtual bt_status_t Connect(RawAddress* bd_addr) = 0; 50 51 /** 52 * Disconnect from headset 53 * 54 * @param bd_addr remote device address 55 * @return BT_STATUS_SUCCESS on success 56 */ 57 virtual bt_status_t Disconnect(RawAddress* bd_addr) = 0; 58 59 /** 60 * Create an audio connection 61 * 62 * @param bd_addr remote device address 63 * @return BT_STATUS_SUCCESS on success 64 */ 65 virtual bt_status_t ConnectAudio(RawAddress* bd_addr) = 0; 66 67 /** 68 * Close the audio connection 69 * 70 * @param bd_addr remote device address 71 * @return BT_STATUS_SUCCESS on success 72 */ 73 virtual bt_status_t DisconnectAudio(RawAddress* bd_addr) = 0; 74 75 /** 76 * Checks whether the device support echo cancellation and/or noise reduction 77 * via the AT+BRSF bitmask 78 * 79 * @param bd_addr remote device address 80 * @return BT_STATUS_SUCCESS on success 81 */ 82 virtual bt_status_t isNoiseReductionSupported(RawAddress* bd_addr) = 0; 83 84 /** 85 * Checks whether the device supports voice recognition via the AT+BRSF 86 * bitmask 87 * 88 * @param bd_addr remote device address 89 * @return BT_STATUS_SUCCESS on success 90 */ 91 virtual bt_status_t isVoiceRecognitionSupported(RawAddress* bd_addr) = 0; 92 93 /** start voice recognition */ 94 /** 95 * Start voice recognition 96 * @param bd_addr remote device address 97 * @return BT_STATUS_SUCCESS on success 98 */ 99 virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr) = 0; 100 101 /** 102 * Stop voice recognition 103 * 104 * @param bd_addr remote device address 105 * @return BT_STATUS_SUCCESS on success 106 */ 107 virtual bt_status_t StopVoiceRecognition(RawAddress* bd_addr) = 0; 108 109 /** 110 * Change HFP related volume on remote headset 111 * 112 * @param type Speaker (+VGS) or Mic (+VGM) 113 * @param volume volume level on scale from 0 to 15, p69, HFP 1.7.1 spec 114 * @param bd_addr remote device address 115 * @return BT_STATUS_SUCCESS on success 116 */ 117 virtual bt_status_t VolumeControl(bthf_volume_type_t type, int volume, 118 RawAddress* bd_addr) = 0; 119 120 /** 121 * Combined device status change notification 122 * 123 * @param ntk_state Network state, available or not available 124 * @param svc_type Service type, roaming or home 125 * @param signal Signal strength, 0 to 5, p86, HFP 1.7.1 spec 126 * @param batt_chg Battery level of the phone, 0 to 5, p87, HFP 1.7.1 spec 127 * @param bd_addr remote device address 128 * @return BT_STATUS_SUCCESS on success 129 */ 130 virtual bt_status_t DeviceStatusNotification(bthf_network_state_t ntk_state, 131 bthf_service_type_t svc_type, 132 int signal, int batt_chg, 133 RawAddress* bd_addr) = 0; 134 135 /** 136 * Response for COPS (Query Operator Selection) command 137 * 138 * @param cops Operator Name, max length 16 char, p32 HFP 1.7.1 spec 139 * @param bd_addr remote device address 140 * @return BT_STATUS_SUCCESS on success 141 */ 142 virtual bt_status_t CopsResponse(const char* cops, RawAddress* bd_addr) = 0; 143 144 /** 145 * Response for CIND (Stanford Indicator Update) command 146 * 147 * @param svc service availability, available or not available 148 * @param num_active number of active calls 149 * @param num_held number of held calls 150 * @param call_setup_state call setup state 151 * @param signal signal strength, 0 to 5, p86 HFP 1.7.1 spec 152 * @param roam roaming state, 1 for roaming, 0 for home, p86 HFP 1.7.1 spec 153 * @param batt_chg AG battery charge, 0 to 5, p87 HFP 1.7.1 spec 154 * @param bd_addr remote device address 155 * @return BT_STATUS_SUCCESS on success 156 */ 157 virtual bt_status_t CindResponse(int svc, int num_active, int num_held, 158 bthf_call_state_t call_setup_state, 159 int signal, int roam, int batt_chg, 160 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, 170 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, 181 int error_code, 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( 199 int index, bthf_call_direction_t dir, bthf_call_state_t state, 200 bthf_call_mode_t mode, bthf_call_mpty_type_t mpty, const char* number, 201 bthf_call_addrtype_t type, 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, 222 const char* number, 223 bthf_call_addrtype_t type, 224 const char* name, 225 RawAddress* bd_addr) = 0; 226 227 /** 228 * Closes the interface. 229 */ 230 virtual void Cleanup() = 0; 231 232 /** 233 * Whether we are allowed to initiate SCO 234 * 235 * @param value true to allow, false to disallow 236 * @return BT_STATUS_SUCCESS on success 237 */ 238 virtual bt_status_t SetScoAllowed(bool value) = 0; 239 240 /** 241 * Send +BSIR response code to enable/disable in-band ringtone in an active 242 * HFP service level connection 243 * 244 * @param value true for enabled, false for disable 245 * @param bd_addr remote device address 246 */ 247 virtual bt_status_t SendBsir(bool value, RawAddress* bd_addr) = 0; 248 249 /** 250 * Set the current active headset device for SCO audio 251 * 252 * @param active_device_addr remote device address 253 */ 254 virtual bt_status_t SetActiveDevice(RawAddress* active_device_addr) = 0; 255 }; 256 257 } // namespace headset 258 } // namespace bluetooth 259