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