1 /** @file 2 * @brief Internal APIs for Bluetooth Handsfree profile handling. 3 */ 4 5 /* 6 * Copyright (c) 2015-2016 Intel Corporation 7 * Copyright 2024 NXP 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 */ 11 12 /* HFP AG Supported features */ 13 #define BT_HFP_AG_SUPPORTED_FEATURES (BT_HFP_AG_FEATURE_INBAND_RINGTONE | BT_HFP_AG_FEATURE_EXT_ERR) 14 15 /* bt_hfp_ag flags: the flags defined here represent HFP AG parameters */ 16 enum { 17 BT_HFP_AG_CMEE_ENABLE, /* Extended Audio Gateway Error Result Code */ 18 BT_HFP_AG_CMER_ENABLE, /* Indicator Events Reporting */ 19 BT_HFP_AG_CLIP_ENABLE, /* Calling Line Identification notification */ 20 BT_HFP_AG_INBAND_RING, /* In-band ring */ 21 BT_HFP_AG_COPS_SET, /* Query Operator selection */ 22 BT_HFP_AG_INCOMING_CALL, /* Incoming call */ 23 BT_HFP_AG_CODEC_CONN, /* Codec connection is ongoing */ 24 BT_HFP_AG_CODEC_CHANGED, /* Codec Id Changed */ 25 BT_HFP_AG_TX_ONGOING, /* TX is ongoing */ 26 BT_HFP_AG_CREATING_SCO, /* SCO is creating */ 27 28 /* Total number of flags - must be at the end of the enum */ 29 BT_HFP_AG_NUM_FLAGS, 30 }; 31 32 /* HFP HF Indicators */ 33 enum { 34 HFP_HF_ENHANCED_SAFETY_IND = 1, /* Enhanced Safety */ 35 HFP_HF_BATTERY_LEVEL_IND = 2, /* Remaining level of Battery */ 36 HFP_HF_IND_MAX 37 }; 38 39 typedef enum __packed { 40 /** Session disconnected */ 41 BT_HFP_DISCONNECTED, 42 /** Session in connecting state */ 43 BT_HFP_CONNECTING, 44 /** Session in config state, HFP configuration */ 45 BT_HFP_CONFIG, 46 /** Session ready for upper layer traffic on it */ 47 BT_HFP_CONNECTED, 48 /** Session in disconnecting state */ 49 BT_HFP_DISCONNECTING, 50 } bt_hfp_state_t; 51 52 typedef enum __packed { 53 /** Call terminate */ 54 BT_HFP_CALL_TERMINATE, 55 /** Call outgoing */ 56 BT_HFP_CALL_OUTGOING, 57 /** Call incoming */ 58 BT_HFP_CALL_INCOMING, 59 /** Call alerting */ 60 BT_HFP_CALL_ALERTING, 61 /** Call active */ 62 BT_HFP_CALL_ACTIVE, 63 /** Call hold */ 64 BT_HFP_CALL_HOLD, 65 } bt_hfp_call_state_t; 66 67 #define AT_COPS_OPERATOR_MAX_LEN 16 68 69 struct bt_hfp_ag { 70 struct bt_rfcomm_dlc rfcomm_dlc; 71 char buffer[HF_MAX_BUF_LEN]; 72 uint32_t hf_features; 73 uint32_t ag_features; 74 75 /* HF Supported Codec Ids*/ 76 uint32_t hf_codec_ids; 77 uint8_t selected_codec_id; 78 79 ATOMIC_DEFINE(flags, BT_HFP_AG_NUM_FLAGS); 80 81 /* ACL Connection Object */ 82 struct bt_conn *acl_conn; 83 84 /* HFP Connection state */ 85 bt_hfp_state_t state; 86 87 /* HFP Call state */ 88 bt_hfp_call_state_t call_state; 89 90 /* Delayed work deferred tasks: 91 * - call status cleanup. 92 */ 93 struct k_work_delayable deferred_work; 94 95 /* AG Indicators */ 96 uint8_t indicator_value[BT_HFP_AG_IND_MAX]; 97 uint32_t indicator; 98 99 /* HF Indicators */ 100 uint32_t hf_indicators_of_ag; 101 uint32_t hf_indicators_of_hf; 102 uint8_t hf_indicator_value[HFP_HF_IND_MAX]; 103 104 /* operator */ 105 char operator[AT_COPS_OPERATOR_MAX_LEN + 1]; 106 107 /* SCO Connection Object */ 108 struct bt_sco_chan sco_chan; 109 /* HFP TX pending */ 110 sys_slist_t tx_pending; 111 112 /* Dial number or incoming number */ 113 char number[CONFIG_BT_HFP_AG_PHONE_NUMBER_MAX_LEN + 1]; 114 115 /* Calling Line Identification notification */ 116 struct k_work_delayable ringing_work; 117 118 /* Critical locker */ 119 struct k_sem lock; 120 121 /* TX work */ 122 struct k_work_delayable tx_work; 123 }; 124 125 /* Active */ 126 #define HFP_AG_CLCC_STATUS_ACTIVE 0 127 /* Held */ 128 #define HFP_AG_CLCC_STATUS_HELD 1 129 /* Dialing (outgoing calls only) */ 130 #define HFP_AG_CLCC_STATUS_DIALING 2 131 /* Alerting (outgoing calls only) */ 132 #define HFP_AG_CLCC_STATUS_ALERTING 3 133 /* Incoming (incoming calls only) */ 134 #define HFP_AG_CLCC_STATUS_INCOMING 4 135 /* Waiting (incoming calls only) */ 136 #define HFP_AG_CLCC_STATUS_WAITING 5 137 /* Call held by Response and Hold */ 138 #define HFP_AG_CLCC_STATUS_CALL_HELD_HOLD 6 139 /* Invalid status */ 140 #define HFP_AG_CLCC_STATUS_INVALID 0xFFU 141