1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __BTC_GATTC_H__ 8 #define __BTC_GATTC_H__ 9 10 #include "btc/btc_task.h" 11 #include "esp_bt_defs.h" 12 #include "esp_gatt_defs.h" 13 #include "esp_gattc_api.h" 14 15 typedef enum { 16 BTC_GATTC_ACT_APP_REGISTER = 0, 17 BTC_GATTC_ACT_APP_UNREGISTER, 18 BTC_GATTC_ACT_OPEN, 19 #if (BLE_50_FEATURE_SUPPORT == TRUE) 20 BTC_GATTC_ACT_AUX_OPEN, 21 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) 22 BTC_GATTC_ACT_CLOSE, 23 BTC_GATTC_ACT_CFG_MTU, 24 BTC_GATTC_ACT_SEARCH_SERVICE, 25 BTC_GATTC_ACT_READ_CHAR, 26 BTC_GATTC_ACT_READ_MULTIPLE_CHAR, 27 BTC_GATTC_ACT_READ_MULTIPLE_VARIABLE_CHAR, 28 BTC_GATTC_ACT_READ_CHAR_DESCR, 29 BTC_GATTC_ACT_READ_BY_TYPE, 30 BTC_GATTC_ACT_WRITE_CHAR, 31 BTC_GATTC_ACT_WRITE_CHAR_DESCR, 32 BTC_GATTC_ACT_PREPARE_WRITE, 33 BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR, 34 BTC_GATTC_ACT_EXECUTE_WRITE, 35 BTC_GATTC_ACT_REG_FOR_NOTIFY, 36 BTC_GATTC_ACT_UNREG_FOR_NOTIFY, 37 BTC_GATTC_ACT_CACHE_REFRESH, 38 BTC_GATTC_ACT_CACHE_ASSOC, 39 BTC_GATTC_ATC_CACHE_GET_ADDR_LIST, 40 BTC_GATTC_ACT_CACHE_CLEAN, 41 } btc_gattc_act_t; 42 43 /* btc_ble_gattc_args_t */ 44 typedef union { 45 //BTC_GATTC_ACT_APP_REGISTER, 46 struct app_reg_arg { 47 uint16_t app_id; 48 } app_reg; 49 //BTC_GATTC_ACT_APP_UNREGISTER, 50 struct app_unreg_arg { 51 esp_gatt_if_t gattc_if; 52 } app_unreg; 53 //BTC_GATTC_ACT_OPEN, 54 struct open_arg { 55 esp_gatt_if_t gattc_if; 56 esp_bd_addr_t remote_bda; 57 esp_ble_addr_type_t remote_addr_type; 58 bool is_direct; 59 bool is_aux; 60 esp_ble_addr_type_t own_addr_type; 61 esp_ble_phy_mask_t phy_mask; 62 esp_ble_conn_params_t phy_1m_conn_params; 63 esp_ble_conn_params_t phy_2m_conn_params; 64 esp_ble_conn_params_t phy_coded_conn_params; 65 } open; 66 //BTC_GATTC_ACT_CLOSE, 67 struct close_arg { 68 uint16_t conn_id; 69 } close; 70 //BTC_GATTC_ACT_CFG_MTU, 71 struct cfg_mtu_arg { 72 uint16_t conn_id; 73 } cfg_mtu; 74 //BTC_GATTC_ACT_SEARCH_SERVICE, 75 struct search_srvc_arg { 76 uint16_t conn_id; 77 bool filter_uuid_enable; 78 esp_bt_uuid_t filter_uuid; 79 } search_srvc; 80 //BTC_GATTC_ACT_GET_CHAR, 81 struct get_char_arg { 82 uint16_t conn_id; 83 uint16_t handle; 84 } get_char; 85 //BTC_GATTC_ACT_GET_DESCR, 86 struct get_descr_arg { 87 uint16_t conn_id; 88 uint16_t handle; 89 } get_descr; 90 //BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE, 91 struct get_first_incl_srvc_arg { 92 uint16_t conn_id; 93 uint16_t handle; 94 } get_first_incl_srvc; 95 //BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE, 96 struct get_next_incl_srvc_arg { 97 uint16_t conn_id; 98 uint16_t handle; 99 } get_next_incl_srvc; 100 //BTC_GATTC_ACT_READ_CHAR, 101 struct read_char_arg { 102 uint16_t conn_id; 103 uint16_t handle; 104 esp_gatt_auth_req_t auth_req; 105 } read_char; 106 //BTC_GATTC_ACT_READ_MULTIPLE_CHAR 107 struct read_multiple_arg { 108 uint16_t conn_id; 109 uint8_t num_attr; 110 uint16_t handles[ESP_GATT_MAX_READ_MULTI_HANDLES]; 111 esp_gatt_auth_req_t auth_req; 112 } read_multiple; 113 //BTC_GATTC_ACT_READ_CHAR_DESCR, 114 struct read_descr_arg { 115 uint16_t conn_id; 116 uint16_t handle; 117 esp_gatt_auth_req_t auth_req; 118 } read_descr; 119 // BTC_GATTC_ACT_READ_BY_TYPE 120 struct read_by_type_arg { 121 uint16_t conn_id; 122 uint16_t s_handle; 123 uint16_t e_handle; 124 esp_bt_uuid_t uuid; 125 esp_gatt_auth_req_t auth_req; 126 } read_by_type; 127 //BTC_GATTC_ACT_WRITE_CHAR, 128 struct write_char_arg { 129 uint16_t conn_id; 130 uint16_t value_len; 131 uint16_t handle; 132 uint8_t *value; 133 esp_gatt_write_type_t write_type; 134 esp_gatt_auth_req_t auth_req; 135 } write_char; 136 //BTC_GATTC_ACT_WRITE_CHAR_DESCR, 137 struct write_descr_arg { 138 uint16_t conn_id; 139 uint16_t value_len; 140 uint16_t handle; 141 uint8_t *value; 142 esp_gatt_write_type_t write_type; 143 esp_gatt_auth_req_t auth_req; 144 } write_descr; 145 //BTC_GATTC_ACT_PREPARE_WRITE, 146 struct prep_write_arg { 147 uint16_t conn_id; 148 uint16_t handle; 149 uint16_t offset; 150 uint16_t value_len; 151 uint8_t *value; 152 esp_gatt_auth_req_t auth_req; 153 } prep_write; 154 //BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR, 155 struct prep_write_descr_arg { 156 uint16_t conn_id; 157 uint16_t handle; 158 uint16_t offset; 159 uint16_t value_len; 160 uint8_t *value; 161 esp_gatt_auth_req_t auth_req; 162 } prep_write_descr; 163 //BTC_GATTC_ACT_EXECUTE_WRITE, 164 struct exec_write_arg { 165 uint16_t conn_id; 166 bool is_execute; 167 } exec_write; 168 //BTC_GATTC_ACT_REG_FOR_NOTIFY, 169 struct reg_for_notify_arg { 170 esp_gatt_if_t gattc_if; 171 esp_bd_addr_t remote_bda; 172 uint16_t handle; 173 } reg_for_notify; 174 //BTC_GATTC_ACT_UNREG_FOR_NOTIFY 175 struct unreg_for_notify_arg { 176 esp_gatt_if_t gattc_if; 177 esp_bd_addr_t remote_bda; 178 uint16_t handle; 179 } unreg_for_notify; 180 //BTC_GATTC_ACT_CACHE_REFRESH, 181 struct cache_refresh_arg { 182 esp_bd_addr_t remote_bda; 183 } cache_refresh; 184 //BTC_GATTC_ACT_CACHE_ASSOC 185 struct cache_assoc_arg { 186 esp_gatt_if_t gattc_if; 187 esp_bd_addr_t src_addr; 188 esp_bd_addr_t assoc_addr; 189 bool is_assoc; 190 } cache_assoc; 191 //BTC_GATTC_ATC_CACHE_GET_ADDR_LIST 192 struct cache_get_addr_list_arg { 193 esp_gatt_if_t gattc_if; 194 }get_addr_list; 195 //BTC_GATTC_ACT_CACHE_CLEAN, 196 struct cache_clean_arg { 197 esp_bd_addr_t remote_bda; 198 } cache_clean; 199 } btc_ble_gattc_args_t; 200 201 void btc_gattc_call_handler(btc_msg_t *msg); 202 void btc_gattc_cb_handler(btc_msg_t *msg); 203 void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); 204 void btc_gattc_arg_deep_free(btc_msg_t *msg); 205 esp_gatt_status_t btc_ble_gattc_get_service(uint16_t conn_id, esp_bt_uuid_t *svc_uuid, 206 esp_gattc_service_elem_t *result, 207 uint16_t *count, uint16_t offset); 208 esp_gatt_status_t btc_ble_gattc_get_all_char(uint16_t conn_id, 209 uint16_t start_handle, 210 uint16_t end_handle, 211 esp_gattc_char_elem_t *result, 212 uint16_t *count, uint16_t offset); 213 esp_gatt_status_t btc_ble_gattc_get_all_descr(uint16_t conn_id, 214 uint16_t char_handle, 215 esp_gattc_descr_elem_t *result, 216 uint16_t *count, uint16_t offset); 217 esp_gatt_status_t btc_ble_gattc_get_char_by_uuid(uint16_t conn_id, 218 uint16_t start_handle, 219 uint16_t end_handle, 220 esp_bt_uuid_t char_uuid, 221 esp_gattc_char_elem_t *result, 222 uint16_t *count); 223 esp_gatt_status_t btc_ble_gattc_get_descr_by_uuid(uint16_t conn_id, 224 uint16_t start_handle, 225 uint16_t end_handle, 226 esp_bt_uuid_t char_uuid, 227 esp_bt_uuid_t descr_uuid, 228 esp_gattc_descr_elem_t *result, 229 uint16_t *count); 230 231 esp_gatt_status_t btc_ble_gattc_get_descr_by_char_handle(uint16_t conn_id, 232 uint16_t char_handle, 233 esp_bt_uuid_t descr_uuid, 234 esp_gattc_descr_elem_t *result, 235 uint16_t *count); 236 237 esp_gatt_status_t btc_ble_gattc_get_include_service(uint16_t conn_id, 238 uint16_t start_handle, 239 uint16_t end_handle, 240 esp_bt_uuid_t *incl_uuid, 241 esp_gattc_incl_svc_elem_t *result, 242 uint16_t *count); 243 244 esp_gatt_status_t btc_ble_gattc_get_attr_count(uint16_t conn_id, 245 esp_gatt_db_attr_type_t type, 246 uint16_t start_handle, 247 uint16_t end_handle, 248 uint16_t char_handle, 249 uint16_t *count); 250 251 esp_gatt_status_t btc_ble_gattc_get_db(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, 252 esp_gattc_db_elem_t *db, uint16_t *count); 253 254 255 256 257 #endif /* __BTC_GATTC_H__ */ 258