1 /* 2 * SPDX-FileCopyrightText: 2015-2021 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_CIND_RESPONSE_EVT, 48 BTC_HF_COPS_RESPONSE_EVT, 49 BTC_HF_CLCC_RESPONSE_EVT, 50 BTC_HF_CNUM_RESPONSE_EVT, 51 BTC_HF_INBAND_RING_EVT, 52 //CALL_HANDLE 53 BTC_HF_AC_INCALL_EVT, 54 BTC_HF_RJ_INCALL_EVT, 55 BTC_HF_OUT_CALL_EVT, 56 BTC_HF_END_CALL_EVT, 57 //REG 58 BTC_HF_REGISTER_DATA_CALLBACK_EVT 59 } btc_hf_act_t; 60 61 /* btc_hf_args_t */ 62 typedef union 63 { 64 // BTC_HF_CONNECT_EVT 65 bt_bdaddr_t connect; 66 67 // BTC_HF_DISCONNECT_EVT 68 bt_bdaddr_t disconnect; 69 70 // BTC_HF_CONNECT_AUDIO_EVT 71 bt_bdaddr_t connect_audio; 72 73 // BTC_HF_DISCONNECT_AUDIO_EVT 74 bt_bdaddr_t disconnect_audio; 75 76 //BTC_HF_VRA_EVT 77 struct vra_param { 78 bt_bdaddr_t remote_addr; 79 esp_hf_vr_state_t value; 80 } vra_rep; 81 82 // BTC_HF_VOLUME_CONTROL_EVT 83 struct volcon_args { 84 bt_bdaddr_t remote_addr; 85 esp_hf_volume_control_target_t target_type; 86 int volume; 87 } volcon; 88 89 //BTC_HF_UNAT_RESPONSE_EVT 90 struct unat_param { 91 bt_bdaddr_t remote_addr; 92 char *unat; 93 } unat_rep; 94 95 //BTC_HF_CME_ERR_EVT 96 struct at_ok_err_args { 97 bt_bdaddr_t remote_addr; 98 esp_hf_at_response_code_t response_code; 99 esp_hf_cme_err_t error_code; 100 } ext_at; 101 102 // BTC_HF_IND_NOTIFICATION_EVT 103 struct indchange_status { 104 bt_bdaddr_t remote_addr; 105 esp_hf_call_status_t call_state; 106 esp_hf_call_setup_status_t call_setup_state; 107 esp_hf_network_state_t ntk_state; 108 int signal; 109 } ind_change; 110 111 //BTC_HF_CIND_RESPONSE_EVT 112 struct cind_args { 113 bt_bdaddr_t remote_addr; 114 esp_hf_call_status_t call_state; 115 esp_hf_call_setup_status_t call_setup_state; 116 esp_hf_network_state_t ntk_state; 117 int signal; 118 esp_hf_roaming_status_t roam; 119 int batt_lev; 120 esp_hf_call_held_status_t call_held_state; 121 } cind_rep; 122 123 //BTC_HF_COPS_RESPONSE_EVT 124 struct cops_args { 125 bt_bdaddr_t remote_addr; 126 char *name; 127 } cops_rep; 128 129 // BTC_HF_CLCC_RESPONSE_EVT 130 struct clcc_args { 131 bt_bdaddr_t remote_addr; 132 int index; 133 esp_hf_current_call_direction_t dir; 134 esp_hf_current_call_status_t current_call_state; 135 esp_hf_current_call_mode_t mode; 136 esp_hf_current_call_mpty_type_t mpty; 137 char *number; 138 esp_hf_call_addr_type_t type; 139 } clcc_rep; 140 141 // BTC_HF_CNUM_RESPONSE_EVT 142 struct cnum_args { 143 bt_bdaddr_t remote_addr; 144 char *number; 145 esp_hf_subscriber_service_type_t type; 146 } cnum_rep; 147 148 //BTC_HF_NREC_RESPONSE_EVT 149 bt_bdaddr_t nrec_rep; 150 151 //BTC_HF_VTC_RESPONSE_EVT 152 struct bts_args { 153 bt_bdaddr_t remote_addr; 154 char *code; 155 } vts_rep; 156 157 //BTC_HF_INBAND_RING_EVT 158 struct bsir_args { 159 bt_bdaddr_t remote_addr; 160 esp_hf_in_band_ring_state_t state; 161 } bsir; 162 163 // BTC_HF_AC_INCALL_EVT 164 // BTC_HF_RJ_INCALL_EVT 165 // BTC_HF_OUT_CALL_EVT 166 // BTC_HF_END_CALL_EVT 167 struct phone_args { 168 bt_bdaddr_t remote_addr; 169 int num_active; 170 int num_held; 171 esp_hf_call_status_t call_state; 172 esp_hf_call_setup_status_t call_setup_state; 173 char *number; 174 esp_hf_call_addr_type_t call_addr_type; 175 } phone; 176 177 // BTC_HF_REGISTER_DATA_CALLBACK_EVT 178 struct reg_data_callback { 179 esp_hf_incoming_data_cb_t recv; 180 esp_hf_outgoing_data_cb_t send; 181 } reg_data_cb; 182 183 } btc_hf_args_t; 184 185 /************************************************************************************ 186 ** Local definitions 187 ************************************************************************************/ 188 /* Number of BTC-HF-AG control blocks */ 189 #define BTC_HF_NUM_CB 1 190 191 /* Handsfree AG app ids for service registration */ 192 /* APP ID definition*/ 193 #define BTC_HF_ID_1 0 194 195 /* BTC-AG control block to map bdaddr to BTA handle */ 196 typedef struct 197 { 198 bool initialized; 199 UINT16 handle; 200 bt_bdaddr_t connected_bda; 201 tBTA_AG_PEER_FEAT peer_feat; 202 tBTA_AG_CHLD_FEAT chld_feat; 203 struct timespec call_end_timestamp; 204 struct timespec connected_timestamp; 205 esp_hf_connection_state_t connection_state; 206 esp_hf_vr_state_t vr_state; 207 int num_active; 208 int num_held; 209 esp_hf_call_status_t call_state; 210 esp_hf_call_setup_status_t call_setup_state; 211 } btc_hf_cb_t; 212 213 typedef struct 214 { 215 int hf_idx; 216 UINT32 btc_hf_features; 217 btc_hf_cb_t btc_hf_cb; 218 esp_hf_incoming_data_cb_t btc_hf_incoming_data_cb; 219 esp_hf_outgoing_data_cb_t btc_hf_outgoing_data_cb; 220 } hf_local_param_t; 221 222 /******************************************************************************* 223 ** BTC HF AG Handle Hub 224 ********************************************************************************/ 225 void btc_hf_call_handler(btc_msg_t *msg); // act the cmd from esp-application 226 227 void btc_hf_cb_handler(btc_msg_t *msg); //handle the event from bta 228 229 void btc_hf_incoming_data_cb_to_app(const uint8_t *data, uint32_t len); 230 231 uint32_t btc_hf_outgoing_data_cb_to_app(uint8_t *data, uint32_t len); 232 233 void btc_hf_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); 234 235 void btc_hf_arg_deep_free(btc_msg_t *msg); 236 237 bt_status_t btc_hf_ci_sco_data(void); 238 239 #endif // BTC_HF_INCLUDED == TRUE 240 241 #endif /* __BTC_HF_AG_H__ */ 242