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