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 /** start voice recognition */ 76 /** 77 * Start voice recognition 78 * @param bd_addr remote device address 79 * @return BT_STATUS_SUCCESS on success 80 */ 81 virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr) = 0; 82 83 /** 84 * Stop voice recognition 85 * 86 * @param bd_addr remote device address 87 * @return BT_STATUS_SUCCESS on success 88 */ 89 virtual bt_status_t StopVoiceRecognition(RawAddress* bd_addr) = 0; 90 91 /** 92 * Change HFP related volume on remote headset 93 * 94 * @param type Speaker (+VGS) or Mic (+VGM) 95 * @param volume volume level on scale from 0 to 15, p69, HFP 1.7.1 spec 96 * @param bd_addr remote device address 97 * @return BT_STATUS_SUCCESS on success 98 */ 99 virtual bt_status_t VolumeControl(bthf_volume_type_t type, int volume, 100 RawAddress* bd_addr) = 0; 101 102 /** 103 * Combined device status change notification 104 * 105 * @param ntk_state Network state, available or not available 106 * @param svc_type Service type, roaming or home 107 * @param signal Signal strength, 0 to 5, p86, HFP 1.7.1 spec 108 * @param batt_chg Battery level of the phone, 0 to 5, p87, HFP 1.7.1 spec 109 * @param bd_addr remote device address 110 * @return BT_STATUS_SUCCESS on success 111 */ 112 virtual bt_status_t DeviceStatusNotification(bthf_network_state_t ntk_state, 113 bthf_service_type_t svc_type, 114 int signal, int batt_chg, 115 RawAddress* bd_addr) = 0; 116 117 /** 118 * Response for COPS (Query Operator Selection) command 119 * 120 * @param cops Operator Name, max length 16 char, p32 HFP 1.7.1 spec 121 * @param bd_addr remote device address 122 * @return BT_STATUS_SUCCESS on success 123 */ 124 virtual bt_status_t CopsResponse(const char* cops, RawAddress* bd_addr) = 0; 125 126 /** 127 * Response for CIND (Stanford Indicator Update) command 128 * 129 * @param svc service availability, available or not available 130 * @param num_active number of active calls 131 * @param num_held number of held calls 132 * @param call_setup_state call setup state 133 * @param signal signal strength, 0 to 5, p86 HFP 1.7.1 spec 134 * @param roam roaming state, 1 for roaming, 0 for home, p86 HFP 1.7.1 spec 135 * @param batt_chg AG battery charge, 0 to 5, p87 HFP 1.7.1 spec 136 * @param bd_addr remote device address 137 * @return BT_STATUS_SUCCESS on success 138 */ 139 virtual bt_status_t CindResponse(int svc, int num_active, int num_held, 140 bthf_call_state_t call_setup_state, 141 int signal, int roam, int batt_chg, 142 RawAddress* bd_addr) = 0; 143 144 /** 145 * Pre-formatted AT response, typically in response to unknown AT cmd 146 * 147 * @param rsp formatted AT response 148 * @param bd_addr remote device address 149 * @return BT_STATUS_SUCCESS on success 150 */ 151 virtual bt_status_t FormattedAtResponse(const char* rsp, 152 RawAddress* bd_addr) = 0; 153 154 /** 155 * ok/error response to AT commands 156 * 157 * @param response_code OK or ERROR 158 * @param error_code actual error code depend on use case 159 * @param bd_addr remote device address 160 * @return BT_STATUS_SUCCESS on success 161 */ 162 virtual bt_status_t AtResponse(bthf_at_response_t response_code, 163 int error_code, RawAddress* bd_addr) = 0; 164 165 /** 166 * Response for CLCC (Current List of Calls) command. 167 * Can be iteratively called for each call index 168 * Call index of 0 will be treated as NULL termination (Completes response) 169 * 170 * @param index index of the call 171 * @param dir direction of the call 172 * @param state state of the call 173 * @param mode mode of the call 174 * @param mpty whether the call is multi party 175 * @param number phone number of the call 176 * @param type type of the call 177 * @param bd_addr remote device address 178 * @return BT_STATUS_SUCCESS on success 179 */ 180 virtual bt_status_t ClccResponse( 181 int index, bthf_call_direction_t dir, bthf_call_state_t state, 182 bthf_call_mode_t mode, bthf_call_mpty_type_t mpty, const char* number, 183 bthf_call_addrtype_t type, RawAddress* bd_addr) = 0; 184 185 /** 186 * Notify of a call state change 187 * Each update notifies 188 * 1. Number of active/held/ringing calls 189 * 2. call_state: This denotes the state change that triggered this msg 190 * This will take one of the values from BtHfCallState 191 * 3. number & type: valid only for incoming & waiting call 192 * 193 * @param num_active number of active calls 194 * @param num_held number of held calls 195 * @param call_setup_state current call setup state 196 * @param number phone number of the call 197 * @param type type of the call 198 * @param name caller display name 199 * @param bd_addr remote device address 200 * @return BT_STATUS_SUCCESS on success 201 */ 202 virtual bt_status_t PhoneStateChange(int num_active, int num_held, 203 bthf_call_state_t call_setup_state, 204 const char* number, 205 bthf_call_addrtype_t type, 206 const char* name, 207 RawAddress* bd_addr) = 0; 208 209 /** 210 * Closes the interface. 211 */ 212 virtual void Cleanup() = 0; 213 214 /** 215 * Whether we are allowed to initiate SCO 216 * 217 * @param value true to allow, false to disallow 218 * @return BT_STATUS_SUCCESS on success 219 */ 220 virtual bt_status_t SetScoAllowed(bool value) = 0; 221 222 /** 223 * Send +BSIR response code to enable/disable in-band ringtone in an active 224 * HFP service level connection 225 * 226 * @param value true for enabled, false for disable 227 * @param bd_addr remote device address 228 */ 229 virtual bt_status_t SendBsir(bool value, RawAddress* bd_addr) = 0; 230 231 /** 232 * Set the current active headset device for SCO audio 233 * 234 * @param active_device_addr remote device address 235 */ 236 virtual bt_status_t SetActiveDevice(RawAddress* active_device_addr) = 0; 237 }; 238 239 } // namespace headset 240 } // namespace bluetooth 241