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 #include <string.h>
16
17 #include "stack/btm_ble_api.h"
18 #include "btc_gattc.h"
19 #include "btc_gatt_util.h"
20 #include "btc/btc_manage.h"
21 #include "bta/bta_gatt_api.h"
22 #include "common/bt_trace.h"
23 #include "osi/allocator.h"
24 #include "esp_gattc_api.h"
25
26 #if (GATTC_INCLUDED == TRUE)
btc_gattc_cb_to_app(esp_gattc_cb_event_t event,esp_gatt_if_t gattc_if,esp_ble_gattc_cb_param_t * param)27 static inline void btc_gattc_cb_to_app(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
28 {
29 esp_gattc_cb_t btc_gattc_cb = (esp_gattc_cb_t )btc_profile_cb_get(BTC_PID_GATTC);
30 if (btc_gattc_cb) {
31 btc_gattc_cb(event, gattc_if, param);
32 }
33 }
34
btc_gattc_arg_deep_copy(btc_msg_t * msg,void * p_dest,void * p_src)35 void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
36 {
37 btc_ble_gattc_args_t *dst = (btc_ble_gattc_args_t *) p_dest;
38 btc_ble_gattc_args_t *src = (btc_ble_gattc_args_t *)p_src;
39
40 switch (msg->act) {
41 case BTC_GATTC_ACT_WRITE_CHAR: {
42 dst->write_char.value = (uint8_t *)osi_malloc(src->write_char.value_len);
43 if (dst->write_char.value) {
44 memcpy(dst->write_char.value, src->write_char.value, src->write_char.value_len);
45 } else {
46 BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act);
47 }
48 break;
49 }
50 case BTC_GATTC_ACT_WRITE_CHAR_DESCR: {
51 dst->write_descr.value = (uint8_t *)osi_malloc(src->write_descr.value_len);
52 if (dst->write_descr.value) {
53 memcpy(dst->write_descr.value, src->write_descr.value, src->write_descr.value_len);
54 } else {
55 BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act);
56 }
57 break;
58 }
59 case BTC_GATTC_ACT_PREPARE_WRITE: {
60 dst->prep_write.value = (uint8_t *)osi_malloc(src->prep_write.value_len);
61 if (dst->prep_write.value) {
62 memcpy(dst->prep_write.value, src->prep_write.value, src->prep_write.value_len);
63 } else {
64 BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act);
65 }
66 break;
67 }
68 case BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR: {
69 dst->prep_write_descr.value = (uint8_t *)osi_malloc(src->prep_write_descr.value_len);
70 if (dst->prep_write_descr.value) {
71 memcpy(dst->prep_write_descr.value, src->prep_write_descr.value, src->prep_write_descr.value_len);
72 } else {
73 BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act);
74 }
75 break;
76 }
77 default:
78 BTC_TRACE_DEBUG("%s Unhandled deep copy %d\n", __func__, msg->act);
79 break;
80 }
81 }
82
btc_gattc_arg_deep_free(btc_msg_t * msg)83 void btc_gattc_arg_deep_free(btc_msg_t *msg)
84 {
85 btc_ble_gattc_args_t *arg = (btc_ble_gattc_args_t *)msg->arg;
86
87 switch (msg->act) {
88 case BTC_GATTC_ACT_WRITE_CHAR: {
89 if (arg->write_char.value) {
90 osi_free(arg->write_char.value);
91 }
92 break;
93 }
94 case BTC_GATTC_ACT_WRITE_CHAR_DESCR: {
95 if (arg->write_descr.value) {
96 osi_free(arg->write_descr.value);
97 }
98 break;
99 }
100 case BTC_GATTC_ACT_PREPARE_WRITE: {
101 if (arg->prep_write.value) {
102 osi_free(arg->prep_write.value);
103 }
104 break;
105 }
106 case BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR: {
107 if (arg->prep_write_descr.value) {
108 osi_free(arg->prep_write_descr.value);
109 }
110 break;
111 }
112 default:
113 BTC_TRACE_DEBUG("%s Unhandled deep free %d\n", __func__, msg->act);
114 break;
115 }
116
117 }
118
btc_gattc_copy_req_data(btc_msg_t * msg,void * p_dest,void * p_src)119 static void btc_gattc_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
120 {
121 tBTA_GATTC *p_dest_data = (tBTA_GATTC *) p_dest;
122 tBTA_GATTC *p_src_data = (tBTA_GATTC *) p_src;
123
124 if (!p_src_data || !p_dest_data) {
125 return;
126 }
127
128 // Allocate buffer for request data if necessary
129 switch (msg->act) {
130 case BTA_GATTC_READ_DESCR_EVT:
131 case BTA_GATTC_READ_CHAR_EVT:
132 case BTA_GATTC_READ_MULTIPLE_EVT: {
133 if (p_src_data->read.p_value && p_src_data->read.p_value->p_value) {
134 p_dest_data->read.p_value = (tBTA_GATT_UNFMT *)osi_malloc(sizeof(tBTA_GATT_UNFMT) + p_src_data->read.p_value->len);
135 p_dest_data->read.p_value->p_value = (uint8_t *)(p_dest_data->read.p_value + 1);
136 if (p_dest_data->read.p_value && p_dest_data->read.p_value->p_value) {
137 p_dest_data->read.p_value->len = p_src_data->read.p_value->len;
138 memcpy(p_dest_data->read.p_value->p_value, p_src_data->read.p_value->p_value, p_src_data->read.p_value->len);
139 } else {
140 BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act);
141 }
142 }
143 break;
144 }
145 case BTA_GATTC_GET_ADDR_LIST_EVT: {
146 if (p_src_data->get_addr_list.bda_list != NULL) {
147 uint8_t num_addr = p_src_data->get_addr_list.num_addr;
148 p_dest_data->get_addr_list.bda_list = (BD_ADDR *)osi_malloc(sizeof(BD_ADDR) * num_addr);
149 if (p_dest_data->get_addr_list.bda_list) {
150 memcpy(p_dest_data->get_addr_list.bda_list, p_src_data->get_addr_list.bda_list, sizeof(BD_ADDR) * num_addr);
151 } else {
152 BTC_TRACE_ERROR("%s %d no mem\n", __func__, msg->act);
153 }
154 }
155 break;
156 }
157 default:
158 break;
159 }
160 }
161
btc_gattc_free_req_data(btc_msg_t * msg)162 static void btc_gattc_free_req_data(btc_msg_t *msg)
163 {
164 tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg);
165 switch (msg->act) {
166 case BTA_GATTC_READ_DESCR_EVT:
167 case BTA_GATTC_READ_CHAR_EVT:
168 case BTA_GATTC_READ_MULTIPLE_EVT: {
169 if (arg->read.p_value) {
170 osi_free(arg->read.p_value);
171 }
172 break;
173 }
174 case BTA_GATTC_GET_ADDR_LIST_EVT: {
175 if (arg->get_addr_list.bda_list) {
176 osi_free(arg->get_addr_list.bda_list);
177 }
178 break;
179 }
180 default:
181 break;
182 }
183 return;
184 }
185
btc_gattc_cback(tBTA_GATTC_EVT event,tBTA_GATTC * p_data)186 static void btc_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
187 {
188 bt_status_t ret;
189 btc_msg_t msg;
190
191 msg.sig = BTC_SIG_API_CB;
192 msg.pid = BTC_PID_GATTC;
193 msg.act = (uint8_t) event;
194 ret = btc_transfer_context(&msg, p_data, sizeof(tBTA_GATTC), btc_gattc_copy_req_data);
195
196 if (ret) {
197 BTC_TRACE_ERROR("%s transfer failed\n", __func__);
198 }
199 }
200
btc_gattc_app_register(btc_ble_gattc_args_t * arg)201 static void btc_gattc_app_register(btc_ble_gattc_args_t *arg)
202 {
203 tBT_UUID app_uuid;
204 app_uuid.len = 2;
205 app_uuid.uu.uuid16 = arg->app_reg.app_id;
206 BTA_GATTC_AppRegister(&app_uuid, btc_gattc_cback);
207 }
208
btc_gattc_app_unregister(btc_ble_gattc_args_t * arg)209 static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg)
210 {
211 BTA_GATTC_AppDeregister(arg->app_unreg.gattc_if);
212 }
213
btc_gattc_open(btc_ble_gattc_args_t * arg)214 static void btc_gattc_open(btc_ble_gattc_args_t *arg)
215 {
216 tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
217 BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda,
218 arg->open.remote_addr_type, arg->open.is_direct,
219 transport, arg->open.is_aux);
220 }
221
btc_gattc_close(btc_ble_gattc_args_t * arg)222 static void btc_gattc_close(btc_ble_gattc_args_t *arg)
223 {
224 // TODO; Review this call of BTA_API, check the usage of BTA_GATTC_CancelOpen
225 BTA_GATTC_Close(arg->close.conn_id);
226 }
227
btc_gattc_cfg_mtu(btc_ble_gattc_args_t * arg)228 static void btc_gattc_cfg_mtu(btc_ble_gattc_args_t *arg)
229 {
230 BTA_GATTC_ConfigureMTU (arg->cfg_mtu.conn_id);
231 }
232
btc_gattc_check_valid_param(int num,uint16_t offset)233 static esp_gatt_status_t btc_gattc_check_valid_param(int num, uint16_t offset)
234 {
235 if (num == 0) {
236 return ESP_GATT_NOT_FOUND;
237 } else if (offset >= num) {
238 return ESP_GATT_INVALID_OFFSET;
239 }
240
241 return ESP_GATT_OK;
242 }
243
btc_gattc_fill_gatt_db_conversion(uint16_t count,uint16_t num,esp_gatt_db_attr_type_t type,uint16_t offset,void * result,btgatt_db_element_t * db)244 static void btc_gattc_fill_gatt_db_conversion(uint16_t count, uint16_t num, esp_gatt_db_attr_type_t type,
245 uint16_t offset, void *result, btgatt_db_element_t *db)
246 {
247 tBT_UUID bta_uuid = {0};
248 uint16_t db_size = (count + offset > num) ? (num - offset) : count;
249 switch(type) {
250 case ESP_GATT_DB_PRIMARY_SERVICE:
251 case ESP_GATT_DB_SECONDARY_SERVICE: {
252 esp_gattc_service_elem_t *svc_result = (esp_gattc_service_elem_t *)result;
253 for (int i = 0; i < db_size; i++) {
254 svc_result->is_primary = (db[offset + i].type == BTGATT_DB_PRIMARY_SERVICE) ? true : false;
255 svc_result->start_handle = db[offset + i].start_handle;
256 svc_result->end_handle = db[offset + i].end_handle;
257 btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
258 bta_to_btc_uuid(&svc_result->uuid, &bta_uuid);
259 svc_result++;
260 }
261 break;
262 }
263 case ESP_GATT_DB_CHARACTERISTIC: {
264 esp_gattc_char_elem_t *char_result = (esp_gattc_char_elem_t *)result;
265 for (int i = 0; i < db_size; i++) {
266 char_result->char_handle = db[offset + i].attribute_handle;
267 char_result->properties = db[offset + i].properties;
268 btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
269 bta_to_btc_uuid(&char_result->uuid, &bta_uuid);
270 char_result++;
271 }
272 break;
273 }
274 case ESP_GATT_DB_DESCRIPTOR: {
275 esp_gattc_descr_elem_t *descr_result = (esp_gattc_descr_elem_t *)result;
276 for (int i = 0; i < db_size; i++) {
277 descr_result->handle = db[offset + i].attribute_handle;
278 btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
279 bta_to_btc_uuid(&descr_result->uuid, &bta_uuid);
280 descr_result++;
281 }
282 break;
283 }
284 case ESP_GATT_DB_INCLUDED_SERVICE: {
285 esp_gattc_incl_svc_elem_t *incl_result = (esp_gattc_incl_svc_elem_t *)result;
286 for (int i = 0; i < db_size; i++) {
287 incl_result->handle = db[offset + i].attribute_handle;
288 incl_result->incl_srvc_s_handle = db[offset + i].start_handle;
289 incl_result->incl_srvc_e_handle = db[offset + i].end_handle;
290 btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
291 bta_to_btc_uuid(&incl_result->uuid, &bta_uuid);
292 incl_result++;
293 }
294 break;
295 }
296 default:
297 BTC_TRACE_WARNING("%s(), Not support type(%d)", __func__, type);
298 break;
299 }
300 }
301
btc_gattc_search_service(btc_ble_gattc_args_t * arg)302 static void btc_gattc_search_service(btc_ble_gattc_args_t *arg)
303 {
304 tBT_UUID srvc_uuid;
305
306 if (arg->search_srvc.filter_uuid_enable) {
307 btc_to_bta_uuid(&srvc_uuid, &arg->search_srvc.filter_uuid);
308 BTA_GATTC_ServiceSearchRequest(arg->search_srvc.conn_id, &srvc_uuid);
309 } else {
310 BTA_GATTC_ServiceSearchRequest(arg->search_srvc.conn_id, NULL);
311 }
312 }
313
btc_ble_gattc_get_service(uint16_t conn_id,esp_bt_uuid_t * svc_uuid,esp_gattc_service_elem_t * result,uint16_t * count,uint16_t offset)314 esp_gatt_status_t btc_ble_gattc_get_service(uint16_t conn_id, esp_bt_uuid_t *svc_uuid,
315 esp_gattc_service_elem_t *result,
316 uint16_t *count, uint16_t offset)
317 {
318 esp_gatt_status_t status;
319 btgatt_db_element_t *db = NULL;
320 uint16_t svc_num = 0;
321 tBT_UUID *bta_uuid = NULL;
322 if (svc_uuid) {
323 bta_uuid = osi_malloc(sizeof(tBT_UUID));
324 btc_to_bta_uuid(bta_uuid, svc_uuid);
325 }
326
327 BTA_GATTC_GetServiceWithUUID(conn_id, bta_uuid, &db, &svc_num);
328
329 if ((status = btc_gattc_check_valid_param((int)svc_num, offset)) != ESP_GATT_OK) {
330 if (db) {
331 osi_free(db);
332 }
333 if (bta_uuid) {
334 osi_free(bta_uuid);
335 }
336 *count = 0;
337 return status;
338 } else {
339 btc_gattc_fill_gatt_db_conversion(*count, svc_num, ESP_GATT_DB_PRIMARY_SERVICE, offset, (void *)result, db);
340 }
341
342 *count = svc_num;
343 //don't forget to free the db buffer after used.
344 if (db) {
345 osi_free(db);
346 }
347 if (bta_uuid) {
348 osi_free(bta_uuid);
349 }
350 return ESP_GATT_OK;
351 }
352
btc_ble_gattc_get_all_char(uint16_t conn_id,uint16_t start_handle,uint16_t end_handle,esp_gattc_char_elem_t * result,uint16_t * count,uint16_t offset)353 esp_gatt_status_t btc_ble_gattc_get_all_char(uint16_t conn_id,
354 uint16_t start_handle,
355 uint16_t end_handle,
356 esp_gattc_char_elem_t *result,
357 uint16_t *count, uint16_t offset)
358 {
359 esp_gatt_status_t status;
360 btgatt_db_element_t *db = NULL;
361 uint16_t char_num = 0;
362 BTA_GATTC_GetAllChar(conn_id, start_handle, end_handle, &db, &char_num);
363
364 if ((status = btc_gattc_check_valid_param((int)char_num, offset)) != ESP_GATT_OK) {
365 if (db) {
366 osi_free(db);
367 }
368 *count = 0;
369 return status;
370 } else {
371 btc_gattc_fill_gatt_db_conversion(*count, char_num, ESP_GATT_DB_CHARACTERISTIC, offset, (void *)result, db);
372 }
373
374 *count = char_num;
375 //don't forget to free the db buffer after used.
376 if (db) {
377 osi_free(db);
378 }
379 return ESP_GATT_OK;
380 }
381
btc_ble_gattc_get_all_descr(uint16_t conn_id,uint16_t char_handle,esp_gattc_descr_elem_t * result,uint16_t * count,uint16_t offset)382 esp_gatt_status_t btc_ble_gattc_get_all_descr(uint16_t conn_id,
383 uint16_t char_handle,
384 esp_gattc_descr_elem_t *result,
385 uint16_t *count, uint16_t offset)
386 {
387 esp_gatt_status_t status;
388 btgatt_db_element_t *db = NULL;
389 uint16_t descr_num = 0;
390 BTA_GATTC_GetAllDescriptor(conn_id, char_handle, &db, &descr_num);
391
392 if ((status = btc_gattc_check_valid_param((int)descr_num, offset)) != ESP_GATT_OK) {
393 if (db) {
394 osi_free(db);
395 }
396 *count = 0;
397 return status;
398 } else {
399 btc_gattc_fill_gatt_db_conversion(*count, descr_num, ESP_GATT_DB_DESCRIPTOR, offset, (void *)result, db);
400 }
401
402 *count = descr_num;
403 //don't forget to free the db buffer after used.
404 if (db) {
405 osi_free(db);
406 }
407 return ESP_GATT_OK;
408 }
409
btc_ble_gattc_get_char_by_uuid(uint16_t conn_id,uint16_t start_handle,uint16_t end_handle,esp_bt_uuid_t char_uuid,esp_gattc_char_elem_t * result,uint16_t * count)410 esp_gatt_status_t btc_ble_gattc_get_char_by_uuid(uint16_t conn_id,
411 uint16_t start_handle,
412 uint16_t end_handle,
413 esp_bt_uuid_t char_uuid,
414 esp_gattc_char_elem_t *result,
415 uint16_t *count)
416 {
417 esp_gatt_status_t status;
418 btgatt_db_element_t *db = NULL;
419 uint16_t char_num = 0;
420 tBT_UUID bta_uuid = {0};
421 btc_to_bta_uuid(&bta_uuid, &char_uuid);
422 BTA_GATTC_GetCharByUUID(conn_id, start_handle, end_handle, bta_uuid, &db, &char_num);
423
424 if ((status = btc_gattc_check_valid_param((int)char_num, 0)) != ESP_GATT_OK) {
425 if (db) {
426 osi_free(db);
427 }
428 *count = 0;
429 return status;
430 } else {
431 btc_gattc_fill_gatt_db_conversion(*count, char_num, ESP_GATT_DB_CHARACTERISTIC, 0, (void *)result, db);
432 }
433
434 *count = char_num;
435 //don't forget to free the db buffer after used.
436 if (db) {
437 osi_free(db);
438 }
439 return ESP_GATT_OK;
440 }
441
btc_ble_gattc_get_descr_by_uuid(uint16_t conn_id,uint16_t start_handle,uint16_t end_handle,esp_bt_uuid_t char_uuid,esp_bt_uuid_t descr_uuid,esp_gattc_descr_elem_t * result,uint16_t * count)442 esp_gatt_status_t btc_ble_gattc_get_descr_by_uuid(uint16_t conn_id,
443 uint16_t start_handle,
444 uint16_t end_handle,
445 esp_bt_uuid_t char_uuid,
446 esp_bt_uuid_t descr_uuid,
447 esp_gattc_descr_elem_t *result,
448 uint16_t *count)
449 {
450 esp_gatt_status_t status;
451 btgatt_db_element_t *db = NULL;
452 uint16_t descr_num = 0;
453 tBT_UUID bta_char_uuid = {0};
454 tBT_UUID bta_descr_uuid = {0};
455 btc_to_bta_uuid(&bta_char_uuid, &char_uuid);
456 btc_to_bta_uuid(&bta_descr_uuid, &descr_uuid);
457
458 BTA_GATTC_GetDescrByUUID(conn_id, start_handle, end_handle,
459 bta_char_uuid, bta_descr_uuid, &db, &descr_num);
460
461 if ((status = btc_gattc_check_valid_param((int)descr_num, 0)) != ESP_GATT_OK) {
462 if (db) {
463 osi_free(db);
464 }
465 *count = 0;
466 return status;
467 } else {
468 btc_gattc_fill_gatt_db_conversion(*count, descr_num, ESP_GATT_DB_DESCRIPTOR, 0, (void *)result, db);
469 }
470
471 *count = descr_num;
472 //don't forget to free the db buffer after used.
473 if (db) {
474 osi_free(db);
475 }
476 return ESP_GATT_OK;
477 }
478
btc_ble_gattc_get_descr_by_char_handle(uint16_t conn_id,uint16_t char_handle,esp_bt_uuid_t descr_uuid,esp_gattc_descr_elem_t * result,uint16_t * count)479 esp_gatt_status_t btc_ble_gattc_get_descr_by_char_handle(uint16_t conn_id,
480 uint16_t char_handle,
481 esp_bt_uuid_t descr_uuid,
482 esp_gattc_descr_elem_t *result,
483 uint16_t *count)
484 {
485 esp_gatt_status_t status;
486 btgatt_db_element_t *db = NULL;
487 uint16_t descr_num = 0;
488 tBT_UUID bta_descr_uuid = {0};
489 btc_to_bta_uuid(&bta_descr_uuid, &descr_uuid);
490
491 BTA_GATTC_GetDescrByCharHandle(conn_id, char_handle, bta_descr_uuid, &db, &descr_num);
492
493 if ((status = btc_gattc_check_valid_param((int)descr_num, 0)) != ESP_GATT_OK) {
494 if (db) {
495 osi_free(db);
496 }
497 *count = 0;
498 return status;
499 } else {
500 btc_gattc_fill_gatt_db_conversion(*count, descr_num, ESP_GATT_DB_DESCRIPTOR, 0, (void *)result, db);
501 }
502
503 *count = descr_num;
504 //don't forget to free the db buffer after used.
505 if (db) {
506 osi_free(db);
507 }
508 return ESP_GATT_OK;
509
510 }
511
btc_ble_gattc_get_include_service(uint16_t conn_id,uint16_t start_handle,uint16_t end_handle,esp_bt_uuid_t * incl_uuid,esp_gattc_incl_svc_elem_t * result,uint16_t * count)512 esp_gatt_status_t btc_ble_gattc_get_include_service(uint16_t conn_id,
513 uint16_t start_handle,
514 uint16_t end_handle,
515 esp_bt_uuid_t *incl_uuid,
516 esp_gattc_incl_svc_elem_t *result,
517 uint16_t *count)
518 {
519 esp_gatt_status_t status;
520 btgatt_db_element_t *db = NULL;
521 uint16_t incl_num = 0;
522 tBT_UUID bta_uuid = {0};
523
524 if (incl_uuid != NULL) {
525 btc_to_bta_uuid(&bta_uuid, incl_uuid);
526 BTA_GATTC_GetIncludeService(conn_id, start_handle, end_handle, &bta_uuid, &db, &incl_num);
527 } else {
528 BTA_GATTC_GetIncludeService(conn_id, start_handle, end_handle, NULL, &db, &incl_num);
529 }
530
531 if ((status = btc_gattc_check_valid_param((int)incl_num, 0)) != ESP_GATT_OK) {
532 if (db) {
533 osi_free(db);
534 }
535 *count = 0;
536 return status;
537 }else {
538 btc_gattc_fill_gatt_db_conversion(*count, incl_num, ESP_GATT_DB_INCLUDED_SERVICE, 0, (void *)result, db);
539 }
540
541 *count = incl_num;
542 //don't forget to free the db buffer after used.
543 if (db) {
544 osi_free(db);
545 }
546 return ESP_GATT_OK;
547 }
548
btc_ble_gattc_get_attr_count(uint16_t conn_id,esp_gatt_db_attr_type_t type,uint16_t start_handle,uint16_t end_handle,uint16_t char_handle,uint16_t * count)549 esp_gatt_status_t btc_ble_gattc_get_attr_count(uint16_t conn_id,
550 esp_gatt_db_attr_type_t type,
551 uint16_t start_handle,
552 uint16_t end_handle,
553 uint16_t char_handle,
554 uint16_t *count)
555 {
556 if (type == ESP_GATT_DB_ALL) {
557 BTA_GATTC_GetDBSize(conn_id, start_handle, end_handle, count);
558 } else {
559 BTA_GATTC_GetDBSizeByType(conn_id, type, start_handle, end_handle, char_handle, count);
560 }
561
562 return ESP_GATT_OK;
563 }
564
btc_ble_gattc_get_db(uint16_t conn_id,uint16_t start_handle,uint16_t end_handle,esp_gattc_db_elem_t * db,uint16_t * count)565 esp_gatt_status_t btc_ble_gattc_get_db(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle,
566 esp_gattc_db_elem_t *db, uint16_t *count)
567 {
568 btgatt_db_element_t *get_db = NULL;
569 uint16_t num = 0;
570 tBT_UUID bta_uuid;
571 uint16_t db_size = 0;
572 BTA_GATTC_GetGattDb(conn_id, start_handle, end_handle, &get_db, &num);
573
574 if (num == 0) {
575 if (get_db) {
576 osi_free(get_db);
577 }
578 *count = 0;
579 return ESP_GATT_NOT_FOUND;
580 }
581
582 db_size = (*count > num) ? num : (*count);
583 for (int i = 0; i < db_size; i++) {
584 db[i].type = get_db[i].type;
585 db[i].attribute_handle = get_db[i].id;
586 db[i].start_handle = get_db[i].start_handle;
587 db[i].end_handle = get_db[i].end_handle;
588 db[i].properties = get_db[i].properties;
589 btc128_to_bta_uuid(&bta_uuid, get_db[i].uuid.uu);
590 bta_to_btc_uuid(&db[i].uuid, &bta_uuid);
591 }
592 *count = db_size;
593 //don't forget to free the db buffer after used.
594 if (get_db) {
595 osi_free(get_db);
596 }
597 return ESP_GATT_OK;
598 }
599
btc_gattc_read_char(btc_ble_gattc_args_t * arg)600 static void btc_gattc_read_char(btc_ble_gattc_args_t *arg)
601 {
602 BTA_GATTC_ReadCharacteristic(arg->read_char.conn_id, arg->read_char.handle, arg->read_char.auth_req);
603 }
604
btc_gattc_read_multiple_char(btc_ble_gattc_args_t * arg)605 static void btc_gattc_read_multiple_char(btc_ble_gattc_args_t *arg)
606 {
607 tBTA_GATTC_MULTI bta_multi;
608 bta_multi.num_attr = arg->read_multiple.num_attr;
609 memcpy(bta_multi.handles, arg->read_multiple.handles, BTA_GATTC_MULTI_MAX);
610 BTA_GATTC_ReadMultiple(arg->read_multiple.conn_id, &bta_multi, arg->read_multiple.auth_req);
611 }
612
btc_gattc_read_char_descr(btc_ble_gattc_args_t * arg)613 static void btc_gattc_read_char_descr(btc_ble_gattc_args_t *arg)
614 {
615 BTA_GATTC_ReadCharDescr(arg->read_descr.conn_id, arg->read_descr.handle, arg->read_descr.auth_req);
616 }
617
btc_gattc_read_by_type(btc_ble_gattc_args_t * arg)618 static void btc_gattc_read_by_type(btc_ble_gattc_args_t *arg)
619 {
620 tBT_UUID uuid;
621 btc_to_bta_uuid(&uuid, &(arg->read_by_type.uuid));
622 BTA_GATTC_Read_by_type(arg->read_by_type.conn_id, arg->read_by_type.s_handle, arg->read_by_type.e_handle, &uuid, arg->read_by_type.auth_req);
623 }
624
btc_gattc_write_char(btc_ble_gattc_args_t * arg)625 static void btc_gattc_write_char(btc_ble_gattc_args_t *arg)
626 {
627 BTA_GATTC_WriteCharValue(arg->write_char.conn_id,
628 arg->write_char.handle,
629 arg->write_char.write_type,
630 arg->write_char.value_len,
631 arg->write_char.value,
632 arg->write_char.auth_req);
633 }
634
btc_gattc_write_char_descr(btc_ble_gattc_args_t * arg)635 static void btc_gattc_write_char_descr(btc_ble_gattc_args_t *arg)
636 {
637 tBTA_GATT_UNFMT descr_val;
638
639 descr_val.len = arg->write_descr.value_len;
640 descr_val.p_value = arg->write_descr.value;
641
642 BTA_GATTC_WriteCharDescr(arg->write_descr.conn_id,
643 arg->write_descr.handle,
644 arg->write_descr.write_type, &descr_val,
645 arg->write_descr.auth_req);
646 }
647
btc_gattc_prepare_write(btc_ble_gattc_args_t * arg)648 static void btc_gattc_prepare_write(btc_ble_gattc_args_t *arg)
649 {
650 BTA_GATTC_PrepareWrite(arg->prep_write.conn_id,
651 arg->prep_write.handle,
652 arg->prep_write.offset,
653 arg->prep_write.value_len,
654 arg->prep_write.value,
655 arg->prep_write.auth_req);
656 }
btc_gattc_prepare_write_char_descr(btc_ble_gattc_args_t * arg)657 static void btc_gattc_prepare_write_char_descr(btc_ble_gattc_args_t *arg)
658 {
659 tBTA_GATT_UNFMT descr_val;
660
661 descr_val.len = arg->prep_write_descr.value_len;
662 descr_val.p_value = arg->prep_write_descr.value;
663 BTA_GATTC_PrepareWriteCharDescr(arg->prep_write_descr.conn_id,
664 arg->prep_write_descr.handle,
665 arg->prep_write_descr.offset,
666 &descr_val,
667 arg->prep_write_descr.auth_req);
668 }
669
btc_gattc_execute_write(btc_ble_gattc_args_t * arg)670 static void btc_gattc_execute_write(btc_ble_gattc_args_t *arg)
671 {
672 BTA_GATTC_ExecuteWrite(arg->exec_write.conn_id, arg->exec_write.is_execute);
673 }
674
btc_gattc_reg_for_notify(btc_ble_gattc_args_t * arg)675 static void btc_gattc_reg_for_notify(btc_ble_gattc_args_t *arg)
676 {
677 tBTA_GATT_STATUS status;
678 esp_ble_gattc_cb_param_t param;
679
680 status = BTA_GATTC_RegisterForNotifications(arg->reg_for_notify.gattc_if,
681 arg->reg_for_notify.remote_bda,
682 arg->reg_for_notify.handle);
683
684 memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
685 param.reg_for_notify.status = status;
686 param.reg_for_notify.handle = arg->reg_for_notify.handle;
687 btc_gattc_cb_to_app(ESP_GATTC_REG_FOR_NOTIFY_EVT, arg->reg_for_notify.gattc_if, ¶m);
688 }
689
btc_gattc_unreg_for_notify(btc_ble_gattc_args_t * arg)690 static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
691 {
692 tBTA_GATT_STATUS status;
693 esp_ble_gattc_cb_param_t param;
694
695 status = BTA_GATTC_DeregisterForNotifications(arg->unreg_for_notify.gattc_if,
696 arg->unreg_for_notify.remote_bda,
697 arg->unreg_for_notify.handle);
698
699 memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
700 param.unreg_for_notify.status = status;
701 param.unreg_for_notify.handle = arg->unreg_for_notify.handle;
702 btc_gattc_cb_to_app(ESP_GATTC_UNREG_FOR_NOTIFY_EVT, arg->unreg_for_notify.gattc_if, ¶m);
703 }
704
btc_gattc_call_handler(btc_msg_t * msg)705 void btc_gattc_call_handler(btc_msg_t *msg)
706 {
707 btc_ble_gattc_args_t *arg = (btc_ble_gattc_args_t *)(msg->arg);
708 switch (msg->act) {
709 case BTC_GATTC_ACT_APP_REGISTER:
710 btc_gattc_app_register(arg);
711 break;
712 case BTC_GATTC_ACT_APP_UNREGISTER:
713 btc_gattc_app_unregister(arg);
714 break;
715 case BTC_GATTC_ACT_OPEN:
716 #if (BLE_50_FEATURE_SUPPORT == TRUE)
717 case BTC_GATTC_ACT_AUX_OPEN:
718 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
719 btc_gattc_open(arg);
720 break;
721 case BTC_GATTC_ACT_CLOSE:
722 btc_gattc_close(arg);
723 break;
724 case BTC_GATTC_ACT_CFG_MTU:
725 btc_gattc_cfg_mtu(arg);
726 break;
727 case BTC_GATTC_ACT_SEARCH_SERVICE:
728 btc_gattc_search_service(arg);
729 break;
730 case BTC_GATTC_ACT_READ_CHAR:
731 btc_gattc_read_char(arg);
732 break;
733 case BTC_GATTC_ACT_READ_MULTIPLE_CHAR:
734 btc_gattc_read_multiple_char(arg);
735 break;
736 case BTC_GATTC_ACT_READ_CHAR_DESCR:
737 btc_gattc_read_char_descr(arg);
738 break;
739 case BTC_GATTC_ACT_READ_BY_TYPE:
740 btc_gattc_read_by_type(arg);
741 break;
742 case BTC_GATTC_ACT_WRITE_CHAR:
743 btc_gattc_write_char(arg);
744 break;
745 case BTC_GATTC_ACT_WRITE_CHAR_DESCR:
746 btc_gattc_write_char_descr(arg);
747 break;
748 case BTC_GATTC_ACT_PREPARE_WRITE:
749 btc_gattc_prepare_write(arg);
750 break;
751 case BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR:
752 btc_gattc_prepare_write_char_descr(arg);
753 break;
754 case BTC_GATTC_ACT_EXECUTE_WRITE:
755 btc_gattc_execute_write(arg);
756 break;
757 case BTC_GATTC_ACT_REG_FOR_NOTIFY:
758 btc_gattc_reg_for_notify(arg);
759 break;
760 case BTC_GATTC_ACT_UNREG_FOR_NOTIFY:
761 btc_gattc_unreg_for_notify(arg);
762 break;
763 case BTC_GATTC_ACT_CACHE_REFRESH:
764 BTA_GATTC_Refresh(arg->cache_refresh.remote_bda, true);
765 break;
766 case BTC_GATTC_ACT_CACHE_ASSOC:
767 BTA_GATTC_CacheAssoc(arg->cache_assoc.gattc_if,
768 arg->cache_assoc.src_addr,
769 arg->cache_assoc.assoc_addr,
770 arg->cache_assoc.is_assoc);
771 break;
772 case BTC_GATTC_ATC_CACHE_GET_ADDR_LIST:
773 BTA_GATTC_CacheGetAddrList(arg->get_addr_list.gattc_if);
774 break;
775 case BTC_GATTC_ACT_CACHE_CLEAN:
776 BTA_GATTC_Clean(arg->cache_clean.remote_bda);
777 break;
778 default:
779 BTC_TRACE_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act);
780 break;
781 }
782
783 btc_gattc_arg_deep_free(msg);
784 }
785
btc_gattc_cb_handler(btc_msg_t * msg)786 void btc_gattc_cb_handler(btc_msg_t *msg)
787 {
788 tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg);
789 esp_gatt_if_t gattc_if = 0;
790 esp_ble_gattc_cb_param_t param = {0};
791
792 memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
793
794 switch (msg->act) {
795 case BTA_GATTC_REG_EVT: {
796 tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
797
798 gattc_if = reg_oper->client_if;
799 param.reg.status = reg_oper->status;
800 param.reg.app_id = reg_oper->app_uuid.uu.uuid16;
801 btc_gattc_cb_to_app(ESP_GATTC_REG_EVT, gattc_if, ¶m);
802 break;
803 }
804 case BTA_GATTC_DEREG_EVT: {
805 tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
806
807 gattc_if = reg_oper->client_if;
808 btc_gattc_cb_to_app(ESP_GATTC_UNREG_EVT, gattc_if, NULL);
809 break;
810 }
811 case BTA_GATTC_READ_CHAR_EVT: {
812 set_read_value(&gattc_if, ¶m, &arg->read);
813 btc_gattc_cb_to_app(ESP_GATTC_READ_CHAR_EVT, gattc_if, ¶m);
814 break;
815 }
816 case BTA_GATTC_WRITE_CHAR_EVT:
817 case BTA_GATTC_PREP_WRITE_EVT: {
818 tBTA_GATTC_WRITE *write = &arg->write;
819 uint32_t ret_evt = (msg->act == BTA_GATTC_WRITE_CHAR_EVT) ?
820 ESP_GATTC_WRITE_CHAR_EVT : ESP_GATTC_PREP_WRITE_EVT;
821
822 gattc_if = BTC_GATT_GET_GATT_IF(write->conn_id);
823 param.write.conn_id = BTC_GATT_GET_CONN_ID(write->conn_id);
824 param.write.status = write->status;
825 param.write.handle = write->handle;
826 param.write.offset = write->offset;
827 btc_gattc_cb_to_app(ret_evt, gattc_if, ¶m);
828 break;
829 }
830
831 case BTA_GATTC_EXEC_EVT: {
832 tBTA_GATTC_EXEC_CMPL *exec_cmpl = &arg->exec_cmpl;
833
834 gattc_if = BTC_GATT_GET_GATT_IF(exec_cmpl->conn_id);
835 param.exec_cmpl.conn_id = BTC_GATT_GET_CONN_ID(exec_cmpl->conn_id);
836 param.exec_cmpl.status = exec_cmpl->status;
837 btc_gattc_cb_to_app(ESP_GATTC_EXEC_EVT, gattc_if, ¶m);
838 break;
839 }
840
841 case BTA_GATTC_SEARCH_CMPL_EVT: {
842 tBTA_GATTC_SEARCH_CMPL *search_cmpl = &arg->search_cmpl;
843
844 gattc_if = BTC_GATT_GET_GATT_IF(search_cmpl->conn_id);
845 param.search_cmpl.conn_id = BTC_GATT_GET_CONN_ID(search_cmpl->conn_id);
846 param.search_cmpl.status = search_cmpl->status;
847 param.search_cmpl.searched_service_source = search_cmpl->searched_service_source;
848 btc_gattc_cb_to_app(ESP_GATTC_SEARCH_CMPL_EVT, gattc_if, ¶m);
849 break;
850 }
851 case BTA_GATTC_SEARCH_RES_EVT: {
852 tBTA_GATTC_SRVC_RES *srvc_res = &arg->srvc_res;
853
854 gattc_if = BTC_GATT_GET_GATT_IF(srvc_res->conn_id);
855 param.search_res.conn_id = BTC_GATT_GET_CONN_ID(srvc_res->conn_id);
856 param.search_res.start_handle = srvc_res->start_handle;
857 param.search_res.end_handle = srvc_res->end_handle;
858 param.search_res.is_primary = srvc_res->is_primary;
859 bta_to_btc_gatt_id(¶m.search_res.srvc_id, &srvc_res->service_uuid);
860 btc_gattc_cb_to_app(ESP_GATTC_SEARCH_RES_EVT, gattc_if, ¶m);
861 break;
862 }
863 case BTA_GATTC_READ_DESCR_EVT: {
864 set_read_value(&gattc_if, ¶m, &arg->read);
865 btc_gattc_cb_to_app(ESP_GATTC_READ_DESCR_EVT, gattc_if, ¶m);
866 break;
867 }
868 case BTA_GATTC_READ_MULTIPLE_EVT: {
869 set_read_value(&gattc_if, ¶m, &arg->read);
870 btc_gattc_cb_to_app(ESP_GATTC_READ_MULTIPLE_EVT, gattc_if, ¶m);
871 break;
872 }
873 case BTA_GATTC_WRITE_DESCR_EVT: {
874 tBTA_GATTC_WRITE *write = &arg->write;
875
876 gattc_if = BTC_GATT_GET_GATT_IF(write->conn_id);
877 param.write.conn_id = BTC_GATT_GET_CONN_ID(write->conn_id);
878 param.write.status = write->status;
879 param.write.handle = write->handle;
880 btc_gattc_cb_to_app(ESP_GATTC_WRITE_DESCR_EVT, gattc_if, ¶m);
881 break;
882 }
883 case BTA_GATTC_NOTIF_EVT: {
884 tBTA_GATTC_NOTIFY *notify = &arg->notify;
885
886 gattc_if = BTC_GATT_GET_GATT_IF(notify->conn_id);
887 param.notify.conn_id = BTC_GATT_GET_CONN_ID(notify->conn_id);
888 memcpy(param.notify.remote_bda, notify->bda, sizeof(esp_bd_addr_t));
889 param.notify.handle = notify->handle;
890 param.notify.is_notify = (notify->is_notify == TRUE) ? true : false;
891 param.notify.value_len = (notify->len > ESP_GATT_MAX_ATTR_LEN) ? \
892 ESP_GATT_MAX_ATTR_LEN : notify->len;
893 param.notify.value = notify->value;
894
895 if (notify->is_notify == FALSE) {
896 BTA_GATTC_SendIndConfirm(notify->conn_id, notify->handle);
897 }
898
899 btc_gattc_cb_to_app(ESP_GATTC_NOTIFY_EVT, gattc_if, ¶m);
900 break;
901 }
902 case BTA_GATTC_OPEN_EVT: {
903 tBTA_GATTC_OPEN *open = &arg->open;
904
905 gattc_if = open->client_if;
906 param.open.status = open->status;
907 param.open.conn_id = BTC_GATT_GET_CONN_ID(open->conn_id);
908 memcpy(param.open.remote_bda, open->remote_bda, sizeof(esp_bd_addr_t));
909 param.open.mtu = open->mtu;
910 btc_gattc_cb_to_app(ESP_GATTC_OPEN_EVT, gattc_if, ¶m);
911 break;
912 }
913 case BTA_GATTC_CONNECT_EVT: {
914 tBTA_GATTC_CONNECT *connect = &arg->connect;
915
916 gattc_if = connect->client_if;
917 param.connect.conn_id = BTC_GATT_GET_CONN_ID(connect->conn_id);
918 param.connect.link_role = connect->link_role;
919 memcpy(param.connect.remote_bda, connect->remote_bda, sizeof(esp_bd_addr_t));
920 param.connect.conn_params.interval = connect->conn_params.interval;
921 param.connect.conn_params.latency = connect->conn_params.latency;
922 param.connect.conn_params.timeout = connect->conn_params.timeout;
923 btc_gattc_cb_to_app(ESP_GATTC_CONNECT_EVT, gattc_if, ¶m);
924 break;
925 }
926 case BTA_GATTC_CLOSE_EVT: {
927 tBTA_GATTC_CLOSE *close = &arg->close;
928
929 gattc_if = close->client_if;
930 param.close.status = close->status;
931 param.close.conn_id = BTC_GATT_GET_CONN_ID(close->conn_id);
932 memcpy(param.close.remote_bda, close->remote_bda, sizeof(esp_bd_addr_t));
933 param.close.reason = close->reason;
934 btc_gattc_cb_to_app(ESP_GATTC_CLOSE_EVT, gattc_if, ¶m);
935 break;
936 }
937 case BTA_GATTC_DISCONNECT_EVT: {
938 tBTA_GATTC_DISCONNECT *disconnect = &arg->disconnect;
939
940 gattc_if = disconnect->client_if;
941 param.disconnect.reason = disconnect->reason;
942 param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(disconnect->conn_id);
943 memcpy(param.disconnect.remote_bda, disconnect->remote_bda, sizeof(esp_bd_addr_t));
944 btc_gattc_cb_to_app(ESP_GATTC_DISCONNECT_EVT, gattc_if, ¶m);
945 break;
946 }
947 case BTA_GATTC_CFG_MTU_EVT: {
948 tBTA_GATTC_CFG_MTU *cfg_mtu = &arg->cfg_mtu;
949
950 gattc_if = BTC_GATT_GET_GATT_IF(cfg_mtu->conn_id);
951 param.cfg_mtu.conn_id = BTC_GATT_GET_CONN_ID(cfg_mtu->conn_id);
952 param.cfg_mtu.status = cfg_mtu->status;
953 param.cfg_mtu.mtu = cfg_mtu->mtu;
954 btc_gattc_cb_to_app(ESP_GATTC_CFG_MTU_EVT, gattc_if, ¶m);
955 break;
956 }
957
958 case BTA_GATTC_ACL_EVT: {
959 /* Currently, this event will never happen */
960 break;
961 }
962 case BTA_GATTC_CANCEL_OPEN_EVT: {
963 /* Currently, this event will never happen */
964 break;
965 }
966 case BTA_GATTC_CONGEST_EVT: {
967 tBTA_GATTC_CONGEST *congest = &arg->congest;
968
969 gattc_if = BTC_GATT_GET_GATT_IF(congest->conn_id);
970 param.congest.conn_id = BTC_GATT_GET_CONN_ID(congest->conn_id);
971 param.congest.congested = (congest->congested == TRUE) ? true : false;
972 btc_gattc_cb_to_app(ESP_GATTC_CONGEST_EVT, gattc_if, ¶m);
973 break;
974 }
975 case BTA_GATTC_SRVC_CHG_EVT: {
976 tBTA_GATTC_SERVICE_CHANGE *srvc_change = &arg->srvc_chg;
977 gattc_if = BTC_GATT_GET_GATT_IF(srvc_change->conn_id);
978 memcpy(param.srvc_chg.remote_bda, srvc_change->remote_bda, sizeof(esp_bd_addr_t));
979 btc_gattc_cb_to_app(ESP_GATTC_SRVC_CHG_EVT, gattc_if, ¶m);
980 break;
981 }
982 case BTA_GATTC_QUEUE_FULL_EVT: {
983 tBTA_GATTC_QUEUE_FULL *queue_full = &arg->queue_full;
984 gattc_if = BTC_GATT_GET_GATT_IF(queue_full->conn_id);
985 param.queue_full.conn_id = BTC_GATT_GET_CONN_ID(queue_full->conn_id);
986 param.queue_full.status = arg->status;
987 param.queue_full.is_full = queue_full->is_full;
988 btc_gattc_cb_to_app(ESP_GATTC_QUEUE_FULL_EVT, gattc_if, ¶m);
989 break;
990 }
991 case BTA_GATTC_ASSOC_EVT: {
992 gattc_if = arg->set_assoc.client_if;
993 param.set_assoc_cmp.status = arg->set_assoc.status;
994 btc_gattc_cb_to_app(ESP_GATTC_SET_ASSOC_EVT, gattc_if, ¶m);
995 break;
996 }
997 case BTA_GATTC_GET_ADDR_LIST_EVT: {
998 gattc_if = arg->get_addr_list.client_if;
999 param.get_addr_list.status = arg->get_addr_list.status;
1000 param.get_addr_list.num_addr = arg->get_addr_list.num_addr;
1001 param.get_addr_list.addr_list = arg->get_addr_list.bda_list;
1002 btc_gattc_cb_to_app(ESP_GATTC_GET_ADDR_LIST_EVT, gattc_if, ¶m);
1003 break;
1004 }
1005 case BTA_GATTC_DIS_SRVC_CMPL_EVT:
1006 gattc_if = BTC_GATT_GET_GATT_IF(arg->dis_cmpl.conn_id);
1007 param.dis_srvc_cmpl.status = arg->dis_cmpl.status;
1008 param.dis_srvc_cmpl.conn_id = BTC_GATT_GET_CONN_ID(arg->dis_cmpl.conn_id);
1009 btc_gattc_cb_to_app(ESP_GATTC_DIS_SRVC_CMPL_EVT, gattc_if, ¶m);
1010 break;
1011 default:
1012 BTC_TRACE_DEBUG("%s: Unhandled event (%d)!", __FUNCTION__, msg->act);
1013 break;
1014 }
1015
1016 // free the deep-copied data
1017 btc_gattc_free_req_data(msg);
1018 }
1019
btc_gattc_congest_callback(tBTA_GATTC * param)1020 void btc_gattc_congest_callback(tBTA_GATTC *param)
1021 {
1022 esp_ble_gattc_cb_param_t esp_param = {0};
1023 memset(&esp_param, 0, sizeof(esp_ble_gattc_cb_param_t));
1024
1025 uint8_t gattc_if = BTC_GATT_GET_GATT_IF(param->congest.conn_id);
1026 esp_param.congest.conn_id = BTC_GATT_GET_CONN_ID(param->congest.conn_id);
1027 esp_param.congest.congested = (param->congest.congested == TRUE) ? true : false;
1028 btc_gattc_cb_to_app(ESP_GATTC_CONGEST_EVT, gattc_if, &esp_param);
1029
1030 }
1031
1032 #endif ///GATTC_INCLUDED == TRUE
1033