1 // Copyright 2018 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /******************************************************************************* 16 * 17 * Filename: btc_hf_ag.h 18 * 19 * Description: Main API header file for all BTC HF AG functions accessed 20 * from internal stack. 21 * 22 *******************************************************************************/ 23 24 #ifndef __BTC_HF_AG_H__ 25 #define __BTC_HF_AG_H__ 26 27 #include "common/bt_target.h" 28 #include "btc/btc_task.h" 29 #include "btc/btc_common.h" 30 #include "bta/bta_ag_api.h" 31 #include "esp_hf_ag_api.h" 32 33 34 #if (BTC_HF_INCLUDED == TRUE) 35 36 /******************************************************************************* 37 ** Type Defs 38 ********************************************************************************/ 39 /* btc_hf_act_t */ 40 typedef enum 41 { 42 //INIT 43 BTC_HF_INIT_EVT, 44 BTC_HF_DEINIT_EVT, 45 BTC_HF_CONNECT_EVT, 46 BTC_HF_DISCONNECT_EVT, 47 BTC_HF_CONNECT_AUDIO_EVT, 48 BTC_HF_DISCONNECT_AUDIO_EVT, 49 BTC_HF_VRA_EVT, 50 BTC_HF_VOLUME_CONTROL_EVT, 51 //AT_RESPONSE 52 BTC_HF_UNAT_RESPONSE_EVT, 53 BTC_HF_CME_ERR_EVT, 54 BTC_HF_IND_NOTIFICATION_EVT, 55 BTC_HF_CIND_RESPONSE_EVT, 56 BTC_HF_COPS_RESPONSE_EVT, 57 BTC_HF_CLCC_RESPONSE_EVT, 58 BTC_HF_CNUM_RESPONSE_EVT, 59 BTC_HF_INBAND_RING_EVT, 60 //CALL_HANDLE 61 BTC_HF_AC_INCALL_EVT, 62 BTC_HF_RJ_INCALL_EVT, 63 BTC_HF_OUT_CALL_EVT, 64 BTC_HF_END_CALL_EVT, 65 //REG 66 BTC_HF_REGISTER_DATA_CALLBACK_EVT 67 } btc_hf_act_t; 68 69 /* btc_hf_args_t */ 70 typedef union 71 { 72 // BTC_HF_INIT_EVT 73 bt_bdaddr_t init; 74 75 //BTC_HF_DEINIT_EVT 76 bt_bdaddr_t deinit; 77 78 // BTC_HF_CONNECT_EVT 79 bt_bdaddr_t connect; 80 81 // BTC_HF_DISCONNECT_EVT 82 bt_bdaddr_t disconnect; 83 84 // BTC_HF_CONNECT_AUDIO_EVT 85 bt_bdaddr_t connect_audio; 86 87 // BTC_HF_DISCONNECT_AUDIO_EVT 88 bt_bdaddr_t disconnect_audio; 89 90 //BTC_HF_VRA_EVT 91 struct vra_param { 92 bt_bdaddr_t remote_addr; 93 esp_hf_vr_state_t value; 94 } vra_rep; 95 96 // BTC_HF_VOLUME_CONTROL_EVT 97 struct volcon_args { 98 bt_bdaddr_t remote_addr; 99 esp_hf_volume_control_target_t target_type; 100 int volume; 101 } volcon; 102 103 //BTC_HF_UNAT_RESPONSE_EVT 104 struct unat_param { 105 bt_bdaddr_t remote_addr; 106 char *unat; 107 } unat_rep; 108 109 //BTC_HF_CME_ERR_EVT 110 struct at_ok_err_args { 111 bt_bdaddr_t remote_addr; 112 esp_hf_at_response_code_t response_code; 113 esp_hf_cme_err_t error_code; 114 } ext_at; 115 116 // BTC_HF_IND_NOTIFICATION_EVT 117 struct indchange_status { 118 bt_bdaddr_t remote_addr; 119 esp_hf_call_status_t call_state; 120 esp_hf_call_setup_status_t call_setup_state; 121 esp_hf_network_state_t ntk_state; 122 int signal; 123 } ind_change; 124 125 //BTC_HF_CIND_RESPONSE_EVT 126 struct cind_args { 127 bt_bdaddr_t remote_addr; 128 esp_hf_call_status_t call_state; 129 esp_hf_call_setup_status_t call_setup_state; 130 esp_hf_network_state_t ntk_state; 131 int signal; 132 esp_hf_roaming_status_t roam; 133 int batt_lev; 134 esp_hf_call_held_status_t call_held_state; 135 } cind_rep; 136 137 //BTC_HF_COPS_RESPONSE_EVT 138 struct cops_args { 139 bt_bdaddr_t remote_addr; 140 char *name; 141 } cops_rep; 142 143 // BTC_HF_CLCC_RESPONSE_EVT 144 struct clcc_args { 145 bt_bdaddr_t remote_addr; 146 int index; 147 esp_hf_current_call_direction_t dir; 148 esp_hf_current_call_status_t current_call_state; 149 esp_hf_current_call_mode_t mode; 150 esp_hf_current_call_mpty_type_t mpty; 151 char *number; 152 esp_hf_call_addr_type_t type; 153 } clcc_rep; 154 155 // BTC_HF_CNUM_RESPONSE_EVT 156 struct cnum_args { 157 bt_bdaddr_t remote_addr; 158 char *number; 159 esp_hf_subscriber_service_type_t type; 160 } cnum_rep; 161 162 //BTC_HF_NREC_RESPONSE_EVT 163 bt_bdaddr_t nrec_rep; 164 165 //BTC_HF_VTC_RESPONSE_EVT 166 struct bts_args { 167 bt_bdaddr_t remote_addr; 168 char *code; 169 } vts_rep; 170 171 //BTC_HF_INBAND_RING_EVT 172 struct bsir_args { 173 bt_bdaddr_t remote_addr; 174 esp_hf_in_band_ring_state_t state; 175 } bsir; 176 177 // BTC_HF_AC_INCALL_EVT 178 // BTC_HF_RJ_INCALL_EVT 179 // BTC_HF_OUT_CALL_EVT 180 // BTC_HF_END_CALL_EVT 181 struct phone_args { 182 bt_bdaddr_t remote_addr; 183 int num_active; 184 int num_held; 185 esp_hf_call_status_t call_state; 186 esp_hf_call_setup_status_t call_setup_state; 187 char *number; 188 esp_hf_call_addr_type_t call_addr_type; 189 } phone; 190 191 // BTC_HF_REGISTER_DATA_CALLBACK_EVT 192 struct reg_data_callback { 193 esp_hf_incoming_data_cb_t recv; 194 esp_hf_outgoing_data_cb_t send; 195 } reg_data_cb; 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 /******************************************************************************* 237 ** BTC HF AG Handle Hub 238 ********************************************************************************/ 239 void btc_hf_call_handler(btc_msg_t *msg); // act the cmd from esp-application 240 241 void btc_hf_cb_handler(btc_msg_t *msg); //handle the event from bta 242 243 void btc_hf_incoming_data_cb_to_app(const uint8_t *data, uint32_t len); 244 245 uint32_t btc_hf_outgoing_data_cb_to_app(uint8_t *data, uint32_t len); 246 247 void btc_hf_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); 248 249 void btc_hf_arg_deep_free(btc_msg_t *msg); 250 251 bt_status_t btc_hf_ci_sco_data(void); 252 253 #endif // BTC_HF_INCLUDED == TRUE 254 255 #endif /* __BTC_HF_AG_H__ */ 256