1 /* 2 * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /******************************************************************************* 8 * 9 * Filename: btc_hf_ag.h 10 * 11 * Description: Main API header file for all BTC HF AG functions accessed 12 * from internal stack. 13 * 14 *******************************************************************************/ 15 16 #ifndef __BTC_HF_AG_H__ 17 #define __BTC_HF_AG_H__ 18 19 #include "common/bt_target.h" 20 #include "btc/btc_task.h" 21 #include "btc/btc_common.h" 22 #include "bta/bta_ag_api.h" 23 #include "esp_hf_ag_api.h" 24 25 26 #if (BTC_HF_INCLUDED == TRUE) 27 28 /******************************************************************************* 29 ** Type Defs 30 ********************************************************************************/ 31 /* btc_hf_act_t */ 32 typedef enum 33 { 34 //INIT 35 BTC_HF_INIT_EVT, 36 BTC_HF_DEINIT_EVT, 37 BTC_HF_CONNECT_EVT, 38 BTC_HF_DISCONNECT_EVT, 39 BTC_HF_CONNECT_AUDIO_EVT, 40 BTC_HF_DISCONNECT_AUDIO_EVT, 41 BTC_HF_VRA_EVT, 42 BTC_HF_VOLUME_CONTROL_EVT, 43 //AT_RESPONSE 44 BTC_HF_UNAT_RESPONSE_EVT, 45 BTC_HF_CME_ERR_EVT, 46 BTC_HF_IND_NOTIFICATION_EVT, 47 BTC_HF_CIEV_REPORT_EVT, 48 BTC_HF_CIND_RESPONSE_EVT, 49 BTC_HF_COPS_RESPONSE_EVT, 50 BTC_HF_CLCC_RESPONSE_EVT, 51 BTC_HF_CNUM_RESPONSE_EVT, 52 BTC_HF_INBAND_RING_EVT, 53 //CALL_HANDLE 54 BTC_HF_AC_INCALL_EVT, 55 BTC_HF_RJ_INCALL_EVT, 56 BTC_HF_OUT_CALL_EVT, 57 BTC_HF_END_CALL_EVT, 58 //REG 59 BTC_HF_REGISTER_DATA_CALLBACK_EVT, 60 BTC_HF_REQUEST_PKT_STAT_EVT 61 } btc_hf_act_t; 62 63 /* btc_hf_args_t */ 64 typedef union 65 { 66 // BTC_HF_CONNECT_EVT 67 bt_bdaddr_t connect; 68 69 // BTC_HF_DISCONNECT_EVT 70 bt_bdaddr_t disconnect; 71 72 // BTC_HF_CONNECT_AUDIO_EVT 73 bt_bdaddr_t connect_audio; 74 75 // BTC_HF_DISCONNECT_AUDIO_EVT 76 bt_bdaddr_t disconnect_audio; 77 78 //BTC_HF_VRA_EVT 79 struct vra_param { 80 bt_bdaddr_t remote_addr; 81 esp_hf_vr_state_t value; 82 } vra_rep; 83 84 // BTC_HF_VOLUME_CONTROL_EVT 85 struct volcon_args { 86 bt_bdaddr_t remote_addr; 87 esp_hf_volume_control_target_t target_type; 88 int volume; 89 } volcon; 90 91 //BTC_HF_UNAT_RESPONSE_EVT 92 struct unat_param { 93 bt_bdaddr_t remote_addr; 94 char *unat; 95 } unat_rep; 96 97 //BTC_HF_CME_ERR_EVT 98 struct at_ok_err_args { 99 bt_bdaddr_t remote_addr; 100 esp_hf_at_response_code_t response_code; 101 esp_hf_cme_err_t error_code; 102 } ext_at; 103 104 // BTC_HF_IND_NOTIFICATION_EVT 105 struct indchange_status { 106 bt_bdaddr_t remote_addr; 107 esp_hf_call_status_t call_state; 108 esp_hf_call_setup_status_t call_setup_state; 109 esp_hf_network_state_t ntk_state; 110 int signal; 111 } ind_change; 112 113 //BTC_HF_CIEV_REPORT_EVT 114 struct ciev_args { 115 bt_bdaddr_t remote_addr; 116 tBTA_AG_IND ind; 117 } ciev_rep; 118 119 //BTC_HF_CIND_RESPONSE_EVT 120 struct cind_args { 121 bt_bdaddr_t remote_addr; 122 esp_hf_call_status_t call_state; 123 esp_hf_call_setup_status_t call_setup_state; 124 esp_hf_network_state_t ntk_state; 125 int signal; 126 esp_hf_roaming_status_t roam; 127 int batt_lev; 128 esp_hf_call_held_status_t call_held_state; 129 } cind_rep; 130 131 //BTC_HF_COPS_RESPONSE_EVT 132 struct cops_args { 133 bt_bdaddr_t remote_addr; 134 char *name; 135 } cops_rep; 136 137 // BTC_HF_CLCC_RESPONSE_EVT 138 struct clcc_args { 139 bt_bdaddr_t remote_addr; 140 int index; 141 esp_hf_current_call_direction_t dir; 142 esp_hf_current_call_status_t current_call_state; 143 esp_hf_current_call_mode_t mode; 144 esp_hf_current_call_mpty_type_t mpty; 145 char *number; 146 esp_hf_call_addr_type_t type; 147 } clcc_rep; 148 149 // BTC_HF_CNUM_RESPONSE_EVT 150 struct cnum_args { 151 bt_bdaddr_t remote_addr; 152 char *number; 153 int number_type; 154 esp_hf_subscriber_service_type_t service_type; 155 } cnum_rep; 156 157 //BTC_HF_NREC_RESPONSE_EVT 158 bt_bdaddr_t nrec_rep; 159 160 //BTC_HF_VTC_RESPONSE_EVT 161 struct bts_args { 162 bt_bdaddr_t remote_addr; 163 char *code; 164 } vts_rep; 165 166 //BTC_HF_INBAND_RING_EVT 167 struct bsir_args { 168 bt_bdaddr_t remote_addr; 169 esp_hf_in_band_ring_state_t state; 170 } bsir; 171 172 // BTC_HF_AC_INCALL_EVT 173 // BTC_HF_RJ_INCALL_EVT 174 // BTC_HF_OUT_CALL_EVT 175 // BTC_HF_END_CALL_EVT 176 struct phone_args { 177 bt_bdaddr_t remote_addr; 178 int num_active; 179 int num_held; 180 esp_hf_call_status_t call_state; 181 esp_hf_call_setup_status_t call_setup_state; 182 char *number; 183 esp_hf_call_addr_type_t call_addr_type; 184 } phone; 185 186 // BTC_HF_REGISTER_DATA_CALLBACK_EVT 187 struct ag_reg_data_callback { 188 esp_hf_incoming_data_cb_t recv; 189 esp_hf_outgoing_data_cb_t send; 190 } reg_data_cb; 191 192 // BTC_HF_REQUEST_PKT_STAT_EVT 193 struct ag_req_pkt_stat_sync_handle { 194 UINT16 sync_conn_handle; 195 } pkt_sync_hd; 196 197 } btc_hf_args_t; 198 199 /************************************************************************************ 200 ** Local definitions 201 ************************************************************************************/ 202 /* Number of BTC-HF-AG control blocks */ 203 #define BTC_HF_NUM_CB 1 204 205 /* Handsfree AG app ids for service registration */ 206 /* APP ID definition*/ 207 #define BTC_HF_ID_1 0 208 209 /* BTC-AG control block to map bdaddr to BTA handle */ 210 typedef struct 211 { 212 bool initialized; 213 UINT16 handle; 214 bt_bdaddr_t connected_bda; 215 tBTA_AG_PEER_FEAT peer_feat; 216 tBTA_AG_CHLD_FEAT chld_feat; 217 struct timespec call_end_timestamp; 218 struct timespec connected_timestamp; 219 esp_hf_connection_state_t connection_state; 220 esp_hf_vr_state_t vr_state; 221 int num_active; 222 int num_held; 223 esp_hf_call_status_t call_state; 224 esp_hf_call_setup_status_t call_setup_state; 225 } btc_hf_cb_t; 226 227 typedef struct 228 { 229 int hf_idx; 230 UINT32 btc_hf_features; 231 btc_hf_cb_t btc_hf_cb; 232 esp_hf_incoming_data_cb_t btc_hf_incoming_data_cb; 233 esp_hf_outgoing_data_cb_t btc_hf_outgoing_data_cb; 234 } hf_local_param_t; 235 236 #if HFP_DYNAMIC_MEMORY == TRUE 237 extern hf_local_param_t *hf_local_param_ptr; 238 #define hf_local_param (hf_local_param_ptr) 239 #endif 240 241 /******************************************************************************* 242 ** BTC HF AG Handle Hub 243 ********************************************************************************/ 244 void btc_hf_call_handler(btc_msg_t *msg); // act the cmd from esp-application 245 246 void btc_hf_cb_handler(btc_msg_t *msg); //handle the event from bta 247 248 void btc_hf_incoming_data_cb_to_app(const uint8_t *data, uint32_t len); 249 250 uint32_t btc_hf_outgoing_data_cb_to_app(uint8_t *data, uint32_t len); 251 252 void btc_hf_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); 253 254 void btc_hf_arg_deep_free(btc_msg_t *msg); 255 256 bt_status_t btc_hf_ci_sco_data(void); 257 258 #endif // BTC_HF_INCLUDED == TRUE 259 260 #endif /* __BTC_HF_AG_H__ */ 261