1 /******************************************************************************
2 *
3 * Copyright 2017 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <bluetooth/log.h>
20 #include <string.h>
21
22 #include <array>
23 #include <queue>
24
25 #include "gap_api.h"
26 #include "gap_int.h"
27 #include "gatt_api.h"
28 #include "hardware/bt_gatt_types.h"
29 #include "stack/include/bt_types.h"
30 #include "stack/include/bt_uuid16.h"
31 #include "stack/include/btm_client_interface.h"
32 #include "stack/include/btm_status.h"
33 #include "types/bluetooth/uuid.h"
34 #include "types/bt_transport.h"
35 #include "types/raw_address.h"
36
37 using bluetooth::Uuid;
38 using namespace bluetooth;
39
40 namespace {
41
42 typedef struct {
43 uint16_t uuid;
44 tGAP_BLE_CMPL_CBACK* p_cback;
45 } tGAP_REQUEST;
46
47 typedef struct {
48 RawAddress bda;
49 tGAP_BLE_CMPL_CBACK* p_cback;
50 tCONN_ID conn_id;
51 uint16_t cl_op_uuid;
52 bool connected;
53 std::queue<tGAP_REQUEST> requests;
54 } tGAP_CLCB;
55
56 typedef struct {
57 uint16_t handle;
58 uint16_t uuid;
59 tGAP_BLE_ATTR_VALUE attr_value;
60 } tGAP_ATTR;
61
62 static void server_attr_request_cback(tCONN_ID, uint32_t, tGATTS_REQ_TYPE, tGATTS_DATA*);
63 static void client_connect_cback(tGATT_IF, const RawAddress&, tCONN_ID, bool, tGATT_DISCONN_REASON,
64 tBT_TRANSPORT);
65 static void client_cmpl_cback(tCONN_ID, tGATTC_OPTYPE, tGATT_STATUS, tGATT_CL_COMPLETE*);
66
67 tGATT_CBACK gap_cback = {
68 .p_conn_cb = client_connect_cback,
69 .p_cmpl_cb = client_cmpl_cback,
70 .p_disc_res_cb = nullptr,
71 .p_disc_cmpl_cb = nullptr,
72 .p_req_cb = server_attr_request_cback,
73 .p_enc_cmpl_cb = nullptr,
74 .p_congestion_cb = nullptr,
75 .p_phy_update_cb = nullptr,
76 .p_conn_update_cb = nullptr,
77 .p_subrate_chg_cb = nullptr,
78 };
79
80 constexpr int GAP_CHAR_DEV_NAME_SIZE = BD_NAME_LEN;
81 constexpr int GAP_MAX_CHAR_NUM = 4;
82
83 std::vector<tGAP_CLCB> gap_clcbs;
84 /* LE GAP attribute database */
85 std::array<tGAP_ATTR, GAP_MAX_CHAR_NUM> gatt_attr;
86 tGATT_IF gatt_if;
87
88 /** returns LCB with matching bd address, or nullptr */
find_clcb_by_bd_addr(const RawAddress & bda)89 static tGAP_CLCB* find_clcb_by_bd_addr(const RawAddress& bda) {
90 for (auto& cb : gap_clcbs) {
91 if (cb.bda == bda) {
92 return &cb;
93 }
94 }
95
96 return nullptr;
97 }
98
99 /** returns LCB with matching connection ID, or nullptr if not found */
ble_find_clcb_by_conn_id(tCONN_ID conn_id)100 static tGAP_CLCB* ble_find_clcb_by_conn_id(tCONN_ID conn_id) {
101 for (auto& cb : gap_clcbs) {
102 if (cb.connected && cb.conn_id == conn_id) {
103 return &cb;
104 }
105 }
106
107 return nullptr;
108 }
109
110 /** allocates a GAP connection link control block */
clcb_alloc(const RawAddress & bda)111 static tGAP_CLCB* clcb_alloc(const RawAddress& bda) {
112 gap_clcbs.emplace_back();
113 tGAP_CLCB& cb = gap_clcbs.back();
114 cb.bda = bda;
115 return &cb;
116 }
117
118 /** The function clean up the pending request queue in GAP */
clcb_dealloc(tGAP_CLCB & clcb)119 static void clcb_dealloc(tGAP_CLCB& clcb) {
120 // put last element into place of current element, and remove last one - just
121 // fast remove.
122 for (auto it = gap_clcbs.begin(); it != gap_clcbs.end(); it++) {
123 if (it->conn_id == clcb.conn_id) {
124 auto last_one = std::prev(gap_clcbs.end());
125 *it = *last_one;
126 gap_clcbs.erase(last_one);
127 return;
128 }
129 }
130 }
131
132 /** GAP Attributes Database Request callback */
read_attr_value(uint16_t handle,tGATT_VALUE * p_value,bool is_long)133 static tGATT_STATUS read_attr_value(uint16_t handle, tGATT_VALUE* p_value, bool is_long) {
134 uint8_t* p = p_value->value;
135 uint16_t offset = p_value->offset;
136 uint8_t* p_dev_name = NULL;
137
138 for (const tGAP_ATTR& db_attr : gatt_attr) {
139 const tGAP_BLE_ATTR_VALUE& attr_value = db_attr.attr_value;
140 if (handle == db_attr.handle) {
141 if (db_attr.uuid != GATT_UUID_GAP_DEVICE_NAME && is_long) {
142 return GATT_NOT_LONG;
143 }
144
145 switch (db_attr.uuid) {
146 case GATT_UUID_GAP_DEVICE_NAME:
147 if (get_btm_client_interface().local.BTM_ReadLocalDeviceName((const char**)&p_dev_name) !=
148 tBTM_STATUS::BTM_SUCCESS) {
149 log::warn("Unable to read local device name");
150 };
151 if (strlen((char*)p_dev_name) > GATT_MAX_ATTR_LEN) {
152 p_value->len = GATT_MAX_ATTR_LEN;
153 } else {
154 p_value->len = (uint16_t)strlen((char*)p_dev_name);
155 }
156
157 if (offset > p_value->len) {
158 return GATT_INVALID_OFFSET;
159 } else {
160 p_value->len -= offset;
161 p_dev_name += offset;
162 ARRAY_TO_STREAM(p, p_dev_name, p_value->len);
163 }
164 break;
165
166 case GATT_UUID_GAP_ICON:
167 UINT16_TO_STREAM(p, attr_value.icon);
168 p_value->len = 2;
169 break;
170
171 case GATT_UUID_GAP_PREF_CONN_PARAM:
172 UINT16_TO_STREAM(p, attr_value.conn_param.int_min); /* int_min */
173 UINT16_TO_STREAM(p, attr_value.conn_param.int_max); /* int_max */
174 UINT16_TO_STREAM(p, attr_value.conn_param.latency); /* latency */
175 UINT16_TO_STREAM(p, attr_value.conn_param.sp_tout); /* sp_tout */
176 p_value->len = 8;
177 break;
178
179 /* address resolution */
180 case GATT_UUID_GAP_CENTRAL_ADDR_RESOL:
181 UINT8_TO_STREAM(p, attr_value.addr_resolution);
182 p_value->len = 1;
183 break;
184 }
185 return GATT_SUCCESS;
186 }
187 }
188 return GATT_NOT_FOUND;
189 }
190
191 /** GAP Attributes Database Read/Read Blob Request process */
proc_read(tGATTS_REQ_TYPE,tGATT_READ_REQ * p_data,tGATTS_RSP * p_rsp)192 static tGATT_STATUS proc_read(tGATTS_REQ_TYPE, tGATT_READ_REQ* p_data, tGATTS_RSP* p_rsp) {
193 if (p_data->is_long) {
194 p_rsp->attr_value.offset = p_data->offset;
195 }
196
197 p_rsp->attr_value.handle = p_data->handle;
198
199 return read_attr_value(p_data->handle, &p_rsp->attr_value, p_data->is_long);
200 }
201
202 /** GAP ATT server process a write request */
proc_write_req(tGATTS_REQ_TYPE,tGATT_WRITE_REQ * p_data)203 static tGATT_STATUS proc_write_req(tGATTS_REQ_TYPE, tGATT_WRITE_REQ* p_data) {
204 for (const auto& db_addr : gatt_attr) {
205 if (p_data->handle == db_addr.handle) {
206 return GATT_WRITE_NOT_PERMIT;
207 }
208 }
209
210 return GATT_NOT_FOUND;
211 }
212
213 /** GAP ATT server attribute access request callback */
server_attr_request_cback(tCONN_ID conn_id,uint32_t trans_id,tGATTS_REQ_TYPE type,tGATTS_DATA * p_data)214 static void server_attr_request_cback(tCONN_ID conn_id, uint32_t trans_id, tGATTS_REQ_TYPE type,
215 tGATTS_DATA* p_data) {
216 tGATT_STATUS status = GATT_INVALID_PDU;
217 bool ignore = false;
218
219 tGATTS_RSP rsp_msg;
220 memset(&rsp_msg, 0, sizeof(tGATTS_RSP));
221
222 switch (type) {
223 case GATTS_REQ_TYPE_READ_CHARACTERISTIC:
224 case GATTS_REQ_TYPE_READ_DESCRIPTOR:
225 status = proc_read(type, &p_data->read_req, &rsp_msg);
226 break;
227
228 case GATTS_REQ_TYPE_WRITE_CHARACTERISTIC:
229 case GATTS_REQ_TYPE_WRITE_DESCRIPTOR:
230 if (!p_data->write_req.need_rsp) {
231 ignore = true;
232 }
233
234 status = proc_write_req(type, &p_data->write_req);
235 break;
236
237 case GATTS_REQ_TYPE_WRITE_EXEC:
238 ignore = true;
239 log::verbose("Ignore GATTS_REQ_TYPE_WRITE_EXEC");
240 break;
241
242 case GATTS_REQ_TYPE_MTU:
243 log::verbose("Get MTU exchange new mtu size: {}", p_data->mtu);
244 ignore = true;
245 break;
246
247 default:
248 log::verbose("Unknown/unexpected LE GAP ATT request: 0x{:02x}", type);
249 break;
250 }
251
252 if (!ignore) {
253 if (GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg) != GATT_SUCCESS) {
254 log::warn("Unable to send GATT ervier response conn_id:{}", conn_id);
255 }
256 }
257 }
258
259 /**
260 * Utility function to send a read request for GAP characteristics.
261 * Returns true if read started, else false if GAP is busy.
262 */
send_cl_read_request(tGAP_CLCB & clcb)263 static bool send_cl_read_request(tGAP_CLCB& clcb) {
264 if (!clcb.requests.size() || clcb.cl_op_uuid != 0) {
265 return false;
266 }
267
268 tGAP_REQUEST& req = clcb.requests.front();
269 clcb.p_cback = req.p_cback;
270 uint16_t uuid = req.uuid;
271 clcb.requests.pop();
272
273 tGATT_READ_PARAM param;
274 memset(¶m, 0, sizeof(tGATT_READ_PARAM));
275
276 param.service.uuid = Uuid::From16Bit(uuid);
277 param.service.s_handle = 1;
278 param.service.e_handle = 0xFFFF;
279 param.service.auth_req = 0;
280
281 if (GATTC_Read(clcb.conn_id, GATT_READ_BY_TYPE, ¶m) == GATT_SUCCESS) {
282 clcb.cl_op_uuid = uuid;
283 }
284
285 return true;
286 }
287
288 /** GAP client operation complete callback */
cl_op_cmpl(tGAP_CLCB & clcb,bool status,uint16_t len,uint8_t * p_name)289 static void cl_op_cmpl(tGAP_CLCB& clcb, bool status, uint16_t len, uint8_t* p_name) {
290 tGAP_BLE_CMPL_CBACK* p_cback = clcb.p_cback;
291 uint16_t op = clcb.cl_op_uuid;
292
293 clcb.cl_op_uuid = 0;
294 clcb.p_cback = NULL;
295
296 if (p_cback && op) {
297 (*p_cback)(status, clcb.bda, len, (char*)p_name);
298 }
299
300 /* if no further activity is requested in callback, drop the link */
301 if (clcb.connected) {
302 if (!send_cl_read_request(clcb)) {
303 if (GATT_Disconnect(clcb.conn_id) != GATT_SUCCESS) {
304 log::warn("Unable to disconnect GATT conn_id:{}", clcb.conn_id);
305 }
306 clcb_dealloc(clcb);
307 }
308 }
309 }
310
311 /** Client connection callback */
client_connect_cback(tGATT_IF,const RawAddress & bda,tCONN_ID conn_id,bool connected,tGATT_DISCONN_REASON,tBT_TRANSPORT)312 static void client_connect_cback(tGATT_IF, const RawAddress& bda, tCONN_ID conn_id, bool connected,
313 tGATT_DISCONN_REASON /* reason */, tBT_TRANSPORT) {
314 tGAP_CLCB* p_clcb = find_clcb_by_bd_addr(bda);
315 if (p_clcb == NULL) {
316 log::info("No active GAP service found for peer:{} callback:{}", bda,
317 (connected) ? "Connected" : "Disconnected");
318 return;
319 }
320
321 if (connected) {
322 log::debug("Connected GAP to remote device");
323 p_clcb->conn_id = conn_id;
324 p_clcb->connected = true;
325 /* start operation is pending */
326 send_cl_read_request(*p_clcb);
327 } else {
328 log::warn("Disconnected GAP from remote device");
329 p_clcb->connected = false;
330 cl_op_cmpl(*p_clcb, false, 0, NULL);
331 /* clean up clcb */
332 clcb_dealloc(*p_clcb);
333 }
334 }
335
336 /** Client operation complete callback */
client_cmpl_cback(tCONN_ID conn_id,tGATTC_OPTYPE op,tGATT_STATUS status,tGATT_CL_COMPLETE * p_data)337 static void client_cmpl_cback(tCONN_ID conn_id, tGATTC_OPTYPE op, tGATT_STATUS status,
338 tGATT_CL_COMPLETE* p_data) {
339 tGAP_CLCB* p_clcb = ble_find_clcb_by_conn_id(conn_id);
340 uint16_t op_type;
341 uint16_t min, max, latency, tout;
342 uint16_t len;
343 uint8_t* pp;
344
345 if (p_clcb == NULL) {
346 return;
347 }
348
349 op_type = p_clcb->cl_op_uuid;
350
351 /* Currently we only issue read commands */
352 if (op != GATTC_OPTYPE_READ) {
353 return;
354 }
355
356 if (status != GATT_SUCCESS) {
357 cl_op_cmpl(*p_clcb, false, 0, NULL);
358 return;
359 }
360
361 pp = p_data->att_value.value;
362 switch (op_type) {
363 case GATT_UUID_GAP_PREF_CONN_PARAM:
364 /* Extract the peripheral preferred connection parameters and save them */
365 STREAM_TO_UINT16(min, pp);
366 STREAM_TO_UINT16(max, pp);
367 STREAM_TO_UINT16(latency, pp);
368 STREAM_TO_UINT16(tout, pp);
369
370 get_btm_client_interface().ble.BTM_BleSetPrefConnParams(p_clcb->bda, min, max, latency, tout);
371 /* release the connection here */
372 cl_op_cmpl(*p_clcb, true, 0, NULL);
373 break;
374
375 case GATT_UUID_GAP_DEVICE_NAME:
376 len = (uint16_t)strlen((char*)pp);
377 if (len > GAP_CHAR_DEV_NAME_SIZE) {
378 len = GAP_CHAR_DEV_NAME_SIZE;
379 }
380 cl_op_cmpl(*p_clcb, true, len, pp);
381 break;
382
383 case GATT_UUID_GAP_CENTRAL_ADDR_RESOL:
384 cl_op_cmpl(*p_clcb, true, 1, pp);
385 break;
386
387 case GATT_UUID_GAP_ICON:
388 cl_op_cmpl(*p_clcb, true, p_data->att_value.len, pp);
389 break;
390
391 default:
392 log::error("Unexpected operation {}", op);
393 break;
394 }
395 }
396
accept_client_operation(const RawAddress & peer_bda,uint16_t uuid,tGAP_BLE_CMPL_CBACK * p_cback)397 static bool accept_client_operation(const RawAddress& peer_bda, uint16_t uuid,
398 tGAP_BLE_CMPL_CBACK* p_cback) {
399 if (p_cback == NULL && uuid != GATT_UUID_GAP_PREF_CONN_PARAM) {
400 return false;
401 }
402
403 tGAP_CLCB* p_clcb = find_clcb_by_bd_addr(peer_bda);
404 if (p_clcb == NULL) {
405 p_clcb = clcb_alloc(peer_bda);
406 }
407
408 if (GATT_GetConnIdIfConnected(gatt_if, peer_bda, &p_clcb->conn_id, BT_TRANSPORT_LE)) {
409 p_clcb->connected = true;
410 }
411
412 if (!GATT_Connect(gatt_if, p_clcb->bda, BTM_BLE_DIRECT_CONNECTION, BT_TRANSPORT_LE, true)) {
413 return false;
414 }
415
416 /* enqueue the request */
417 p_clcb->requests.push({.uuid = uuid, .p_cback = p_cback});
418
419 if (p_clcb->connected && p_clcb->cl_op_uuid == 0) {
420 return send_cl_read_request(*p_clcb);
421 } else { /* wait for connection up or pending operation to finish */
422 return true;
423 }
424 }
425
426 } // namespace
427
428 /*******************************************************************************
429 *
430 * Function gap_attr_db_init
431 *
432 * Description GAP ATT database initialization.
433 *
434 * Returns void.
435 *
436 ******************************************************************************/
gap_attr_db_init(void)437 void gap_attr_db_init(void) {
438 /* Fill our internal UUID with a fixed pattern 0x82 */
439 std::array<uint8_t, Uuid::kNumBytes128> tmp;
440 tmp.fill(0x82);
441 Uuid app_uuid = Uuid::From128BitBE(tmp);
442 gatt_attr.fill({});
443
444 gatt_if = GATT_Register(app_uuid, "Gap", &gap_cback, false);
445
446 GATT_StartIf(gatt_if);
447
448 Uuid svc_uuid = Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER);
449 Uuid name_uuid = Uuid::From16Bit(GATT_UUID_GAP_DEVICE_NAME);
450 Uuid icon_uuid = Uuid::From16Bit(GATT_UUID_GAP_ICON);
451 Uuid addr_res_uuid = Uuid::From16Bit(GATT_UUID_GAP_CENTRAL_ADDR_RESOL);
452
453 btgatt_db_element_t service[] = {{
454 .uuid = svc_uuid,
455 .type = BTGATT_DB_PRIMARY_SERVICE,
456 },
457 {.uuid = name_uuid,
458 .type = BTGATT_DB_CHARACTERISTIC,
459 .properties = GATT_CHAR_PROP_BIT_READ,
460 .permissions = GATT_PERM_READ_IF_ENCRYPTED_OR_DISCOVERABLE},
461 {.uuid = icon_uuid,
462 .type = BTGATT_DB_CHARACTERISTIC,
463 .properties = GATT_CHAR_PROP_BIT_READ,
464 .permissions = GATT_PERM_READ},
465 {.uuid = addr_res_uuid,
466 .type = BTGATT_DB_CHARACTERISTIC,
467 .properties = GATT_CHAR_PROP_BIT_READ,
468 .permissions = GATT_PERM_READ}
469 #if (BTM_PERIPHERAL_ENABLED == TRUE) /* Only needed for peripheral testing */
470 ,
471 {.uuid = Uuid::From16Bit(GATT_UUID_GAP_PREF_CONN_PARAM),
472 .type = BTGATT_DB_CHARACTERISTIC,
473 .properties = GATT_CHAR_PROP_BIT_READ,
474 .permissions = GATT_PERM_READ}
475 #endif
476 };
477
478 /* Add a GAP service */
479 if (GATTS_AddService(gatt_if, service, sizeof(service) / sizeof(btgatt_db_element_t)) !=
480 GATT_SERVICE_STARTED) {
481 log::warn("Unable to add GATT services gatt_if:{}", gatt_if);
482 }
483
484 gatt_attr[0].uuid = GATT_UUID_GAP_DEVICE_NAME;
485 gatt_attr[0].handle = service[1].attribute_handle;
486
487 gatt_attr[1].uuid = GATT_UUID_GAP_ICON;
488 gatt_attr[1].handle = service[2].attribute_handle;
489
490 gatt_attr[2].uuid = GATT_UUID_GAP_CENTRAL_ADDR_RESOL;
491 gatt_attr[2].handle = service[3].attribute_handle;
492 gatt_attr[2].attr_value.addr_resolution = 0;
493
494 #if (BTM_PERIPHERAL_ENABLED == TRUE) /* Only needed for peripheral testing */
495
496 gatt_attr[3].uuid = GATT_UUID_GAP_PREF_CONN_PARAM;
497 gatt_attr[3].attr_value.conn_param.int_max = GAP_PREFER_CONN_INT_MAX; /* 6 */
498 gatt_attr[3].attr_value.conn_param.int_min = GAP_PREFER_CONN_INT_MIN; /* 0 */
499 gatt_attr[3].attr_value.conn_param.latency = GAP_PREFER_CONN_LATENCY; /* 0 */
500 gatt_attr[3].attr_value.conn_param.sp_tout = GAP_PREFER_CONN_SP_TOUT; /* 2000 */
501 gatt_attr[3].handle = service[4].attribute_handle;
502 #endif
503 }
504
505 /*******************************************************************************
506 *
507 * Function GAP_BleAttrDBUpdate
508 *
509 * Description GAP ATT database update.
510 *
511 ******************************************************************************/
GAP_BleAttrDBUpdate(uint16_t attr_uuid,tGAP_BLE_ATTR_VALUE * p_value)512 void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE* p_value) {
513 for (tGAP_ATTR& db_attr : gatt_attr) {
514 if (db_attr.uuid == attr_uuid) {
515 switch (attr_uuid) {
516 case GATT_UUID_GAP_ICON:
517 db_attr.attr_value.icon = p_value->icon;
518 break;
519
520 case GATT_UUID_GAP_PREF_CONN_PARAM:
521 memcpy((void*)&db_attr.attr_value.conn_param, (const void*)&p_value->conn_param,
522 sizeof(tGAP_BLE_PREF_PARAM));
523 break;
524
525 case GATT_UUID_GAP_DEVICE_NAME:
526 if (get_btm_client_interface().local.BTM_SetLocalDeviceName(
527 (const char*)p_value->p_dev_name) != tBTM_STATUS::BTM_SUCCESS) {
528 log::warn("Unable to set local name");
529 }
530 break;
531
532 case GATT_UUID_GAP_CENTRAL_ADDR_RESOL:
533 db_attr.attr_value.addr_resolution = p_value->addr_resolution;
534 break;
535 }
536 break;
537 }
538 }
539
540 return;
541 }
542
543 /*******************************************************************************
544 *
545 * Function GAP_BleReadPeerPrefConnParams
546 *
547 * Description Start a process to read a connected peripheral's preferred
548 * connection parameters
549 *
550 * Returns true if read started, else false if GAP is busy
551 *
552 ******************************************************************************/
GAP_BleReadPeerPrefConnParams(const RawAddress & peer_bda)553 bool GAP_BleReadPeerPrefConnParams(const RawAddress& peer_bda) {
554 return accept_client_operation(peer_bda, GATT_UUID_GAP_PREF_CONN_PARAM, NULL);
555 }
556
557 /*******************************************************************************
558 *
559 * Function GAP_BleReadPeerDevName
560 *
561 * Description Start a process to read a connected peripheral's device
562 * name.
563 *
564 * Returns true if request accepted
565 *
566 ******************************************************************************/
GAP_BleReadPeerDevName(const RawAddress & peer_bda,tGAP_BLE_CMPL_CBACK * p_cback)567 bool GAP_BleReadPeerDevName(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_cback) {
568 return accept_client_operation(peer_bda, GATT_UUID_GAP_DEVICE_NAME, p_cback);
569 }
570
571 /*******************************************************************************
572 *
573 * Function GAP_BleReadPeerAppearance
574 *
575 * Description Start a process to read a connected peripheral's appearance.
576 *
577 * Returns true if request accepted
578 *
579 ******************************************************************************/
GAP_BleReadPeerAppearance(const RawAddress & peer_bda,tGAP_BLE_CMPL_CBACK * p_cback)580 bool GAP_BleReadPeerAppearance(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_cback) {
581 return accept_client_operation(peer_bda, GATT_UUID_GAP_ICON, p_cback);
582 }
583
584 /*******************************************************************************
585 *
586 * Function GAP_BleCancelReadPeerDevName
587 *
588 * Description Cancel reading a peripheral's device name.
589 *
590 * Returns true if request accepted
591 *
592 ******************************************************************************/
GAP_BleCancelReadPeerDevName(const RawAddress & peer_bda)593 bool GAP_BleCancelReadPeerDevName(const RawAddress& peer_bda) {
594 tGAP_CLCB* p_clcb = find_clcb_by_bd_addr(peer_bda);
595
596 if (p_clcb == NULL) {
597 log::error("Cannot cancel current op is not get dev name");
598 return false;
599 }
600
601 if (!p_clcb->connected) {
602 if (!GATT_CancelConnect(gatt_if, peer_bda, true)) {
603 log::error("Cannot cancel where No connection id");
604 return false;
605 }
606 }
607
608 cl_op_cmpl(*p_clcb, false, 0, NULL);
609
610 return true;
611 }
612