xref: /btstack/src/classic/hfp.h (revision 9ff73f4179c5a3ea030a421752f0ce903fd7d883)
13deb3ec6SMatthias Ringwald /*
23deb3ec6SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
33deb3ec6SMatthias Ringwald  *
43deb3ec6SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53deb3ec6SMatthias Ringwald  * modification, are permitted provided that the following conditions
63deb3ec6SMatthias Ringwald  * are met:
73deb3ec6SMatthias Ringwald  *
83deb3ec6SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103deb3ec6SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123deb3ec6SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133deb3ec6SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143deb3ec6SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153deb3ec6SMatthias Ringwald  *    from this software without specific prior written permission.
163deb3ec6SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173deb3ec6SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183deb3ec6SMatthias Ringwald  *    monetary gain.
193deb3ec6SMatthias Ringwald  *
203deb3ec6SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213deb3ec6SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223deb3ec6SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
233deb3ec6SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
243deb3ec6SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253deb3ec6SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263deb3ec6SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273deb3ec6SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283deb3ec6SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293deb3ec6SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303deb3ec6SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313deb3ec6SMatthias Ringwald  * SUCH DAMAGE.
323deb3ec6SMatthias Ringwald  *
333deb3ec6SMatthias Ringwald  * Please inquire about commercial licensing options at
343deb3ec6SMatthias Ringwald  * [email protected]
353deb3ec6SMatthias Ringwald  *
363deb3ec6SMatthias Ringwald  */
373deb3ec6SMatthias Ringwald 
383deb3ec6SMatthias Ringwald // *****************************************************************************
393deb3ec6SMatthias Ringwald //
40a0ffb263SMatthias Ringwald //  HFP Hands-Free (HF) unit and Audio Gateway Commons
413deb3ec6SMatthias Ringwald //
423deb3ec6SMatthias Ringwald // *****************************************************************************
433deb3ec6SMatthias Ringwald 
443deb3ec6SMatthias Ringwald 
4580e33422SMatthias Ringwald #ifndef BTSTACK_HFP_H
4680e33422SMatthias Ringwald #define BTSTACK_HFP_H
473deb3ec6SMatthias Ringwald 
483deb3ec6SMatthias Ringwald #include "hci.h"
49efda0b48SMatthias Ringwald #include "classic/sdp_client_rfcomm.h"
503deb3ec6SMatthias Ringwald 
513deb3ec6SMatthias Ringwald #if defined __cplusplus
523deb3ec6SMatthias Ringwald extern "C" {
533deb3ec6SMatthias Ringwald #endif
543deb3ec6SMatthias Ringwald 
553deb3ec6SMatthias Ringwald 
563deb3ec6SMatthias Ringwald /* HF Supported Features:
573deb3ec6SMatthias Ringwald 0: EC and/or NR function
583deb3ec6SMatthias Ringwald 1: Three-way calling
593deb3ec6SMatthias Ringwald 2: CLI presentation capability
603deb3ec6SMatthias Ringwald 3: Voice recognition activation
613deb3ec6SMatthias Ringwald 4: Remote volume control
623deb3ec6SMatthias Ringwald 5: Enhanced call status
633deb3ec6SMatthias Ringwald 6: Enhanced call control
643deb3ec6SMatthias Ringwald 7: Codec negotiation
653deb3ec6SMatthias Ringwald 8: HF Indicators
663deb3ec6SMatthias Ringwald 9: eSCO S4 (and T2) Settings Supported
673deb3ec6SMatthias Ringwald 10-31: Reserved for future definition
683deb3ec6SMatthias Ringwald */
693deb3ec6SMatthias Ringwald #define HFP_HFSF_EC_NR_FUNCTION              0
70aa4dd815SMatthias Ringwald #define HFP_HFSF_THREE_WAY_CALLING           1
714f84bf36SMatthias Ringwald #define HFP_HFSF_CLI_PRESENTATION_CAPABILITY 2
72aa4dd815SMatthias Ringwald #define HFP_HFSF_VOICE_RECOGNITION_FUNCTION  3
734f84bf36SMatthias Ringwald #define HFP_HFSF_REMOTE_VOLUME_CONTROL       4
744f84bf36SMatthias Ringwald #define HFP_HFSF_ENHANCED_CALL_STATUS        5
754f84bf36SMatthias Ringwald #define HFP_HFSF_ENHANCED_CALL_CONTROL       6
763deb3ec6SMatthias Ringwald #define HFP_HFSF_CODEC_NEGOTIATION           7
773deb3ec6SMatthias Ringwald #define HFP_HFSF_HF_INDICATORS               8
78ce263fc8SMatthias Ringwald #define HFP_HFSF_ESCO_S4                     9
793deb3ec6SMatthias Ringwald 
803deb3ec6SMatthias Ringwald /* AG Supported Features:
813deb3ec6SMatthias Ringwald 0: Three-way calling
823deb3ec6SMatthias Ringwald 1: EC and/or NR function
833deb3ec6SMatthias Ringwald 2: Voice recognition function
843deb3ec6SMatthias Ringwald 3: In-band ring tone capability
853deb3ec6SMatthias Ringwald 4: Attach a number to a voice tag
863deb3ec6SMatthias Ringwald 5: Ability to reject a call
873deb3ec6SMatthias Ringwald 6: Enhanced call status
883deb3ec6SMatthias Ringwald 7: Enhanced call control
893deb3ec6SMatthias Ringwald 8: Extended Error Result Codes
903deb3ec6SMatthias Ringwald 9: Codec negotiation
913deb3ec6SMatthias Ringwald 10: HF Indicators
923deb3ec6SMatthias Ringwald 11: eSCO S4 (and T2) Settings Supported
933deb3ec6SMatthias Ringwald 12-31: Reserved for future definition
943deb3ec6SMatthias Ringwald */
953deb3ec6SMatthias Ringwald #define HFP_AGSF_THREE_WAY_CALLING              0
963deb3ec6SMatthias Ringwald #define HFP_AGSF_EC_NR_FUNCTION                 1
97aa4dd815SMatthias Ringwald #define HFP_AGSF_VOICE_RECOGNITION_FUNCTION     2
98aa4dd815SMatthias Ringwald #define HFP_AGSF_IN_BAND_RING_TONE              3
994f84bf36SMatthias Ringwald #define HFP_AGSF_ATTACH_A_NUMBER_TO_A_VOICE_TAG 4
1004f84bf36SMatthias Ringwald #define HFP_AGSF_ABILITY_TO_REJECT_A_CALL       5
1014f84bf36SMatthias Ringwald #define HFP_AGSF_ENHANCED_CALL_STATUS           6
1024f84bf36SMatthias Ringwald #define HFP_AGSF_ENHANCED_CALL_CONTROL          7
1034f84bf36SMatthias Ringwald #define HFP_AGSF_EXTENDED_ERROR_RESULT_CODES    8
1043deb3ec6SMatthias Ringwald #define HFP_AGSF_CODEC_NEGOTIATION              9
1053deb3ec6SMatthias Ringwald #define HFP_AGSF_HF_INDICATORS                 10
106ce263fc8SMatthias Ringwald #define HFP_AGSF_ESCO_S4                       11
1073deb3ec6SMatthias Ringwald 
1083deb3ec6SMatthias Ringwald #define HFP_DEFAULT_HF_SUPPORTED_FEATURES 0x0000
1093deb3ec6SMatthias Ringwald #define HFP_DEFAULT_AG_SUPPORTED_FEATURES 0x0009
1103deb3ec6SMatthias Ringwald 
11125789943SMilanka Ringwald #define HFP_MAX_NUM_INDICATORS                  10
11225789943SMilanka Ringwald #define HFP_MAX_NUM_CALL_SERVICES               20
11325789943SMilanka Ringwald #define HFP_CALL_SERVICE_SIZE                    3
11425789943SMilanka Ringwald #define HFP_MAX_NUM_CODECS                      10
11525789943SMilanka Ringwald 
1163deb3ec6SMatthias Ringwald #define HFP_MAX_INDICATOR_DESC_SIZE 20
11789425bfcSMilanka Ringwald #define HFP_MAX_NETWORK_OPERATOR_NAME_SIZE 17
11825789943SMilanka Ringwald 
1193deb3ec6SMatthias Ringwald 
1203deb3ec6SMatthias Ringwald #define HFP_SUPPORTED_FEATURES "+BRSF"
1213deb3ec6SMatthias Ringwald #define HFP_AVAILABLE_CODECS "+BAC"
1223deb3ec6SMatthias Ringwald #define HFP_INDICATOR "+CIND"
1233deb3ec6SMatthias Ringwald #define HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS "+CMER"
124aa4dd815SMatthias Ringwald #define HFP_ENABLE_CLIP "+CLIP"
125aa4dd815SMatthias Ringwald #define HFP_ENABLE_CALL_WAITING_NOTIFICATION "+CCWA"
1263deb3ec6SMatthias Ringwald #define HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS "+BIA" // +BIA:<enabled>,,<enabled>,,,<enabled>
1273deb3ec6SMatthias Ringwald #define HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES "+CHLD"
1283deb3ec6SMatthias Ringwald #define HFP_GENERIC_STATUS_INDICATOR "+BIND"
1293deb3ec6SMatthias Ringwald #define HFP_TRANSFER_AG_INDICATOR_STATUS "+CIEV" // +CIEV: <index>,<value>
130ce263fc8SMatthias Ringwald #define HFP_TRANSFER_HF_INDICATOR_STATUS "+BIEV" // +BIEC: <index>,<value>
1313deb3ec6SMatthias Ringwald #define HFP_QUERY_OPERATOR_SELECTION "+COPS"     // +COPS: <mode>,0,<opearator>
1323deb3ec6SMatthias Ringwald #define HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR "+CMEE"
1333deb3ec6SMatthias Ringwald #define HFP_EXTENDED_AUDIO_GATEWAY_ERROR "+CME ERROR"
1343deb3ec6SMatthias Ringwald #define HFP_TRIGGER_CODEC_CONNECTION_SETUP "+BCC"
1353deb3ec6SMatthias Ringwald #define HFP_CONFIRM_COMMON_CODEC "+BCS"
13697d2cadbSMatthias Ringwald #define HFP_ANSWER_CALL "ATA"
137aa4dd815SMatthias Ringwald #define HFP_HANG_UP_CALL "+CHUP"
138aa4dd815SMatthias Ringwald #define HFP_CHANGE_IN_BAND_RING_TONE_SETTING "+BSIR"
139aa4dd815SMatthias Ringwald #define HFP_CALL_PHONE_NUMBER "ATD"
140ce263fc8SMatthias Ringwald #define HFP_REDIAL_LAST_NUMBER "+BLDN"
141aa4dd815SMatthias Ringwald #define HFP_TURN_OFF_EC_AND_NR "+NREC" // EC (Echo CAnceling), NR (Noise Reduction)
142aa4dd815SMatthias Ringwald #define HFP_ACTIVATE_VOICE_RECOGNITION "+BVRA" // EC (Echo CAnceling), NR (Noise Reduction)
143aa4dd815SMatthias Ringwald #define HFP_SET_MICROPHONE_GAIN  "+VGM"
144aa4dd815SMatthias Ringwald #define HFP_SET_SPEAKER_GAIN     "+VGS"
145aa4dd815SMatthias Ringwald #define HFP_PHONE_NUMBER_FOR_VOICE_TAG "+BINP"
146aa4dd815SMatthias Ringwald #define HFP_TRANSMIT_DTMF_CODES  "+VTS"
147ce263fc8SMatthias Ringwald #define HFP_SUBSCRIBER_NUMBER_INFORMATION "+CNUM"
148ce263fc8SMatthias Ringwald #define HFP_LIST_CURRENT_CALLS "+CLCC"
149ce263fc8SMatthias Ringwald #define HFP_RESPONSE_AND_HOLD "+BTRH"
1503deb3ec6SMatthias Ringwald 
1513deb3ec6SMatthias Ringwald #define HFP_OK "OK"
1523deb3ec6SMatthias Ringwald #define HFP_ERROR "ERROR"
153ce263fc8SMatthias Ringwald #define HFP_RING "RING"
1543deb3ec6SMatthias Ringwald 
1553deb3ec6SMatthias Ringwald // Codecs
1563deb3ec6SMatthias Ringwald #define HFP_CODEC_CVSD 0x01
1573deb3ec6SMatthias Ringwald #define HFP_CODEC_MSBC 0x02
1583deb3ec6SMatthias Ringwald 
1593deb3ec6SMatthias Ringwald typedef enum {
160520c92d5SMatthias Ringwald     HFP_ROLE_INVALID = 0,
161520c92d5SMatthias Ringwald     HFP_ROLE_AG,
162323d3000SMatthias Ringwald     HFP_ROLE_HF,
163323d3000SMatthias Ringwald } hfp_role_t;
164323d3000SMatthias Ringwald 
165323d3000SMatthias Ringwald typedef enum {
1663deb3ec6SMatthias Ringwald     HFP_CMD_NONE = 0,
1673deb3ec6SMatthias Ringwald     HFP_CMD_ERROR,
168aa4dd815SMatthias Ringwald     HFP_CMD_UNKNOWN,
1693deb3ec6SMatthias Ringwald     HFP_CMD_OK,
170ce263fc8SMatthias Ringwald     HFP_CMD_RING,
171245852b7SMilanka Ringwald     HFP_CMD_SUPPORTED_FEATURES,                             // 5
1723deb3ec6SMatthias Ringwald     HFP_CMD_AVAILABLE_CODECS,
17384a0c24eSMatthias Ringwald     HFP_CMD_RETRIEVE_AG_INDICATORS_GENERIC,
174aa4dd815SMatthias Ringwald     HFP_CMD_RETRIEVE_AG_INDICATORS,
175aa4dd815SMatthias Ringwald     HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS,
176245852b7SMilanka Ringwald     HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE,                 // 10
1773deb3ec6SMatthias Ringwald     HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE,
1783deb3ec6SMatthias Ringwald     HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES,
179aa4dd815SMatthias Ringwald     HFP_CMD_ENABLE_CLIP,
180a0ffb263SMatthias Ringwald     HFP_CMD_AG_SENT_CLIP_INFORMATION,
181245852b7SMilanka Ringwald     HFP_CMD_ENABLE_CALL_WAITING_NOTIFICATION,               // 15
182a0ffb263SMatthias Ringwald     HFP_CMD_AG_SENT_CALL_WAITING_NOTIFICATION_UPDATE,
183aa4dd815SMatthias Ringwald     HFP_CMD_LIST_GENERIC_STATUS_INDICATORS,
184aa4dd815SMatthias Ringwald     HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS,
185aa4dd815SMatthias Ringwald     HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE,
186245852b7SMilanka Ringwald     HFP_CMD_SET_GENERIC_STATUS_INDICATOR_STATUS,            // 20
1873deb3ec6SMatthias Ringwald     HFP_CMD_TRANSFER_AG_INDICATOR_STATUS,
188aa4dd815SMatthias Ringwald     HFP_CMD_QUERY_OPERATOR_SELECTION_NAME,
189aa4dd815SMatthias Ringwald     HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT,
1903deb3ec6SMatthias Ringwald     HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR,
191245852b7SMilanka Ringwald     HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR,                   // 25
1923deb3ec6SMatthias Ringwald     HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP,
193aa4dd815SMatthias Ringwald     HFP_CMD_AG_SEND_COMMON_CODEC,
1943deb3ec6SMatthias Ringwald     HFP_CMD_AG_SUGGESTED_CODEC,
195aa4dd815SMatthias Ringwald     HFP_CMD_HF_CONFIRMED_CODEC,
196aa4dd815SMatthias Ringwald     HFP_CMD_CALL_ANSWERED,
197aa4dd815SMatthias Ringwald     HFP_CMD_CALL_HOLD,
198aa4dd815SMatthias Ringwald     HFP_CMD_HANG_UP_CALL,
199aa4dd815SMatthias Ringwald     HFP_CMD_CHANGE_IN_BAND_RING_TONE_SETTING,
200aa4dd815SMatthias Ringwald     HFP_CMD_CALL_PHONE_NUMBER,
201aa4dd815SMatthias Ringwald     HFP_CMD_REDIAL_LAST_NUMBER,
202aa4dd815SMatthias Ringwald     HFP_CMD_TURN_OFF_EC_AND_NR,
203aa4dd815SMatthias Ringwald     HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION,
204aa4dd815SMatthias Ringwald     HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION,
205aa4dd815SMatthias Ringwald     HFP_CMD_HF_REQUEST_PHONE_NUMBER,
206ce263fc8SMatthias Ringwald     HFP_CMD_AG_SENT_PHONE_NUMBER,
207aa4dd815SMatthias Ringwald     HFP_CMD_TRANSMIT_DTMF_CODES,
208aa4dd815SMatthias Ringwald     HFP_CMD_SET_MICROPHONE_GAIN,
209ce263fc8SMatthias Ringwald     HFP_CMD_SET_SPEAKER_GAIN,
210ce263fc8SMatthias Ringwald     HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION,
211ce263fc8SMatthias Ringwald     HFP_CMD_LIST_CURRENT_CALLS,
212ce263fc8SMatthias Ringwald     HFP_CMD_RESPONSE_AND_HOLD_QUERY,
213ce263fc8SMatthias Ringwald     HFP_CMD_RESPONSE_AND_HOLD_COMMAND,
214667ec068SMatthias Ringwald     HFP_CMD_RESPONSE_AND_HOLD_STATUS,
215ce263fc8SMatthias Ringwald     HFP_CMD_HF_INDICATOR_STATUS
2163deb3ec6SMatthias Ringwald } hfp_command_t;
2173deb3ec6SMatthias Ringwald 
218aa4dd815SMatthias Ringwald 
2193deb3ec6SMatthias Ringwald typedef enum {
2203deb3ec6SMatthias Ringwald     HFP_CME_ERROR_AG_FAILURE = 0,
2213deb3ec6SMatthias Ringwald     HFP_CME_ERROR_NO_CONNECTION_TO_PHONE,
2223deb3ec6SMatthias Ringwald     HFP_CME_ERROR_2,
2233deb3ec6SMatthias Ringwald     HFP_CME_ERROR_OPERATION_NOT_ALLOWED,
2243deb3ec6SMatthias Ringwald     HFP_CME_ERROR_OPERATION_NOT_SUPPORTED,
2253deb3ec6SMatthias Ringwald     HFP_CME_ERROR_PH_SIM_PIN_REQUIRED,
2263deb3ec6SMatthias Ringwald     HFP_CME_ERROR_6,
2273deb3ec6SMatthias Ringwald     HFP_CME_ERROR_7,
2283deb3ec6SMatthias Ringwald     HFP_CME_ERROR_8,
2293deb3ec6SMatthias Ringwald     HFP_CME_ERROR_9,
2303deb3ec6SMatthias Ringwald     HFP_CME_ERROR_SIM_NOT_INSERTED,
2313deb3ec6SMatthias Ringwald     HFP_CME_ERROR_SIM_PIN_REQUIRED,
2323deb3ec6SMatthias Ringwald     HFP_CME_ERROR_SIM_PUK_REQUIRED,
2333deb3ec6SMatthias Ringwald     HFP_CME_ERROR_SIM_FAILURE,
2343deb3ec6SMatthias Ringwald     HFP_CME_ERROR_SIM_BUSY,
2353deb3ec6SMatthias Ringwald     HFP_CME_ERROR_15,
2363deb3ec6SMatthias Ringwald     HFP_CME_ERROR_INCORRECT_PASSWORD,
2373deb3ec6SMatthias Ringwald     HFP_CME_ERROR_SIM_PIN2_REQUIRED,
2383deb3ec6SMatthias Ringwald     HFP_CME_ERROR_SIM_PUK2_REQUIRED,
2393deb3ec6SMatthias Ringwald     HFP_CME_ERROR_19,
2403deb3ec6SMatthias Ringwald     HFP_CME_ERROR_MEMORY_FULL,
2413deb3ec6SMatthias Ringwald     HFP_CME_ERROR_INVALID_INDEX,
2423deb3ec6SMatthias Ringwald     HFP_CME_ERROR_22,
2433deb3ec6SMatthias Ringwald     HFP_CME_ERROR_MEMORY_FAILURE,
2443deb3ec6SMatthias Ringwald     HFP_CME_ERROR_TEXT_STRING_TOO_LONG,
2453deb3ec6SMatthias Ringwald     HFP_CME_ERROR_INVALID_CHARACTERS_IN_TEXT_STRING,
2463deb3ec6SMatthias Ringwald     HFP_CME_ERROR_DIAL_STRING_TOO_LONG,
2473deb3ec6SMatthias Ringwald     HFP_CME_ERROR_INVALID_CHARACTERS_IN_DIAL_STRING,
2483deb3ec6SMatthias Ringwald     HFP_CME_ERROR_28,
2493deb3ec6SMatthias Ringwald     HFP_CME_ERROR_29,
2503deb3ec6SMatthias Ringwald     HFP_CME_ERROR_NO_NETWORK_SERVICE,
2513deb3ec6SMatthias Ringwald     HFP_CME_ERROR_NETWORK_TIMEOUT,
2523deb3ec6SMatthias Ringwald     HFP_CME_ERROR_NETWORK_NOT_ALLOWED_EMERGENCY_CALLS_ONLY
2533deb3ec6SMatthias Ringwald } hfp_cme_error_t;
2543deb3ec6SMatthias Ringwald 
2553deb3ec6SMatthias Ringwald typedef enum {
2563deb3ec6SMatthias Ringwald     HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS = 0,
2573deb3ec6SMatthias Ringwald     HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT
2583deb3ec6SMatthias Ringwald } hfp_call_status_t;
2593deb3ec6SMatthias Ringwald 
2603deb3ec6SMatthias Ringwald typedef enum {
2613deb3ec6SMatthias Ringwald     HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS = 0,
2623deb3ec6SMatthias Ringwald     HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS,
2633deb3ec6SMatthias Ringwald     HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE,
2643deb3ec6SMatthias Ringwald     HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE
2653deb3ec6SMatthias Ringwald } hfp_callsetup_status_t;
2663deb3ec6SMatthias Ringwald 
2673deb3ec6SMatthias Ringwald typedef enum {
268aa4dd815SMatthias Ringwald     HFP_CALLHELD_STATUS_NO_CALLS_HELD = 0,
269aa4dd815SMatthias Ringwald     HFP_CALLHELD_STATUS_CALL_ON_HOLD_OR_SWAPPED,
270aa4dd815SMatthias Ringwald     HFP_CALLHELD_STATUS_CALL_ON_HOLD_AND_NO_ACTIVE_CALLS
2713deb3ec6SMatthias Ringwald } hfp_callheld_status_t;
2723deb3ec6SMatthias Ringwald 
273d210d9c4SMatthias Ringwald 
2743deb3ec6SMatthias Ringwald typedef enum {
275aa4dd815SMatthias Ringwald     HFP_AG_INCOMING_CALL,
276aa4dd815SMatthias Ringwald     HFP_AG_INCOMING_CALL_ACCEPTED_BY_AG,
277aa4dd815SMatthias Ringwald     HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF,
278aa4dd815SMatthias Ringwald     HFP_AG_AUDIO_CONNECTION_ESTABLISHED,
279*9ff73f41SMatthias Ringwald     HFP_AG_OUTGOING_CALL_INITIATED_BY_HF,
280aa4dd815SMatthias Ringwald     HFP_AG_OUTGOING_CALL_REJECTED,
281aa4dd815SMatthias Ringwald     HFP_AG_OUTGOING_CALL_ACCEPTED,
282aa4dd815SMatthias Ringwald     HFP_AG_OUTGOING_CALL_RINGING,
283aa4dd815SMatthias Ringwald     HFP_AG_OUTGOING_CALL_ESTABLISHED,
284aa4dd815SMatthias Ringwald     HFP_AG_OUTGOING_REDIAL_INITIATED,
285ce263fc8SMatthias Ringwald     HFP_AG_HELD_CALL_JOINED_BY_AG,
286aa4dd815SMatthias Ringwald     HFP_AG_TERMINATE_CALL_BY_AG,
287aa4dd815SMatthias Ringwald     HFP_AG_TERMINATE_CALL_BY_HF,
288aa4dd815SMatthias Ringwald     HFP_AG_CALL_DROPPED,
289ce263fc8SMatthias Ringwald     HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_AG,
290ce263fc8SMatthias Ringwald     HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_AG,
291ce263fc8SMatthias Ringwald     HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_AG,
292ce263fc8SMatthias Ringwald     HFP_AG_RESPONSE_AND_HOLD_ACCEPT_INCOMING_CALL_BY_HF,
293ce263fc8SMatthias Ringwald     HFP_AG_RESPONSE_AND_HOLD_ACCEPT_HELD_CALL_BY_HF,
294d210d9c4SMatthias Ringwald     HFP_AG_RESPONSE_AND_HOLD_REJECT_HELD_CALL_BY_HF,
295d210d9c4SMatthias Ringwald     HFP_AG_CALL_HOLD_USER_BUSY,
296d210d9c4SMatthias Ringwald     HFP_AG_CALL_HOLD_RELEASE_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL,
297d210d9c4SMatthias Ringwald     HFP_AG_CALL_HOLD_PARK_ACTIVE_ACCEPT_HELD_OR_WAITING_CALL,
298d210d9c4SMatthias Ringwald     HFP_AG_CALL_HOLD_ADD_HELD_CALL,
299d0c20769SMatthias Ringwald     HFP_AG_CALL_HOLD_EXIT_AND_JOIN_CALLS,
300d0c20769SMatthias Ringwald     HFP_AG_SET_CLIP
301aa4dd815SMatthias Ringwald } hfp_ag_call_event_t;
302aa4dd815SMatthias Ringwald 
303aa4dd815SMatthias Ringwald 
304aa4dd815SMatthias Ringwald typedef enum {
3053deb3ec6SMatthias Ringwald     HFP_PARSER_CMD_HEADER = 0,
3063deb3ec6SMatthias Ringwald     HFP_PARSER_CMD_SEQUENCE,
3073deb3ec6SMatthias Ringwald     HFP_PARSER_SECOND_ITEM,
3083deb3ec6SMatthias Ringwald     HFP_PARSER_THIRD_ITEM
3093deb3ec6SMatthias Ringwald } hfp_parser_state_t;
3103deb3ec6SMatthias Ringwald 
3113deb3ec6SMatthias Ringwald 
3123deb3ec6SMatthias Ringwald typedef enum {
3133deb3ec6SMatthias Ringwald     HFP_IDLE = 0, //0
3143deb3ec6SMatthias Ringwald     HFP_SDP_QUERY_RFCOMM_CHANNEL,
3151d9c9c90SMilanka Ringwald     HFP_W2_SEND_SDP_QUERY,
316a0ffb263SMatthias Ringwald     HFP_W4_SDP_QUERY_COMPLETE,
3173deb3ec6SMatthias Ringwald     HFP_W4_RFCOMM_CONNECTED,
3183deb3ec6SMatthias Ringwald 
3191d9c9c90SMilanka Ringwald     HFP_EXCHANGE_SUPPORTED_FEATURES,   // 5
3201d9c9c90SMilanka Ringwald     HFP_W4_EXCHANGE_SUPPORTED_FEATURES,
3213deb3ec6SMatthias Ringwald 
3223deb3ec6SMatthias Ringwald     HFP_NOTIFY_ON_CODECS,
3233deb3ec6SMatthias Ringwald     HFP_W4_NOTIFY_ON_CODECS,
3243deb3ec6SMatthias Ringwald 
3253deb3ec6SMatthias Ringwald     HFP_RETRIEVE_INDICATORS,
3261d9c9c90SMilanka Ringwald     HFP_W4_RETRIEVE_INDICATORS,        // 10
3273deb3ec6SMatthias Ringwald 
3281d9c9c90SMilanka Ringwald     HFP_RETRIEVE_INDICATORS_STATUS,
3293deb3ec6SMatthias Ringwald     HFP_W4_RETRIEVE_INDICATORS_STATUS,
3303deb3ec6SMatthias Ringwald 
3313deb3ec6SMatthias Ringwald     HFP_ENABLE_INDICATORS_STATUS_UPDATE,
3323deb3ec6SMatthias Ringwald     HFP_W4_ENABLE_INDICATORS_STATUS_UPDATE,
3333deb3ec6SMatthias Ringwald 
3341d9c9c90SMilanka Ringwald     HFP_RETRIEVE_CAN_HOLD_CALL,        // 15
3351d9c9c90SMilanka Ringwald     HFP_W4_RETRIEVE_CAN_HOLD_CALL,
3363deb3ec6SMatthias Ringwald 
3373deb3ec6SMatthias Ringwald     HFP_LIST_GENERIC_STATUS_INDICATORS,
3383deb3ec6SMatthias Ringwald     HFP_W4_LIST_GENERIC_STATUS_INDICATORS,
3393deb3ec6SMatthias Ringwald 
3403deb3ec6SMatthias Ringwald     HFP_RETRIEVE_GENERIC_STATUS_INDICATORS,
3411d9c9c90SMilanka Ringwald     HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS,  //20
3423deb3ec6SMatthias Ringwald 
3431d9c9c90SMilanka Ringwald     HFP_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS,
3443deb3ec6SMatthias Ringwald     HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS,
3453deb3ec6SMatthias Ringwald 
346aa4dd815SMatthias Ringwald     HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED,
3473deb3ec6SMatthias Ringwald 
348aa4dd815SMatthias Ringwald     HFP_W2_CONNECT_SCO,
349aa4dd815SMatthias Ringwald     HFP_W4_SCO_CONNECTED,
3503deb3ec6SMatthias Ringwald 
3513deb3ec6SMatthias Ringwald     HFP_AUDIO_CONNECTION_ESTABLISHED,
3523deb3ec6SMatthias Ringwald 
3533deb3ec6SMatthias Ringwald     HFP_W2_DISCONNECT_SCO,
354aa4dd815SMatthias Ringwald     HFP_W4_SCO_DISCONNECTED,
35548e6eeeeSMatthias Ringwald     HFP_W4_SCO_DISCONNECTED_TO_SHUTDOWN,
35648e6eeeeSMatthias Ringwald     HFP_W4_WBS_SHUTDOWN,
3573deb3ec6SMatthias Ringwald 
3583deb3ec6SMatthias Ringwald     HFP_W2_DISCONNECT_RFCOMM,
3593deb3ec6SMatthias Ringwald     HFP_W4_RFCOMM_DISCONNECTED,
3603deb3ec6SMatthias Ringwald     HFP_W4_RFCOMM_DISCONNECTED_AND_RESTART,
3613deb3ec6SMatthias Ringwald     HFP_W4_CONNECTION_ESTABLISHED_TO_SHUTDOWN
3623deb3ec6SMatthias Ringwald } hfp_state_t;
3633deb3ec6SMatthias Ringwald 
364aa4dd815SMatthias Ringwald typedef enum {
365aa4dd815SMatthias Ringwald     HFP_CODECS_IDLE,
366aa4dd815SMatthias Ringwald     HFP_CODECS_RECEIVED_LIST,
367aa4dd815SMatthias Ringwald     HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE,
368aa4dd815SMatthias Ringwald     HFP_CODECS_W4_AG_COMMON_CODEC,
369aa4dd815SMatthias Ringwald     HFP_CODECS_AG_SENT_COMMON_CODEC,
370aa4dd815SMatthias Ringwald     HFP_CODECS_AG_RESEND_COMMON_CODEC,
371ce263fc8SMatthias Ringwald     HFP_CODECS_HF_CONFIRMED_CODEC,
372aa4dd815SMatthias Ringwald     HFP_CODECS_EXCHANGED,
373aa4dd815SMatthias Ringwald     HFP_CODECS_ERROR
374aa4dd815SMatthias Ringwald } hfp_codecs_state_t;
375aa4dd815SMatthias Ringwald 
376aa4dd815SMatthias Ringwald typedef enum {
377aa4dd815SMatthias Ringwald     HFP_CALL_IDLE,
378aa4dd815SMatthias Ringwald     HFP_CALL_TRIGGER_AUDIO_CONNECTION,
379aa4dd815SMatthias Ringwald     HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING,
380aa4dd815SMatthias Ringwald     HFP_CALL_RINGING,
381aa4dd815SMatthias Ringwald     HFP_CALL_W4_AUDIO_CONNECTION_FOR_ACTIVE,
382aa4dd815SMatthias Ringwald     HFP_CALL_ACTIVE,
383aa4dd815SMatthias Ringwald     HFP_CALL_W2_SEND_CALL_WAITING,
384aa4dd815SMatthias Ringwald     HFP_CALL_W4_CHLD,
385aa4dd815SMatthias Ringwald     HFP_CALL_OUTGOING_INITIATED,
386aa4dd815SMatthias Ringwald     HFP_CALL_OUTGOING_DIALING,
387aa4dd815SMatthias Ringwald     HFP_CALL_OUTGOING_RINGING
388aa4dd815SMatthias Ringwald } hfp_call_state_t;
389aa4dd815SMatthias Ringwald 
390aa4dd815SMatthias Ringwald typedef enum{
391ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_DIR_OUTGOING,
392ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_DIR_INCOMING
393ce263fc8SMatthias Ringwald } hfp_enhanced_call_dir_t;
394ce263fc8SMatthias Ringwald 
395ce263fc8SMatthias Ringwald typedef enum{
396ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_STATUS_ACTIVE,
397ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_STATUS_HELD,
398ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING,
399ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING,
400ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_STATUS_INCOMING,
401ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING,
402ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD
403ce263fc8SMatthias Ringwald } hfp_enhanced_call_status_t;
404ce263fc8SMatthias Ringwald 
405ce263fc8SMatthias Ringwald typedef enum{
406ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_MODE_VOICE,
407ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_MODE_DATA,
408ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_MODE_FAX
409ce263fc8SMatthias Ringwald } hfp_enhanced_call_mode_t;
410ce263fc8SMatthias Ringwald 
411ce263fc8SMatthias Ringwald typedef enum{
412ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL,
413ce263fc8SMatthias Ringwald     HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL
414ce263fc8SMatthias Ringwald } hfp_enhanced_call_mpty_t;
415ce263fc8SMatthias Ringwald 
416ce263fc8SMatthias Ringwald typedef enum {
417ce263fc8SMatthias Ringwald     HFP_RESPONSE_AND_HOLD_INCOMING_ON_HOLD = 0,
418ce263fc8SMatthias Ringwald     HFP_RESPONSE_AND_HOLD_HELD_INCOMING_ACCEPTED,
419ce263fc8SMatthias Ringwald     HFP_RESPONSE_AND_HOLD_HELD_INCOMING_REJECTED
420ce263fc8SMatthias Ringwald } hfp_response_and_hold_state_t;
421ce263fc8SMatthias Ringwald 
422ce263fc8SMatthias Ringwald typedef enum {
423ce263fc8SMatthias Ringwald     HFP_HF_QUERY_OPERATOR_FORMAT_NOT_SET = 0,
424ce263fc8SMatthias Ringwald     HFP_HF_QUERY_OPERATOR_SET_FORMAT,
425ce263fc8SMatthias Ringwald     HFP_HF_QUERY_OPERATOR_W4_SET_FORMAT_OK,
426ce263fc8SMatthias Ringwald     HFP_HF_QUERY_OPERATOR_FORMAT_SET,
427ce263fc8SMatthias Ringwald     HFP_HF_QUERY_OPERATOR_SEND_QUERY,
428ce263fc8SMatthias Ringwald     HPF_HF_QUERY_OPERATOR_W4_RESULT
429ce263fc8SMatthias Ringwald } hfp_hf_query_operator_state_t;
430ce263fc8SMatthias Ringwald 
431ce263fc8SMatthias Ringwald typedef enum {
432ce263fc8SMatthias Ringwald     HFP_LINK_SETTINGS_D0 = 0,
433ce263fc8SMatthias Ringwald     HFP_LINK_SETTINGS_D1,
434ce263fc8SMatthias Ringwald     HFP_LINK_SETTINGS_S1,
435ce263fc8SMatthias Ringwald     HFP_LINK_SETTINGS_S2,
436ce263fc8SMatthias Ringwald     HFP_LINK_SETTINGS_S3,
437ce263fc8SMatthias Ringwald     HFP_LINK_SETTINGS_S4,
438ce263fc8SMatthias Ringwald     HFP_LINK_SETTINGS_T1,
439b5c379c1SMatthias Ringwald     HFP_LINK_SETTINGS_T2,
440b5c379c1SMatthias Ringwald     HFP_LINK_SETTINGS_NONE,
441b5c379c1SMatthias Ringwald } hfp_link_settings_t;
442ce263fc8SMatthias Ringwald 
443ce263fc8SMatthias Ringwald typedef enum{
444aa4dd815SMatthias Ringwald     HFP_NONE_SM,
445aa4dd815SMatthias Ringwald     HFP_SLC_SM,
446aa4dd815SMatthias Ringwald     HFP_SLC_QUERIES_SM,
447aa4dd815SMatthias Ringwald     HFP_CODECS_CONNECTION_SM,
448aa4dd815SMatthias Ringwald     HFP_AUDIO_CONNECTION_SM,
449aa4dd815SMatthias Ringwald     HFP_CALL_SM
450aa4dd815SMatthias Ringwald } hfp_state_machine_t;
451aa4dd815SMatthias Ringwald 
4523deb3ec6SMatthias Ringwald typedef struct{
4533deb3ec6SMatthias Ringwald     uint16_t uuid;
4543deb3ec6SMatthias Ringwald     uint8_t state; // enabled
4553deb3ec6SMatthias Ringwald } hfp_generic_status_indicator_t;
4563deb3ec6SMatthias Ringwald 
4573deb3ec6SMatthias Ringwald typedef struct{
4583deb3ec6SMatthias Ringwald     uint8_t index;
4593deb3ec6SMatthias Ringwald     char name[HFP_MAX_INDICATOR_DESC_SIZE];
4603deb3ec6SMatthias Ringwald     uint8_t min_range;
4613deb3ec6SMatthias Ringwald     uint8_t max_range;
4623deb3ec6SMatthias Ringwald     uint8_t status;
4633deb3ec6SMatthias Ringwald     uint8_t mandatory;
4643deb3ec6SMatthias Ringwald     uint8_t enabled;
4653deb3ec6SMatthias Ringwald     uint8_t status_changed;
4663deb3ec6SMatthias Ringwald } hfp_ag_indicator_t;
4673deb3ec6SMatthias Ringwald 
4683deb3ec6SMatthias Ringwald typedef struct{
46989425bfcSMilanka Ringwald     char name[HFP_CALL_SERVICE_SIZE];
4703deb3ec6SMatthias Ringwald } hfp_call_service_t;
4713deb3ec6SMatthias Ringwald 
4723deb3ec6SMatthias Ringwald 
4733deb3ec6SMatthias Ringwald typedef struct{
4743deb3ec6SMatthias Ringwald     uint8_t mode;
4753deb3ec6SMatthias Ringwald     uint8_t format;
47689425bfcSMilanka Ringwald     char name[HFP_MAX_NETWORK_OPERATOR_NAME_SIZE]; // enabled
4773deb3ec6SMatthias Ringwald } hfp_network_opearator_t;
4783deb3ec6SMatthias Ringwald 
4793deb3ec6SMatthias Ringwald 
4803deb3ec6SMatthias Ringwald typedef struct hfp_connection {
481665d90f2SMatthias Ringwald     btstack_linked_item_t    item;
4823deb3ec6SMatthias Ringwald 
483323d3000SMatthias Ringwald     // local role: HF or AG
484323d3000SMatthias Ringwald     hfp_role_t local_role;
485323d3000SMatthias Ringwald 
4863deb3ec6SMatthias Ringwald     bd_addr_t remote_addr;
487fc64f94aSMatthias Ringwald     hci_con_handle_t acl_handle;
488fc64f94aSMatthias Ringwald     hci_con_handle_t sco_handle;
4893deb3ec6SMatthias Ringwald     uint16_t rfcomm_channel_nr;
4903deb3ec6SMatthias Ringwald     uint16_t rfcomm_cid;
4913deb3ec6SMatthias Ringwald 
492aa4dd815SMatthias Ringwald     hfp_state_machine_t state_machine;
493aa4dd815SMatthias Ringwald     hfp_call_state_t call_state;
4943deb3ec6SMatthias Ringwald     hfp_state_t state;
495aa4dd815SMatthias Ringwald     hfp_codecs_state_t codecs_state;
496aa4dd815SMatthias Ringwald 
497323d3000SMatthias Ringwald     // needed for reestablishing connection - service uuid of the remote
4983deb3ec6SMatthias Ringwald     uint16_t service_uuid;
4993deb3ec6SMatthias Ringwald 
5003deb3ec6SMatthias Ringwald     // used during service level connection establishment
5013deb3ec6SMatthias Ringwald     hfp_command_t command;
5023deb3ec6SMatthias Ringwald     hfp_parser_state_t parser_state;
5033deb3ec6SMatthias Ringwald     int      parser_item_index;
504ce263fc8SMatthias Ringwald     int      parser_indicator_index;
5050222a807SMatthias Ringwald     uint32_t parser_indicator_value;
5061dddc4f4SMatthias Ringwald     bool     parser_quoted;
5073deb3ec6SMatthias Ringwald     uint8_t  line_buffer[HFP_MAX_INDICATOR_DESC_SIZE];
5083deb3ec6SMatthias Ringwald     int      line_size;
5093deb3ec6SMatthias Ringwald 
5103deb3ec6SMatthias Ringwald     uint32_t remote_supported_features;
5113deb3ec6SMatthias Ringwald 
51225789943SMilanka Ringwald     uint16_t remote_codecs_nr;
51325789943SMilanka Ringwald     uint8_t  remote_codecs[HFP_MAX_NUM_CODECS];
514667ec068SMatthias Ringwald 
51525789943SMilanka Ringwald     uint16_t ag_indicators_nr;
51625789943SMilanka Ringwald     hfp_ag_indicator_t ag_indicators[HFP_MAX_NUM_INDICATORS];
517667ec068SMatthias Ringwald     uint32_t ag_indicators_status_update_bitmap;
518667ec068SMatthias Ringwald     uint8_t  enable_status_update_for_ag_indicators;
519667ec068SMatthias Ringwald 
52025789943SMilanka Ringwald     uint16_t remote_call_services_index;
52125789943SMilanka Ringwald     hfp_call_service_t remote_call_services[HFP_MAX_NUM_CALL_SERVICES];
5223deb3ec6SMatthias Ringwald 
5233deb3ec6SMatthias Ringwald     // TODO: use bitmap.
52425789943SMilanka Ringwald     uint16_t generic_status_indicators_nr;
525667ec068SMatthias Ringwald     uint32_t generic_status_update_bitmap;
52625789943SMilanka Ringwald     hfp_generic_status_indicator_t generic_status_indicators[HFP_MAX_NUM_INDICATORS];
5273deb3ec6SMatthias Ringwald 
5283deb3ec6SMatthias Ringwald     hfp_network_opearator_t network_operator;
5293deb3ec6SMatthias Ringwald 
5303deb3ec6SMatthias Ringwald     // Retrieved during service level connection establishment, not used yet
5313deb3ec6SMatthias Ringwald     uint8_t  negotiated_codec;
5323deb3ec6SMatthias Ringwald 
533aa4dd815SMatthias Ringwald     // HF -> AG configuration
534aa4dd815SMatthias Ringwald     uint8_t clip_enabled;
535aa4dd815SMatthias Ringwald     uint8_t call_waiting_notification_enabled;
536aa4dd815SMatthias Ringwald 
5373deb3ec6SMatthias Ringwald     // TODO: put these bit flags in a bitmap
538aa4dd815SMatthias Ringwald     uint8_t ok_pending;
539aa4dd815SMatthias Ringwald     // uint8_t send_ok;
5403deb3ec6SMatthias Ringwald     uint8_t send_error;
5413deb3ec6SMatthias Ringwald 
542dd533208SMatthias Ringwald     bool found_equal_sign;
543ce263fc8SMatthias Ringwald     uint8_t ignore_value;
5443deb3ec6SMatthias Ringwald 
5453deb3ec6SMatthias Ringwald     uint8_t change_status_update_for_individual_ag_indicators;
5463deb3ec6SMatthias Ringwald     uint8_t operator_name_changed;
5473deb3ec6SMatthias Ringwald 
5483deb3ec6SMatthias Ringwald     uint8_t enable_extended_audio_gateway_error_report;
549a0ffb263SMatthias Ringwald     uint8_t extended_audio_gateway_error_value;
5503deb3ec6SMatthias Ringwald     uint8_t extended_audio_gateway_error;
5513deb3ec6SMatthias Ringwald 
5523deb3ec6SMatthias Ringwald     // establish codecs connection
5533deb3ec6SMatthias Ringwald     uint8_t suggested_codec;
5543deb3ec6SMatthias Ringwald     uint8_t codec_confirmed;
555bc1b1537SMilanka Ringwald     uint8_t sco_for_msbc_failed;
5562ee45eb2SMilanka Ringwald     uint8_t trigger_codec_exchange;
557cb81d35dSMatthias Ringwald 
558cb81d35dSMatthias Ringwald     // establish audio connection
559cb81d35dSMatthias Ringwald     hfp_link_settings_t link_setting;
560cb81d35dSMatthias Ringwald     uint8_t accept_sco; // 1 = SCO, 2 = eSCO
561cb81d35dSMatthias Ringwald 
5623deb3ec6SMatthias Ringwald     uint8_t establish_audio_connection;
5633deb3ec6SMatthias Ringwald     uint8_t release_audio_connection;
5648439fb24SMilanka Ringwald     uint8_t release_slc_connection;
5653deb3ec6SMatthias Ringwald 
566ec820d77SMatthias Ringwald     btstack_timer_source_t hfp_timeout;
567aa4dd815SMatthias Ringwald 
568aa4dd815SMatthias Ringwald     uint8_t microphone_gain;
569aa4dd815SMatthias Ringwald     uint8_t send_microphone_gain;
570aa4dd815SMatthias Ringwald 
571aa4dd815SMatthias Ringwald     uint8_t speaker_gain;
572aa4dd815SMatthias Ringwald     uint8_t send_speaker_gain;
573aa4dd815SMatthias Ringwald 
574aa4dd815SMatthias Ringwald     uint8_t send_phone_number_for_voice_tag;
575ce263fc8SMatthias Ringwald     uint8_t send_ag_status_indicators;
576ad902e3dSMatthias Ringwald     uint8_t send_ag_indicators_segment;
577a5bdcda8SMatthias Ringwald     uint8_t send_response_and_hold_status;  // 0 - don't send. BRTH:0 == 1, ..
578ce263fc8SMatthias Ringwald 
579ce263fc8SMatthias Ringwald     // AG only
580ce263fc8SMatthias Ringwald     uint8_t change_in_band_ring_tone_setting;
581ce263fc8SMatthias Ringwald     uint8_t ag_ring;
582ce263fc8SMatthias Ringwald     uint8_t ag_send_clip;
583ce263fc8SMatthias Ringwald     uint8_t ag_echo_and_noise_reduction;
584ce263fc8SMatthias Ringwald     uint8_t ag_activate_voice_recognition;
585a0ffb263SMatthias Ringwald     uint8_t ag_notify_incoming_call_waiting;
586ce263fc8SMatthias Ringwald     uint8_t send_subscriber_number;
587ce263fc8SMatthias Ringwald     uint8_t next_subscriber_number_to_send;
5880222a807SMatthias Ringwald     uint8_t ag_call_hold_action;
5890222a807SMatthias Ringwald     uint8_t ag_response_and_hold_action;
5900222a807SMatthias Ringwald     uint8_t ag_dtmf_code;
591245852b7SMilanka Ringwald     bool    ag_send_no_carrier;
592ce263fc8SMatthias Ringwald 
593ce263fc8SMatthias Ringwald     int send_status_of_current_calls;
5949cae807eSMatthias Ringwald     int next_call_index;
595ce263fc8SMatthias Ringwald 
596ce263fc8SMatthias Ringwald     // HF only
597ce263fc8SMatthias Ringwald     hfp_hf_query_operator_state_t hf_query_operator_state;
598ce263fc8SMatthias Ringwald     uint8_t hf_answer_incoming_call;
599ce263fc8SMatthias Ringwald     uint8_t hf_initiate_outgoing_call;
600ce263fc8SMatthias Ringwald     uint8_t hf_initiate_memory_dialing;
601ce263fc8SMatthias Ringwald     uint8_t hf_initiate_redial_last_number;
6021cc65c4fSMatthias Ringwald     bool    hf_send_codec_confirm;
6031cc65c4fSMatthias Ringwald     bool    hf_send_supported_codecs;
6041cc65c4fSMatthias Ringwald 
605a0ffb263SMatthias Ringwald     int memory_id;
606ce263fc8SMatthias Ringwald 
607ce263fc8SMatthias Ringwald     uint8_t hf_send_clip_enable;
608ce263fc8SMatthias Ringwald     uint8_t hf_send_chup;
609ce263fc8SMatthias Ringwald     uint8_t hf_send_chld_0;
610ce263fc8SMatthias Ringwald     uint8_t hf_send_chld_1;
611ce263fc8SMatthias Ringwald     uint8_t hf_send_chld_2;
612ce263fc8SMatthias Ringwald     uint8_t hf_send_chld_3;
613ce263fc8SMatthias Ringwald     uint8_t hf_send_chld_4;
614667ec068SMatthias Ringwald     uint8_t hf_send_chld_x;
615667ec068SMatthias Ringwald     uint8_t hf_send_chld_x_index;
616ce263fc8SMatthias Ringwald     char    hf_send_dtmf_code;
617ce263fc8SMatthias Ringwald     uint8_t hf_send_binp;
618667ec068SMatthias Ringwald     uint8_t hf_send_clcc;
619667ec068SMatthias Ringwald     uint8_t hf_send_rrh;
620667ec068SMatthias Ringwald     char    hf_send_rrh_command;
621667ec068SMatthias Ringwald     uint8_t hf_send_cnum;
622667ec068SMatthias Ringwald 
623ce263fc8SMatthias Ringwald     uint8_t hf_activate_call_waiting_notification;
624ce263fc8SMatthias Ringwald     uint8_t hf_deactivate_call_waiting_notification;
625ce263fc8SMatthias Ringwald 
626ce263fc8SMatthias Ringwald     uint8_t hf_activate_calling_line_notification;
627ce263fc8SMatthias Ringwald     uint8_t hf_deactivate_calling_line_notification;
628ce263fc8SMatthias Ringwald     uint8_t hf_activate_echo_canceling_and_noise_reduction;
629ce263fc8SMatthias Ringwald     uint8_t hf_deactivate_echo_canceling_and_noise_reduction;
630ce263fc8SMatthias Ringwald     uint8_t hf_activate_voice_recognition_notification;
631ce263fc8SMatthias Ringwald     uint8_t hf_deactivate_voice_recognition_notification;
632ce263fc8SMatthias Ringwald 
633667ec068SMatthias Ringwald     uint8_t clcc_idx;
634667ec068SMatthias Ringwald     uint8_t clcc_dir;
635667ec068SMatthias Ringwald     uint8_t clcc_status;
636667ec068SMatthias Ringwald     uint8_t clcc_mode;
637667ec068SMatthias Ringwald     uint8_t clcc_mpty;
638667ec068SMatthias Ringwald 
639d0c20769SMatthias Ringwald     uint8_t call_index;
640a0ffb263SMatthias Ringwald     // also used for CLCC, CCWA, CLIP if set
641ce263fc8SMatthias Ringwald     uint8_t bnip_type;       // 0 == not set
642ce263fc8SMatthias Ringwald     char    bnip_number[25]; //
643ce263fc8SMatthias Ringwald 
6443721a235SMatthias Ringwald #ifdef ENABLE_CC256X_ASSISTED_HFP
6453721a235SMatthias Ringwald     bool cc256x_send_write_codec_config;
6463721a235SMatthias Ringwald     bool cc256x_send_wbs_associate;
6473721a235SMatthias Ringwald     bool cc256x_send_wbs_disassociate;
6483721a235SMatthias Ringwald #endif
649689d4323SMatthias Ringwald #ifdef ENABLE_BCM_PCM_WBS
650689d4323SMatthias Ringwald     bool bcm_send_enable_wbs;
651689d4323SMatthias Ringwald     bool bcm_send_disable_wbs;
652689d4323SMatthias Ringwald     bool bcm_send_write_i2spcm_interface_param;
653689d4323SMatthias Ringwald #endif
6543deb3ec6SMatthias Ringwald } hfp_connection_t;
6553deb3ec6SMatthias Ringwald 
6563deb3ec6SMatthias Ringwald // UTILS_START : TODO move to utils
6573deb3ec6SMatthias Ringwald int send_str_over_rfcomm(uint16_t cid, char * command);
6583deb3ec6SMatthias Ringwald int join(char * buffer, int buffer_size, uint8_t * values, int values_nr);
6593deb3ec6SMatthias Ringwald int join_bitmap(char * buffer, int buffer_size, uint32_t values, int values_nr);
6603deb3ec6SMatthias Ringwald int get_bit(uint16_t bitmap, int position);
6613deb3ec6SMatthias Ringwald int store_bit(uint32_t bitmap, int position, uint8_t value);
6623deb3ec6SMatthias Ringwald // UTILS_END
6633deb3ec6SMatthias Ringwald 
66448e6eeeeSMatthias Ringwald void hfp_finalize_connection_context(hfp_connection_t * hfp_connection);
665f2a3f984SMilanka Ringwald 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);
666f2a3f984SMilanka Ringwald 
667ca59be51SMatthias Ringwald void hfp_set_ag_callback(btstack_packet_handler_t callback);
668ca59be51SMatthias Ringwald void hfp_set_ag_rfcomm_packet_handler(btstack_packet_handler_t handler);
669f4000eebSMatthias Ringwald 
670ca59be51SMatthias Ringwald void hfp_set_hf_callback(btstack_packet_handler_t callback);
671ca59be51SMatthias Ringwald void hfp_set_hf_rfcomm_packet_handler(btstack_packet_handler_t handler);
672d68dcce1SMatthias Ringwald 
673520c92d5SMatthias Ringwald void hfp_init(void);
67420b2edb6SMatthias Ringwald void hfp_deinit(void);
675520c92d5SMatthias Ringwald 
6769b1c3b4dSMatthias Ringwald void hfp_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t service_uuid, int rfcomm_channel_nr, const char * name);
677405014fbSMatthias Ringwald void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, hfp_role_t local_role);
67827950165SMatthias Ringwald void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, hfp_role_t local_role);
679ca59be51SMatthias Ringwald void hfp_emit_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, uint8_t value);
680ca59be51SMatthias Ringwald void hfp_emit_simple_event(hfp_connection_t * hfp_connection, uint8_t event_subtype);
681ca59be51SMatthias Ringwald void hfp_emit_string_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, const char * value);
682ca59be51SMatthias Ringwald void hfp_emit_slc_connection_event(hfp_connection_t * hfp_connection, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr);
683aa4dd815SMatthias Ringwald 
6843deb3ec6SMatthias Ringwald hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid);
685405014fbSMatthias Ringwald hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr, hfp_role_t hfp_role);
686405014fbSMatthias Ringwald hfp_connection_t * get_hfp_connection_context_for_sco_handle(uint16_t handle, hfp_role_t hfp_role);
687405014fbSMatthias Ringwald hfp_connection_t * get_hfp_connection_context_for_acl_handle(uint16_t handle, hfp_role_t hfp_role);
688aa4dd815SMatthias Ringwald 
6898f2a52f4SMatthias Ringwald btstack_linked_list_t * hfp_get_connections(void);
690a0ffb263SMatthias Ringwald void hfp_parse(hfp_connection_t * connection, uint8_t byte, int isHandsFree);
6913deb3ec6SMatthias Ringwald 
692323d3000SMatthias Ringwald void hfp_establish_service_level_connection(bd_addr_t bd_addr, uint16_t service_uuid, hfp_role_t local_role);
6933deb3ec6SMatthias Ringwald void hfp_release_service_level_connection(hfp_connection_t * connection);
694a0ffb263SMatthias Ringwald void hfp_reset_context_flags(hfp_connection_t * connection);
6953deb3ec6SMatthias Ringwald 
696a0ffb263SMatthias Ringwald void hfp_release_audio_connection(hfp_connection_t * connection);
6973deb3ec6SMatthias Ringwald 
698eddcd308SMatthias Ringwald void hfp_setup_synchronous_connection(hfp_connection_t * connection);
699cb81d35dSMatthias Ringwald void hfp_accept_synchronous_connection(hfp_connection_t * hfp_connection, bool incoming_eSCO);
7006a7f44bdSMilanka Ringwald int hfp_supports_codec(uint8_t codec, int codecs_nr, uint8_t * codecs);
701d715cf51SMatthias Ringwald void hfp_hf_drop_mSBC_if_eSCO_not_supported(uint8_t * codecs, uint8_t * codecs_nr);
702e453c1d9SMatthias Ringwald void hfp_init_link_settings(hfp_connection_t * hfp_connection, uint8_t eSCO_S4_supported);
703e453c1d9SMatthias Ringwald 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);
704ce263fc8SMatthias Ringwald 
7053deb3ec6SMatthias Ringwald const char * hfp_hf_feature(int index);
7063deb3ec6SMatthias Ringwald const char * hfp_ag_feature(int index);
7073deb3ec6SMatthias Ringwald 
708186dd3d2SMatthias Ringwald void hfp_log_rfcomm_message(const char * tag, uint8_t * packet, uint16_t size);
709186dd3d2SMatthias Ringwald 
7100aee97efSMilanka Ringwald const char * hfp_enhanced_call_dir2str(uint16_t index);
7110aee97efSMilanka Ringwald const char * hfp_enhanced_call_status2str(uint16_t index);
7120aee97efSMilanka Ringwald const char * hfp_enhanced_call_mode2str(uint16_t index);
7130aee97efSMilanka Ringwald const char * hfp_enhanced_call_mpty2str(uint16_t index);
7140aee97efSMilanka Ringwald 
7153721a235SMatthias Ringwald #ifdef ENABLE_CC256X_ASSISTED_HFP
7163721a235SMatthias Ringwald void hfp_cc256x_prepare_for_sco(hfp_connection_t * hfp_connection);
7173721a235SMatthias Ringwald void hfp_cc256x_write_codec_config(hfp_connection_t * hfp_connection);
7183721a235SMatthias Ringwald #endif
719689d4323SMatthias Ringwald #ifdef ENABLE_BCM_PCM_WBS
720689d4323SMatthias Ringwald void hfp_bcm_prepare_for_sco(hfp_connection_t * hfp_connection);
721689d4323SMatthias Ringwald void hfp_bcm_write_i2spcm_interface_param (hfp_connection_t * hfp_connection);
722689d4323SMatthias Ringwald #endif
7233721a235SMatthias Ringwald 
724991c26beSMatthias Ringwald /**
725352a0504SMatthias Ringwald  * @brief Set packet types for SCO connections
726991c26beSMatthias Ringwald  * @param common single packet_types: HFP_SCO_PACKET_TYPES_*
727991c26beSMatthias Ringwald  */
728991c26beSMatthias Ringwald void hfp_set_sco_packet_types(uint16_t packet_types);
729991c26beSMatthias Ringwald 
730991c26beSMatthias Ringwald /**
731352a0504SMatthias Ringwald  * @brief Get packet types for SCO connections
732991c26beSMatthias Ringwald  * @returns packet_types
733991c26beSMatthias Ringwald  */
734991c26beSMatthias Ringwald uint16_t hfp_get_sco_packet_types(void);
735991c26beSMatthias Ringwald 
7363deb3ec6SMatthias Ringwald #if defined __cplusplus
7373deb3ec6SMatthias Ringwald }
7383deb3ec6SMatthias Ringwald #endif
7393deb3ec6SMatthias Ringwald 
74080e33422SMatthias Ringwald #endif // BTSTACK_HFP_H
741