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