1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /** 39 * HFP Hands-Free (HF) unit and Audio Gateway Commons 40 * 41 */ 42 43 #ifndef BTSTACK_HFP_H 44 #define BTSTACK_HFP_H 45 46 #include "hci.h" 47 #include "classic/sdp_client_rfcomm.h" 48 49 #if defined __cplusplus 50 extern "C" { 51 #endif 52 53 54 /* HF Supported Features: 55 0: EC and/or NR function 56 1: Three-way calling 57 2: CLI presentation capability 58 3: Voice recognition activation 59 4: Remote volume control 60 5: Enhanced call status 61 6: Enhanced call control 62 7: Codec negotiation 63 8: HF Indicators 64 9: eSCO S4 (and T2) Settings Supported 65 10-31: Reserved for future definition 66 */ 67 #define HFP_HFSF_EC_NR_FUNCTION 0 68 #define HFP_HFSF_THREE_WAY_CALLING 1 69 #define HFP_HFSF_CLI_PRESENTATION_CAPABILITY 2 70 #define HFP_HFSF_VOICE_RECOGNITION_FUNCTION 3 71 #define HFP_HFSF_REMOTE_VOLUME_CONTROL 4 72 #define HFP_HFSF_ENHANCED_CALL_STATUS 5 73 #define HFP_HFSF_ENHANCED_CALL_CONTROL 6 74 #define HFP_HFSF_CODEC_NEGOTIATION 7 75 #define HFP_HFSF_HF_INDICATORS 8 76 #define HFP_HFSF_ESCO_S4 9 77 #define HFP_HFSF_ENHANCED_VOICE_RECOGNITION_STATUS 10 78 #define HFP_HFSF_VOICE_RECOGNITION_TEXT 11 79 80 /* AG Supported Features: 81 0: Three-way calling 82 1: EC and/or NR function 83 2: Voice recognition function 84 3: In-band ring tone capability 85 4: Attach a number to a voice tag 86 5: Ability to reject a call 87 6: Enhanced call status 88 7: Enhanced call control 89 8: Extended Error Result Codes 90 9: Codec negotiation 91 10: HF Indicators 92 11: eSCO S4 (and T2) Settings Supported 93 12-31: Reserved for future definition 94 */ 95 #define HFP_AGSF_THREE_WAY_CALLING 0 96 #define HFP_AGSF_EC_NR_FUNCTION 1 97 #define HFP_AGSF_VOICE_RECOGNITION_FUNCTION 2 98 #define HFP_AGSF_IN_BAND_RING_TONE 3 99 #define HFP_AGSF_ATTACH_A_NUMBER_TO_A_VOICE_TAG 4 100 #define HFP_AGSF_ABILITY_TO_REJECT_A_CALL 5 101 #define HFP_AGSF_ENHANCED_CALL_STATUS 6 102 #define HFP_AGSF_ENHANCED_CALL_CONTROL 7 103 #define HFP_AGSF_EXTENDED_ERROR_RESULT_CODES 8 104 #define HFP_AGSF_CODEC_NEGOTIATION 9 105 #define HFP_AGSF_HF_INDICATORS 10 106 #define HFP_AGSF_ESCO_S4 11 107 #define HFP_AGSF_ENHANCED_VOICE_RECOGNITION_STATUS 12 108 #define HFP_AGSF_VOICE_RECOGNITION_TEXT 13 109 110 #define HFP_DEFAULT_HF_SUPPORTED_FEATURES 0x0000 111 #define HFP_DEFAULT_AG_SUPPORTED_FEATURES 0x0009 112 113 #define HFP_MAX_NUM_INDICATORS 10 114 #define HFP_MAX_NUM_CALL_SERVICES 20 115 #define HFP_CALL_SERVICE_SIZE 3 116 #define HFP_MAX_NUM_CODECS 10 117 118 #define HFP_MAX_INDICATOR_DESC_SIZE 20 119 #define HFP_MAX_VR_TEXT_SIZE 100 120 #define HFP_MAX_NETWORK_OPERATOR_NAME_SIZE 17 121 122 123 #define HFP_SUPPORTED_FEATURES "+BRSF" 124 #define HFP_AVAILABLE_CODECS "+BAC" 125 #define HFP_INDICATOR "+CIND" 126 #define HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS "+CMER" 127 #define HFP_ENABLE_CLIP "+CLIP" 128 #define HFP_ENABLE_CALL_WAITING_NOTIFICATION "+CCWA" 129 #define HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS "+BIA" // +BIA:<enabled>,,<enabled>,,,<enabled> 130 #define HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES "+CHLD" 131 #define HFP_GENERIC_STATUS_INDICATOR "+BIND" 132 #define HFP_TRANSFER_AG_INDICATOR_STATUS "+CIEV" // +CIEV: <index>,<value> 133 #define HFP_TRANSFER_HF_INDICATOR_STATUS "+BIEV" // +BIEC: <index>,<value> 134 #define HFP_QUERY_OPERATOR_SELECTION "+COPS" // +COPS: <mode>,0,<opearator> 135 #define HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR "+CMEE" 136 #define HFP_EXTENDED_AUDIO_GATEWAY_ERROR "+CME ERROR" 137 #define HFP_TRIGGER_CODEC_CONNECTION_SETUP "+BCC" 138 #define HFP_CONFIRM_COMMON_CODEC "+BCS" 139 #define HFP_ANSWER_CALL "ATA" 140 #define HFP_HANG_UP_CALL "+CHUP" 141 #define HFP_CHANGE_IN_BAND_RING_TONE_SETTING "+BSIR" 142 #define HFP_CALL_PHONE_NUMBER "ATD" 143 #define HFP_REDIAL_LAST_NUMBER "+BLDN" 144 #define HFP_TURN_OFF_EC_AND_NR "+NREC" // EC (Echo CAnceling), NR (Noise Reduction) 145 #define HFP_ACTIVATE_VOICE_RECOGNITION "+BVRA" // Voice Recognition 146 #define HFP_SET_MICROPHONE_GAIN "+VGM" 147 #define HFP_SET_SPEAKER_GAIN "+VGS" 148 #define HFP_PHONE_NUMBER_FOR_VOICE_TAG "+BINP" 149 #define HFP_TRANSMIT_DTMF_CODES "+VTS" 150 #define HFP_SUBSCRIBER_NUMBER_INFORMATION "+CNUM" 151 #define HFP_LIST_CURRENT_CALLS "+CLCC" 152 #define HFP_RESPONSE_AND_HOLD "+BTRH" 153 154 #define HFP_OK "OK" 155 #define HFP_ERROR "ERROR" 156 #define HFP_RING "RING" 157 158 // Codecs 159 #define HFP_CODEC_CVSD 0x01 160 #define HFP_CODEC_MSBC 0x02 161 162 typedef enum { 163 HFP_ROLE_INVALID = 0, 164 HFP_ROLE_AG, 165 HFP_ROLE_HF, 166 } hfp_role_t; 167 168 typedef enum { 169 HFP_CMD_NONE = 0, 170 HFP_CMD_ERROR, 171 HFP_CMD_UNKNOWN, 172 HFP_CMD_OK, 173 HFP_CMD_RING, 174 HFP_CMD_SUPPORTED_FEATURES, // 5 175 HFP_CMD_AVAILABLE_CODECS, 176 HFP_CMD_RETRIEVE_AG_INDICATORS_GENERIC, 177 HFP_CMD_RETRIEVE_AG_INDICATORS, 178 HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS, 179 HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE, // 10 180 HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, 181 HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, 182 HFP_CMD_ENABLE_CLIP, 183 HFP_CMD_AG_SENT_CLIP_INFORMATION, 184 HFP_CMD_ENABLE_CALL_WAITING_NOTIFICATION, // 15 185 HFP_CMD_AG_SENT_CALL_WAITING_NOTIFICATION_UPDATE, 186 HFP_CMD_LIST_GENERIC_STATUS_INDICATORS, 187 HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS, 188 HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE, 189 HFP_CMD_SET_GENERIC_STATUS_INDICATOR_STATUS, // 20 190 HFP_CMD_TRANSFER_AG_INDICATOR_STATUS, 191 HFP_CMD_QUERY_OPERATOR_SELECTION_NAME, 192 HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT, 193 HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, 194 HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR, // 25 195 HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP, 196 HFP_CMD_AG_SEND_COMMON_CODEC, 197 HFP_CMD_AG_SUGGESTED_CODEC, 198 HFP_CMD_HF_CONFIRMED_CODEC, 199 HFP_CMD_CALL_ANSWERED, // 30 200 HFP_CMD_CALL_HOLD, 201 HFP_CMD_HANG_UP_CALL, 202 HFP_CMD_CHANGE_IN_BAND_RING_TONE_SETTING, 203 HFP_CMD_CALL_PHONE_NUMBER, 204 HFP_CMD_REDIAL_LAST_NUMBER, // 35 205 HFP_CMD_TURN_OFF_EC_AND_NR, 206 HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION, // 37 207 HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION, 208 HFP_CMD_HF_REQUEST_PHONE_NUMBER, 209 HFP_CMD_AG_SENT_PHONE_NUMBER, 210 HFP_CMD_TRANSMIT_DTMF_CODES, 211 HFP_CMD_SET_MICROPHONE_GAIN, 212 HFP_CMD_SET_SPEAKER_GAIN, 213 HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION, 214 HFP_CMD_LIST_CURRENT_CALLS, 215 HFP_CMD_RESPONSE_AND_HOLD_QUERY, 216 HFP_CMD_RESPONSE_AND_HOLD_COMMAND, 217 HFP_CMD_RESPONSE_AND_HOLD_STATUS, 218 HFP_CMD_HF_INDICATOR_STATUS 219 } hfp_command_t; 220 221 222 typedef enum { 223 HFP_CME_ERROR_AG_FAILURE = 0, 224 HFP_CME_ERROR_NO_CONNECTION_TO_PHONE, 225 HFP_CME_ERROR_2, 226 HFP_CME_ERROR_OPERATION_NOT_ALLOWED, 227 HFP_CME_ERROR_OPERATION_NOT_SUPPORTED, 228 HFP_CME_ERROR_PH_SIM_PIN_REQUIRED, 229 HFP_CME_ERROR_6, 230 HFP_CME_ERROR_7, 231 HFP_CME_ERROR_8, 232 HFP_CME_ERROR_9, 233 HFP_CME_ERROR_SIM_NOT_INSERTED, 234 HFP_CME_ERROR_SIM_PIN_REQUIRED, 235 HFP_CME_ERROR_SIM_PUK_REQUIRED, 236 HFP_CME_ERROR_SIM_FAILURE, 237 HFP_CME_ERROR_SIM_BUSY, 238 HFP_CME_ERROR_15, 239 HFP_CME_ERROR_INCORRECT_PASSWORD, 240 HFP_CME_ERROR_SIM_PIN2_REQUIRED, 241 HFP_CME_ERROR_SIM_PUK2_REQUIRED, 242 HFP_CME_ERROR_19, 243 HFP_CME_ERROR_MEMORY_FULL, 244 HFP_CME_ERROR_INVALID_INDEX, 245 HFP_CME_ERROR_22, 246 HFP_CME_ERROR_MEMORY_FAILURE, 247 HFP_CME_ERROR_TEXT_STRING_TOO_LONG, 248 HFP_CME_ERROR_INVALID_CHARACTERS_IN_TEXT_STRING, 249 HFP_CME_ERROR_DIAL_STRING_TOO_LONG, 250 HFP_CME_ERROR_INVALID_CHARACTERS_IN_DIAL_STRING, 251 HFP_CME_ERROR_28, 252 HFP_CME_ERROR_29, 253 HFP_CME_ERROR_NO_NETWORK_SERVICE, 254 HFP_CME_ERROR_NETWORK_TIMEOUT, 255 HFP_CME_ERROR_NETWORK_NOT_ALLOWED_EMERGENCY_CALLS_ONLY 256 } hfp_cme_error_t; 257 258 typedef enum { 259 HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS = 0, 260 HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT 261 } hfp_call_status_t; 262 263 typedef enum { 264 HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS = 0, 265 HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS, 266 HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE, 267 HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE 268 } hfp_callsetup_status_t; 269 270 typedef enum { 271 HFP_CALLHELD_STATUS_NO_CALLS_HELD = 0, 272 HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED, 273 HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS 274 } hfp_callheld_status_t; 275 276 277 typedef enum { 278 HFP_AG_INCOMING_CALL, 279 HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG, 280 HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF, 281 HFP_AG_AUDIO_CONNECTION_ESTABLISHED, 282 HFP_AG_OUTGOING_CALL_INITIATED_BY_AG, 283 HFP_AG_OUTGOING_CALL_INITIATED_BY_HF, 284 HFP_AG_OUTGOING_CALL_REJECTED, 285 HFP_AG_OUTGOING_CALL_ACCEPTED, 286 HFP_AG_OUTGOING_CALL_RINGING, 287 HFP_AG_OUTGOING_CALL_ESTABLISHED, 288 HFP_AG_OUTGOING_REDIAL_INITIATED, 289 HFP_AG_HELD_CALL_JOINED_BY_AG, 290 HFP_AG_TERMINATE_CALL_BY_AG, 291 HFP_AG_TERMINATE_CALL_BY_HF, 292 HFP_AG_CALL_DROPPED, 293 HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG, 294 HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_AG, 295 HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG, 296 HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF, 297 HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_HF, 298 HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_HF, 299 HFP_AG_CALL_HOLD_USER_BUSY, 300 HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL, 301 HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL, 302 HFP_AG_CALL_HOLD_ADD_HELD_CALL, 303 HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS, 304 HFP_AG_SET_CLIP 305 } hfp_ag_call_event_t; 306 307 308 typedef enum { 309 HFP_PARSER_CMD_HEADER = 0, 310 HFP_PARSER_CMD_SEQUENCE, 311 HFP_PARSER_SECOND_ITEM, 312 HFP_PARSER_THIRD_ITEM 313 } hfp_parser_state_t; 314 315 typedef enum { 316 HFP_VOICE_RECOGNITION_STATE_AG_READY = 0, 317 HFP_VOICE_RECOGNITION_STATE_AG_READY_TO_ACCEPT_AUDIO_INPUT = 1, 318 HFP_VOICE_RECOGNITION_STATE_AG_IS_STARTING_SOUND = 2, 319 HFP_VOICE_RECOGNITION_STATE_AG_IS_PROCESSING_AUDIO_INPUT = 4 320 } hfp_voice_recognition_state_t; 321 322 typedef enum { 323 HFP_TEXT_TYPE_RECOGNISED_FROM_HF_AUDIO = 0, 324 HFP_TEXT_TYPE_MESSAGE_FROM_AG, 325 HFP_TEXT_TYPE_QUESTION_FROM_AG, 326 HFP_TEXT_TYPE_ERROR_FROM_AG 327 } hfp_text_type_t; 328 329 typedef enum { 330 HFP_TEXT_OPERATION_NEW_TEXT = 1, 331 HFP_TEXT_OPERATION_REPLACE, 332 HFP_TEXT_OPERATION_APPEND 333 } hfp_text_operation_t; 334 335 typedef enum { 336 HFP_IDLE = 0, //0 337 HFP_SDP_QUERY_RFCOMM_CHANNEL, 338 HFP_W2_SEND_SDP_QUERY, 339 HFP_W4_SDP_QUERY_COMPLETE, 340 HFP_W4_RFCOMM_CONNECTED, 341 342 HFP_EXCHANGE_SUPPORTED_FEATURES, // 5 343 HFP_W4_EXCHANGE_SUPPORTED_FEATURES, 344 345 HFP_NOTIFY_ON_CODECS, 346 HFP_W4_NOTIFY_ON_CODECS, 347 348 HFP_RETRIEVE_INDICATORS, 349 HFP_W4_RETRIEVE_INDICATORS, // 10 350 351 HFP_RETRIEVE_INDICATORS_STATUS, 352 HFP_W4_RETRIEVE_INDICATORS_STATUS, 353 354 HFP_ENABLE_INDICATORS_STATUS_UPDATE, 355 HFP_W4_ENABLE_INDICATORS_STATUS_UPDATE, 356 357 HFP_RETRIEVE_CAN_HOLD_CALL, // 15 358 HFP_W4_RETRIEVE_CAN_HOLD_CALL, 359 360 HFP_LIST_GENERIC_STATUS_INDICATORS, 361 HFP_W4_LIST_GENERIC_STATUS_INDICATORS, 362 363 HFP_RETRIEVE_GENERIC_STATUS_INDICATORS, 364 HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS, //20 365 366 HFP_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS, 367 HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS, 368 369 HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED, //23 370 371 HFP_W2_CONNECT_SCO, 372 HFP_W4_SCO_CONNECTED, 373 374 HFP_AUDIO_CONNECTION_ESTABLISHED, 375 376 377 HFP_W2_DISCONNECT_SCO, 378 HFP_W4_SCO_DISCONNECTED, 379 HFP_W4_SCO_DISCONNECTED_TO_SHUTDOWN, 380 HFP_W4_WBS_SHUTDOWN, 381 382 HFP_W2_DISCONNECT_RFCOMM, 383 HFP_W4_RFCOMM_DISCONNECTED, 384 HFP_W4_RFCOMM_DISCONNECTED_AND_RESTART, 385 HFP_W4_CONNECTION_ESTABLISHED_TO_SHUTDOWN 386 } hfp_state_t; 387 388 389 typedef enum { 390 // shared between normal voice recognition and enhanced one 391 HFP_VRA_VOICE_RECOGNITION_OFF, 392 393 HFP_VRA_W2_SEND_VOICE_RECOGNITION_OFF, 394 HFP_VRA_W4_VOICE_RECOGNITION_OFF, 395 396 HFP_VRA_W2_SEND_VOICE_RECOGNITION_ACTIVATED, 397 HFP_VRA_W4_VOICE_RECOGNITION_ACTIVATED, 398 HFP_VRA_VOICE_RECOGNITION_ACTIVATED, 399 400 HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO, 401 HFP_VRA_W4_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO, 402 HFP_VRA_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO, 403 404 HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_STATUS, 405 HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_MSG 406 } hfp_voice_recognition_activation_status_t; 407 408 typedef struct { 409 uint16_t text_id; 410 hfp_text_type_t text_type; 411 hfp_text_operation_t text_operation; 412 const char * text; 413 } hfp_voice_recognition_message_t; 414 415 typedef enum { 416 HFP_CODECS_IDLE, 417 HFP_CODECS_RECEIVED_LIST, 418 HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE, 419 HFP_CODECS_W4_AG_COMMON_CODEC, 420 HFP_CODECS_AG_SENT_COMMON_CODEC, 421 HFP_CODECS_AG_RESEND_COMMON_CODEC, 422 HFP_CODECS_HF_CONFIRMED_CODEC, 423 HFP_CODECS_EXCHANGED, 424 HFP_CODECS_ERROR 425 } hfp_codecs_state_t; 426 427 typedef enum { 428 HFP_CALL_IDLE, 429 HFP_CALL_TRIGGER_AUDIO_CONNECTION, 430 HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING, 431 HFP_CALL_RINGING, 432 HFP_CALL_W4_AUDIO_CONNECTION_FOR_ACTIVE, 433 HFP_CALL_ACTIVE, 434 HFP_CALL_W2_SEND_CALL_WAITING, 435 HFP_CALL_W4_CHLD, 436 HFP_CALL_OUTGOING_INITIATED, 437 HFP_CALL_OUTGOING_DIALING, 438 HFP_CALL_OUTGOING_RINGING 439 } hfp_call_state_t; 440 441 typedef enum{ 442 HFP_ENHANCED_CALL_DIR_OUTGOING, 443 HFP_ENHANCED_CALL_DIR_INCOMING 444 } hfp_enhanced_call_dir_t; 445 446 typedef enum{ 447 HFP_ENHANCED_CALL_STATUS_ACTIVE, 448 HFP_ENHANCED_CALL_STATUS_HELD, 449 HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING, 450 HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING, 451 HFP_ENHANCED_CALL_STATUS_INCOMING, 452 HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING, 453 HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD 454 } hfp_enhanced_call_status_t; 455 456 typedef enum{ 457 HFP_ENHANCED_CALL_MODE_VOICE, 458 HFP_ENHANCED_CALL_MODE_DATA, 459 HFP_ENHANCED_CALL_MODE_FAX 460 } hfp_enhanced_call_mode_t; 461 462 typedef enum{ 463 HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL, 464 HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL 465 } hfp_enhanced_call_mpty_t; 466 467 typedef enum { 468 HFP_RESPONSE_AND_HOLD_INCOMING_ON_HOLD = 0, 469 HFP_RESPONSE_AND_HOLD_HELD_INCOMING_ACCEPTED, 470 HFP_RESPONSE_AND_HOLD_HELD_INCOMING_REJECTED 471 } hfp_response_and_hold_state_t; 472 473 typedef enum { 474 HFP_HF_QUERY_OPERATOR_FORMAT_NOT_SET = 0, 475 HFP_HF_QUERY_OPERATOR_SET_FORMAT, 476 HFP_HF_QUERY_OPERATOR_W4_SET_FORMAT_OK, 477 HFP_HF_QUERY_OPERATOR_FORMAT_SET, 478 HFP_HF_QUERY_OPERATOR_SEND_QUERY, 479 HPF_HF_QUERY_OPERATOR_W4_RESULT 480 } hfp_hf_query_operator_state_t; 481 482 typedef enum { 483 HFP_LINK_SETTINGS_D0 = 0, 484 HFP_LINK_SETTINGS_D1, 485 HFP_LINK_SETTINGS_S1, 486 HFP_LINK_SETTINGS_S2, 487 HFP_LINK_SETTINGS_S3, 488 HFP_LINK_SETTINGS_S4, 489 HFP_LINK_SETTINGS_T1, 490 HFP_LINK_SETTINGS_T2, 491 HFP_LINK_SETTINGS_NONE, 492 } hfp_link_settings_t; 493 494 typedef enum{ 495 HFP_NONE_SM, 496 HFP_SLC_SM, 497 HFP_SLC_QUERIES_SM, 498 HFP_CODECS_CONNECTION_SM, 499 HFP_AUDIO_CONNECTION_SM, 500 HFP_CALL_SM 501 } hfp_state_machine_t; 502 503 typedef struct{ 504 uint16_t uuid; 505 uint8_t state; // enabled 506 } hfp_generic_status_indicator_t; 507 508 typedef struct{ 509 uint8_t index; 510 char name[HFP_MAX_INDICATOR_DESC_SIZE]; 511 uint8_t min_range; 512 uint8_t max_range; 513 uint8_t status; 514 uint8_t mandatory; 515 uint8_t enabled; 516 uint8_t status_changed; 517 } hfp_ag_indicator_t; 518 519 typedef struct{ 520 char name[HFP_CALL_SERVICE_SIZE]; 521 } hfp_call_service_t; 522 523 524 typedef struct{ 525 uint8_t mode; 526 uint8_t format; 527 char name[HFP_MAX_NETWORK_OPERATOR_NAME_SIZE]; // enabled 528 } hfp_network_opearator_t; 529 530 531 typedef struct hfp_connection { 532 btstack_linked_item_t item; 533 534 // local role: HF or AG 535 hfp_role_t local_role; 536 537 bd_addr_t remote_addr; 538 hci_con_handle_t acl_handle; 539 hci_con_handle_t sco_handle; 540 uint16_t rfcomm_channel_nr; 541 uint16_t rfcomm_cid; 542 543 hfp_state_machine_t state_machine; 544 hfp_call_state_t call_state; 545 hfp_state_t state; 546 hfp_codecs_state_t codecs_state; 547 548 // needed for reestablishing connection - service uuid of the remote 549 uint16_t service_uuid; 550 551 // used during service level connection establishment 552 hfp_command_t command; 553 hfp_parser_state_t parser_state; 554 int parser_item_index; 555 int parser_indicator_index; 556 uint32_t parser_indicator_value; 557 bool parser_quoted; 558 uint8_t line_buffer[HFP_MAX_VR_TEXT_SIZE]; 559 int line_size; 560 561 uint32_t remote_supported_features; 562 563 uint16_t remote_codecs_nr; 564 uint8_t remote_codecs[HFP_MAX_NUM_CODECS]; 565 566 uint16_t ag_indicators_nr; 567 hfp_ag_indicator_t ag_indicators[HFP_MAX_NUM_INDICATORS]; 568 uint32_t ag_indicators_status_update_bitmap; 569 uint8_t enable_status_update_for_ag_indicators; 570 571 uint16_t remote_call_services_index; 572 hfp_call_service_t remote_call_services[HFP_MAX_NUM_CALL_SERVICES]; 573 574 // TODO: use bitmap. 575 uint16_t generic_status_indicators_nr; 576 uint32_t generic_status_update_bitmap; 577 hfp_generic_status_indicator_t generic_status_indicators[HFP_MAX_NUM_INDICATORS]; 578 579 hfp_network_opearator_t network_operator; 580 581 // Retrieved during service level connection establishment, not used yet 582 uint8_t negotiated_codec; 583 584 // HF -> AG configuration 585 uint8_t clip_enabled; 586 uint8_t call_waiting_notification_enabled; 587 588 // TODO: put these bit flags in a bitmap 589 uint8_t ok_pending; 590 // uint8_t send_ok; 591 uint8_t send_error; 592 593 bool found_equal_sign; 594 uint8_t ignore_value; 595 596 uint8_t change_status_update_for_individual_ag_indicators; 597 uint8_t operator_name_changed; 598 599 uint8_t enable_extended_audio_gateway_error_report; 600 uint8_t extended_audio_gateway_error_value; 601 uint8_t extended_audio_gateway_error; 602 603 // establish codecs connection 604 uint8_t suggested_codec; 605 uint8_t codec_confirmed; 606 uint8_t sco_for_msbc_failed; 607 uint8_t trigger_codec_exchange; 608 609 // establish audio connection 610 hfp_link_settings_t link_setting; 611 uint8_t accept_sco; // 1 = SCO, 2 = eSCO 612 613 uint8_t establish_audio_connection; 614 uint8_t release_audio_connection; 615 uint8_t release_slc_connection; 616 617 btstack_timer_source_t hfp_timeout; 618 619 uint8_t microphone_gain; 620 uint8_t send_microphone_gain; 621 622 uint8_t speaker_gain; 623 uint8_t send_speaker_gain; 624 625 uint8_t send_phone_number_for_voice_tag; 626 uint8_t send_ag_status_indicators; 627 uint8_t send_ag_indicators_segment; 628 uint8_t send_response_and_hold_status; // 0 - don't send. BRTH:0 == 1, .. 629 630 // AG only 631 uint8_t change_in_band_ring_tone_setting; 632 uint8_t ag_ring; 633 uint8_t ag_send_clip; 634 uint8_t ag_echo_and_noise_reduction; 635 // used by AG: HFP parser stores here the activation value issued by HF 636 uint8_t ag_activate_voice_recognition_value; 637 bool ag_audio_connection_opened_before_vra; 638 639 uint8_t ag_notify_incoming_call_waiting; 640 uint8_t send_subscriber_number; 641 uint8_t next_subscriber_number_to_send; 642 uint8_t ag_call_hold_action; 643 uint8_t ag_response_and_hold_action; 644 uint8_t ag_dtmf_code; 645 bool ag_send_no_carrier; 646 647 int send_status_of_current_calls; 648 int next_call_index; 649 650 // HF only 651 hfp_hf_query_operator_state_t hf_query_operator_state; 652 uint8_t hf_answer_incoming_call; 653 uint8_t hf_initiate_outgoing_call; 654 uint8_t hf_initiate_memory_dialing; 655 uint8_t hf_initiate_redial_last_number; 656 bool hf_send_codec_confirm; 657 bool hf_send_supported_codecs; 658 659 int memory_id; 660 661 uint8_t hf_send_clip_enable; 662 uint8_t hf_send_chup; 663 uint8_t hf_send_chld_0; 664 uint8_t hf_send_chld_1; 665 uint8_t hf_send_chld_2; 666 uint8_t hf_send_chld_3; 667 uint8_t hf_send_chld_4; 668 uint8_t hf_send_chld_x; 669 uint8_t hf_send_chld_x_index; 670 char hf_send_dtmf_code; 671 uint8_t hf_send_binp; 672 uint8_t hf_send_clcc; 673 uint8_t hf_send_rrh; 674 char hf_send_rrh_command; 675 uint8_t hf_send_cnum; 676 677 uint8_t hf_activate_call_waiting_notification; 678 uint8_t hf_deactivate_call_waiting_notification; 679 680 uint8_t hf_activate_calling_line_notification; 681 uint8_t hf_deactivate_calling_line_notification; 682 uint8_t hf_activate_echo_canceling_and_noise_reduction; 683 uint8_t hf_deactivate_echo_canceling_and_noise_reduction; 684 685 hfp_voice_recognition_activation_status_t vra_state; 686 hfp_voice_recognition_activation_status_t vra_state_requested; 687 bool deactivate_voice_recognition; 688 bool activate_voice_recognition; 689 bool enhanced_voice_recognition_enabled; 690 691 // ih HF, used by parser, in AG used for commands 692 uint8_t ag_vra_status; 693 hfp_voice_recognition_state_t ag_vra_state; 694 hfp_voice_recognition_message_t ag_msg; 695 uint16_t ag_vra_msg_length; 696 697 uint8_t clcc_idx; 698 uint8_t clcc_dir; 699 uint8_t clcc_status; 700 uint8_t clcc_mode; 701 uint8_t clcc_mpty; 702 703 uint8_t call_index; 704 // also used for CLCC, CCWA, CLIP if set 705 uint8_t bnip_type; // 0 == not set 706 char bnip_number[25]; // 707 708 #ifdef ENABLE_CC256X_ASSISTED_HFP 709 bool cc256x_send_write_codec_config; 710 bool cc256x_send_wbs_associate; 711 bool cc256x_send_wbs_disassociate; 712 #endif 713 #ifdef ENABLE_BCM_PCM_WBS 714 bool bcm_send_enable_wbs; 715 bool bcm_send_disable_wbs; 716 bool bcm_send_write_i2spcm_interface_param; 717 #endif 718 } hfp_connection_t; 719 720 // UTILS_START : TODO move to utils 721 int send_str_over_rfcomm(uint16_t cid, char * command); 722 int join(char * buffer, int buffer_size, uint8_t * values, int values_nr); 723 int join_bitmap(char * buffer, int buffer_size, uint32_t values, int values_nr); 724 int get_bit(uint16_t bitmap, int position); 725 int store_bit(uint32_t bitmap, int position, uint8_t value); 726 // UTILS_END 727 728 void hfp_finalize_connection_context(hfp_connection_t * hfp_connection); 729 void hfp_emit_sco_event(hfp_connection_t * hfp_connection, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr, uint8_t negotiated_codec); 730 731 void hfp_set_ag_callback(btstack_packet_handler_t callback); 732 void hfp_set_ag_rfcomm_packet_handler(btstack_packet_handler_t handler); 733 734 void hfp_set_hf_callback(btstack_packet_handler_t callback); 735 void hfp_set_hf_rfcomm_packet_handler(btstack_packet_handler_t handler); 736 737 void hfp_init(void); 738 void hfp_deinit(void); 739 740 void hfp_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t service_uuid, int rfcomm_channel_nr, const char * name); 741 void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, hfp_role_t local_role); 742 void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, hfp_role_t local_role); 743 void hfp_emit_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, uint8_t value); 744 void hfp_emit_simple_event(hfp_connection_t * hfp_connection, uint8_t event_subtype); 745 void hfp_emit_string_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, const char * value); 746 void hfp_emit_slc_connection_event(hfp_connection_t * hfp_connection, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr); 747 748 /** 749 * @brief Emit HFP_SUBEVENT_VOICE_RECOGNITION_STATUS event 750 * @param hfp_connection 751 * @param status ERROR_CODE_SUCCESS if successful, otherwise ERROR_CODE_COMMAND_DISALLOWED 752 * @param state 0 if deactivated, 1 if activated 753 */ 754 void hfp_emit_voice_recognition_state_event(hfp_connection_t * hfp_connection, uint8_t status); 755 void hfp_emit_enhanced_voice_recognition_hf_ready_for_audio_event(hfp_connection_t * hfp_connection, uint8_t status); 756 void hfp_emit_enhanced_voice_recognition_state_event(hfp_connection_t * hfp_connection, uint8_t status); 757 758 hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid); 759 hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr, hfp_role_t hfp_role); 760 hfp_connection_t * get_hfp_connection_context_for_sco_handle(uint16_t handle, hfp_role_t hfp_role); 761 hfp_connection_t * get_hfp_connection_context_for_acl_handle(uint16_t handle, hfp_role_t hfp_role); 762 763 btstack_linked_list_t * hfp_get_connections(void); 764 void hfp_parse(hfp_connection_t * connection, uint8_t byte, int isHandsFree); 765 766 /** 767 * @brief Establish RFCOMM connection, and perform service level connection agreement: 768 * @param bd_addr 769 * @param service_uuid 770 * @param local_role 771 * @return status ERROR_CODE_SUCCESS if successful, otherwise: 772 * - ERROR_CODE_COMMAND_DISALLOWED if connection already exists, or 773 * - BTSTACK_MEMORY_ALLOC_FAILED 774 */ 775 uint8_t hfp_establish_service_level_connection(bd_addr_t bd_addr, uint16_t service_uuid, hfp_role_t local_role); 776 777 /** 778 * @brief Prepare connection for audio and SLC connections release 779 * @param hfp_connection 780 */ 781 void hfp_trigger_release_service_level_connection(hfp_connection_t * hfp_connection); 782 783 /** 784 * @brief Prepare connection for audio connection release 785 * @param hfp_connection 786 */ 787 uint8_t hfp_trigger_release_audio_connection(hfp_connection_t * hfp_connection); 788 789 void hfp_reset_context_flags(hfp_connection_t * hfp_connection); 790 791 void hfp_setup_synchronous_connection(hfp_connection_t * hfp_connection); 792 void hfp_accept_synchronous_connection(hfp_connection_t * hfp_connection, bool incoming_eSCO); 793 int hfp_supports_codec(uint8_t codec, int codecs_nr, uint8_t * codecs); 794 void hfp_hf_drop_mSBC_if_eSCO_not_supported(uint8_t * codecs, uint8_t * codecs_nr); 795 void hfp_init_link_settings(hfp_connection_t * hfp_connection, uint8_t eSCO_S4_supported); 796 hfp_link_settings_t hfp_next_link_setting(hfp_link_settings_t current_setting, bool local_eSCO_supported, bool remote_eSCO_supported, bool eSCO_s4_supported, uint8_t negotiated_codec); 797 798 const char * hfp_hf_feature(int index); 799 const char * hfp_ag_feature(int index); 800 801 void hfp_log_rfcomm_message(const char * tag, uint8_t * packet, uint16_t size); 802 803 const char * hfp_enhanced_call_dir2str(uint16_t index); 804 const char * hfp_enhanced_call_status2str(uint16_t index); 805 const char * hfp_enhanced_call_mode2str(uint16_t index); 806 const char * hfp_enhanced_call_mpty2str(uint16_t index); 807 808 #ifdef ENABLE_CC256X_ASSISTED_HFP 809 void hfp_cc256x_prepare_for_sco(hfp_connection_t * hfp_connection); 810 void hfp_cc256x_write_codec_config(hfp_connection_t * hfp_connection); 811 #endif 812 #ifdef ENABLE_BCM_PCM_WBS 813 void hfp_bcm_prepare_for_sco(hfp_connection_t * hfp_connection); 814 void hfp_bcm_write_i2spcm_interface_param (hfp_connection_t * hfp_connection); 815 #endif 816 817 /** 818 * @brief Set packet types for SCO connections 819 * @param common single packet_types: HFP_SCO_PACKET_TYPES_* 820 */ 821 void hfp_set_sco_packet_types(uint16_t packet_types); 822 823 /** 824 * @brief Get packet types for SCO connections 825 * @returns packet_types 826 */ 827 uint16_t hfp_get_sco_packet_types(void); 828 829 #if defined __cplusplus 830 } 831 #endif 832 833 #endif // BTSTACK_HFP_H 834