1 /******************************************************************************
2 *
3 * Copyright 1999-2012 Broadcom Corporation
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 /******************************************************************************
20 *
21 * This file contains functions that handle BTM interface functions for the
22 * Bluetooth device including Rest, HCI buffer size and others
23 *
24 ******************************************************************************/
25
26 #define LOG_TAG "devctl"
27
28 #include <bluetooth/log.h>
29 #include <stddef.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "acl_api_types.h"
34 #include "btm_sec_cb.h"
35 #include "btm_sec_int_types.h"
36 #include "hci/controller_interface.h"
37 #include "main/shim/btm_api.h"
38 #include "main/shim/entry.h"
39 #include "stack/btm/btm_int_types.h"
40 #include "stack/btm/btm_sec.h"
41 #include "stack/gatt/connection_manager.h"
42 #include "stack/include/acl_api.h"
43 #include "stack/include/acl_api_types.h"
44 #include "stack/include/bt_types.h"
45 #include "stack/include/btm_api.h"
46 #include "stack/include/btm_ble_privacy.h"
47 #include "stack/include/btm_inq.h"
48 #include "stack/include/hcidefs.h"
49 #include "stack/include/l2cap_controller_interface.h"
50 #include "types/raw_address.h"
51
52 using namespace bluetooth;
53
54 extern tBTM_CB btm_cb;
55
56 void btm_inq_db_reset(void);
57 void btm_pm_reset(void);
58 /******************************************************************************/
59 /* L O C A L D A T A D E F I N I T I O N S */
60 /******************************************************************************/
61
62 #ifndef BTM_DEV_RESET_TIMEOUT
63 #define BTM_DEV_RESET_TIMEOUT 4
64 #endif
65
66 // TODO: Reevaluate this value in the context of timers with ms granularity
67 #define BTM_DEV_NAME_REPLY_TIMEOUT_MS \
68 (2 * 1000) /* 2 seconds for name reply \
69 */
70
71 #define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */
72
73 /******************************************************************************/
74 /* L O C A L F U N C T I O N P R O T O T Y P E S */
75 /******************************************************************************/
76
77 static void decode_controller_support();
78
79 /*******************************************************************************
80 *
81 * Function btm_dev_init
82 *
83 * Description This function is on the BTM startup
84 *
85 * Returns void
86 *
87 ******************************************************************************/
btm_dev_init()88 void btm_dev_init() {
89 /* Initialize nonzero defaults */
90 memset(btm_sec_cb.cfg.bd_name, 0, sizeof(BD_NAME));
91
92 btm_cb.devcb.read_local_name_timer = alarm_new("btm.read_local_name_timer");
93 btm_cb.devcb.read_rssi_timer = alarm_new("btm.read_rssi_timer");
94 btm_cb.devcb.read_failed_contact_counter_timer =
95 alarm_new("btm.read_failed_contact_counter_timer");
96 btm_cb.devcb.read_automatic_flush_timeout_timer =
97 alarm_new("btm.read_automatic_flush_timeout_timer");
98 btm_cb.devcb.read_tx_power_timer = alarm_new("btm.read_tx_power_timer");
99 }
100
btm_dev_free()101 void btm_dev_free() {
102 alarm_free(btm_cb.devcb.read_local_name_timer);
103 alarm_free(btm_cb.devcb.read_rssi_timer);
104 alarm_free(btm_cb.devcb.read_failed_contact_counter_timer);
105 alarm_free(btm_cb.devcb.read_automatic_flush_timeout_timer);
106 alarm_free(btm_cb.devcb.read_tx_power_timer);
107 }
108
109 /*******************************************************************************
110 *
111 * Function btm_db_reset
112 *
113 * Returns void
114 *
115 ******************************************************************************/
BTM_db_reset(void)116 void BTM_db_reset(void) {
117 tBTM_CMPL_CB* p_cb;
118
119 btm_inq_db_reset();
120
121 if (btm_cb.devcb.p_rln_cmpl_cb) {
122 p_cb = btm_cb.devcb.p_rln_cmpl_cb;
123 btm_cb.devcb.p_rln_cmpl_cb = NULL;
124
125 if (p_cb) (*p_cb)((void*)NULL);
126 }
127
128 if (btm_cb.devcb.p_rssi_cmpl_cb) {
129 p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
130 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
131
132 if (p_cb) {
133 tBTM_RSSI_RESULT btm_rssi_result;
134 btm_rssi_result.status = BTM_DEV_RESET;
135 (*p_cb)(&btm_rssi_result);
136 }
137 }
138
139 if (btm_cb.devcb.p_failed_contact_counter_cmpl_cb) {
140 p_cb = btm_cb.devcb.p_failed_contact_counter_cmpl_cb;
141 btm_cb.devcb.p_failed_contact_counter_cmpl_cb = NULL;
142
143 if (p_cb) {
144 tBTM_FAILED_CONTACT_COUNTER_RESULT btm_failed_contact_counter_result;
145 btm_failed_contact_counter_result.status = BTM_DEV_RESET;
146 (*p_cb)(&btm_failed_contact_counter_result);
147 }
148 }
149
150 if (btm_cb.devcb.p_automatic_flush_timeout_cmpl_cb) {
151 p_cb = btm_cb.devcb.p_automatic_flush_timeout_cmpl_cb;
152 btm_cb.devcb.p_automatic_flush_timeout_cmpl_cb = NULL;
153
154 if (p_cb) {
155 tBTM_AUTOMATIC_FLUSH_TIMEOUT_RESULT btm_automatic_flush_timeout_result;
156 btm_automatic_flush_timeout_result.status = BTM_DEV_RESET;
157 (*p_cb)(&btm_automatic_flush_timeout_result);
158 }
159 }
160 }
161
set_sec_state_idle(void * data,void *)162 static bool set_sec_state_idle(void* data, void* /* context */) {
163 tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data);
164 p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE;
165 return true;
166 }
167
BTM_reset_complete()168 void BTM_reset_complete() {
169 /* Tell L2CAP that all connections are gone */
170 l2cu_device_reset();
171
172 /* Clear current security state */
173 list_foreach(btm_sec_cb.sec_dev_rec, set_sec_state_idle, NULL);
174
175 /* After the reset controller should restore all parameters to defaults. */
176 btm_cb.btm_inq_vars.inq_counter = 1;
177 btm_cb.btm_inq_vars.inq_scan_window = HCI_DEF_INQUIRYSCAN_WINDOW;
178 btm_cb.btm_inq_vars.inq_scan_period = HCI_DEF_INQUIRYSCAN_INTERVAL;
179 btm_cb.btm_inq_vars.inq_scan_type = HCI_DEF_SCAN_TYPE;
180
181 btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW;
182 btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL;
183 btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE;
184
185 btm_cb.ble_ctr_cb.set_connection_state_idle();
186 connection_manager::reset(true);
187
188 btm_pm_reset();
189
190 l2c_link_init(bluetooth::shim::GetController()->GetNumAclPacketBuffers());
191
192 // setup the random number generator
193 std::srand(std::time(nullptr));
194
195 /* Set up the BLE privacy settings */
196 if (bluetooth::shim::GetController()->SupportsBle() &&
197 bluetooth::shim::GetController()->SupportsBlePrivacy() &&
198 bluetooth::shim::GetController()->GetLeResolvingListSize() > 0) {
199 btm_ble_resolving_list_init(
200 bluetooth::shim::GetController()->GetLeResolvingListSize());
201 /* set the default random private address timeout */
202 btsnd_hcic_ble_set_rand_priv_addr_timeout(
203 btm_get_next_private_addrress_interval_ms() / 1000);
204 } else {
205 log::info(
206 "Le Address Resolving list disabled due to lack of controller support");
207 }
208
209 if (bluetooth::shim::GetController()->SupportsBle()) {
210 l2c_link_processs_ble_num_bufs(bluetooth::shim::GetController()
211 ->GetLeBufferSize()
212 .total_num_le_packets_);
213 }
214
215 BTM_SetPinType(btm_sec_cb.cfg.pin_type, btm_sec_cb.cfg.pin_code,
216 btm_sec_cb.cfg.pin_code_len);
217
218 decode_controller_support();
219 }
220
221 /*******************************************************************************
222 *
223 * Function BTM_IsDeviceUp
224 *
225 * Description This function is called to check if the device is up.
226 *
227 * Returns true if device is up, else false
228 *
229 ******************************************************************************/
BTM_IsDeviceUp(void)230 bool BTM_IsDeviceUp(void) {
231 return bluetooth::shim::GetController() != nullptr;
232 }
233
234 /*******************************************************************************
235 *
236 * Function btm_read_local_name_timeout
237 *
238 * Description Callback when reading the local name times out.
239 *
240 * Returns void
241 *
242 ******************************************************************************/
btm_read_local_name_timeout(void *)243 static void btm_read_local_name_timeout(void* /* data */) {
244 tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rln_cmpl_cb;
245 btm_cb.devcb.p_rln_cmpl_cb = NULL;
246 if (p_cb) (*p_cb)((void*)NULL);
247 }
248
decode_controller_support()249 static void decode_controller_support() {
250 /* Create (e)SCO supported packet types mask */
251 btm_cb.btm_sco_pkt_types_supported = 0;
252 btm_cb.sco_cb.esco_supported = false;
253 if (bluetooth::shim::GetController()->SupportsSco()) {
254 btm_cb.btm_sco_pkt_types_supported = ESCO_PKT_TYPES_MASK_HV1;
255
256 if (bluetooth::shim::GetController()->SupportsHv2Packets())
257 btm_cb.btm_sco_pkt_types_supported |= ESCO_PKT_TYPES_MASK_HV2;
258
259 if (bluetooth::shim::GetController()->SupportsHv3Packets())
260 btm_cb.btm_sco_pkt_types_supported |= ESCO_PKT_TYPES_MASK_HV3;
261 }
262
263 if (bluetooth::shim::GetController()->SupportsEv3Packets())
264 btm_cb.btm_sco_pkt_types_supported |= ESCO_PKT_TYPES_MASK_EV3;
265
266 if (bluetooth::shim::GetController()->SupportsEv4Packets())
267 btm_cb.btm_sco_pkt_types_supported |= ESCO_PKT_TYPES_MASK_EV4;
268
269 if (bluetooth::shim::GetController()->SupportsEv5Packets())
270 btm_cb.btm_sco_pkt_types_supported |= ESCO_PKT_TYPES_MASK_EV5;
271
272 if (btm_cb.btm_sco_pkt_types_supported & BTM_ESCO_LINK_ONLY_MASK) {
273 btm_cb.sco_cb.esco_supported = true;
274
275 /* Add in EDR related eSCO types */
276 if (bluetooth::shim::GetController()->SupportsEsco2mPhy()) {
277 if (!bluetooth::shim::GetController()->Supports3SlotEdrPackets())
278 btm_cb.btm_sco_pkt_types_supported |= ESCO_PKT_TYPES_MASK_NO_2_EV5;
279 } else {
280 btm_cb.btm_sco_pkt_types_supported |=
281 (ESCO_PKT_TYPES_MASK_NO_2_EV3 + ESCO_PKT_TYPES_MASK_NO_2_EV5);
282 }
283
284 if (bluetooth::shim::GetController()->SupportsEsco3mPhy()) {
285 if (!bluetooth::shim::GetController()->Supports3SlotEdrPackets())
286 btm_cb.btm_sco_pkt_types_supported |= ESCO_PKT_TYPES_MASK_NO_3_EV5;
287 } else {
288 btm_cb.btm_sco_pkt_types_supported |=
289 (ESCO_PKT_TYPES_MASK_NO_3_EV3 + ESCO_PKT_TYPES_MASK_NO_3_EV5);
290 }
291 }
292
293 log::verbose("Local supported SCO packet types: 0x{:04x}",
294 btm_cb.btm_sco_pkt_types_supported);
295
296 BTM_acl_after_controller_started();
297 btm_sec_dev_reset();
298
299 if (bluetooth::shim::GetController()->SupportsRssiWithInquiryResults()) {
300 if (bluetooth::shim::GetController()->SupportsExtendedInquiryResponse()) {
301 if (BTM_SetInquiryMode(BTM_INQ_RESULT_EXTENDED) != BTM_SUCCESS) {
302 log::warn("Unable to set inquiry mode BTM_INQ_RESULT_EXTENDED");
303 }
304 } else {
305 if (BTM_SetInquiryMode(BTM_INQ_RESULT_WITH_RSSI) != BTM_SUCCESS) {
306 log::warn("Unable to set inquiry mode BTM_INQ_RESULT_WITH_RSSI");
307 }
308 }
309 }
310
311 l2cu_set_non_flushable_pbf(
312 bluetooth::shim::GetController()->SupportsNonFlushablePb());
313 BTM_EnableInterlacedPageScan();
314 BTM_EnableInterlacedInquiryScan();
315 }
316
317 /*******************************************************************************
318 *
319 * Function BTM_SetLocalDeviceName
320 *
321 * Description This function is called to set the local device name.
322 *
323 * Returns status of the operation
324 *
325 ******************************************************************************/
BTM_SetLocalDeviceName(const char * p_name)326 tBTM_STATUS BTM_SetLocalDeviceName(const char* p_name) {
327 uint8_t* p;
328
329 if (!p_name || !p_name[0] || (strlen((char*)p_name) > BD_NAME_LEN))
330 return (BTM_ILLEGAL_VALUE);
331
332 if (bluetooth::shim::GetController() == nullptr) return (BTM_DEV_RESET);
333 /* Save the device name if local storage is enabled */
334 p = (uint8_t*)btm_sec_cb.cfg.bd_name;
335 if (p != (uint8_t*)p_name)
336 bd_name_from_char_pointer(btm_sec_cb.cfg.bd_name, p_name);
337
338 btsnd_hcic_change_name(p);
339 return (BTM_CMD_STARTED);
340 }
341
342 /*******************************************************************************
343 *
344 * Function BTM_ReadLocalDeviceName
345 *
346 * Description This function is called to read the local device name.
347 *
348 * Returns status of the operation
349 * If success, BTM_SUCCESS is returned and p_name points stored
350 * local device name
351 * If BTM doesn't store local device name, BTM_NO_RESOURCES is
352 * is returned and p_name is set to NULL
353 *
354 ******************************************************************************/
BTM_ReadLocalDeviceName(const char ** p_name)355 tBTM_STATUS BTM_ReadLocalDeviceName(const char** p_name) {
356 *p_name = (const char*)btm_sec_cb.cfg.bd_name;
357 return (BTM_SUCCESS);
358 }
359
360 /*******************************************************************************
361 *
362 * Function BTM_ReadLocalDeviceNameFromController
363 *
364 * Description Get local device name from controller. Do not use cached
365 * name (used to get chip-id prior to btm reset complete).
366 *
367 * Returns BTM_CMD_STARTED if successful, otherwise an error
368 *
369 ******************************************************************************/
BTM_ReadLocalDeviceNameFromController(tBTM_CMPL_CB * p_rln_cmpl_cback)370 tBTM_STATUS BTM_ReadLocalDeviceNameFromController(
371 tBTM_CMPL_CB* p_rln_cmpl_cback) {
372 /* Check if rln already in progress */
373 if (btm_cb.devcb.p_rln_cmpl_cb) return (BTM_NO_RESOURCES);
374
375 /* Save callback */
376 btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback;
377
378 btsnd_hcic_read_name();
379 alarm_set_on_mloop(btm_cb.devcb.read_local_name_timer,
380 BTM_DEV_NAME_REPLY_TIMEOUT_MS, btm_read_local_name_timeout,
381 NULL);
382
383 return BTM_CMD_STARTED;
384 }
385
386 /*******************************************************************************
387 *
388 * Function btm_read_local_name_complete
389 *
390 * Description This function is called when local name read complete.
391 * message is received from the HCI.
392 *
393 * Returns void
394 *
395 ******************************************************************************/
btm_read_local_name_complete(uint8_t * p,uint16_t)396 void btm_read_local_name_complete(uint8_t* p, uint16_t /* evt_len */) {
397 tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rln_cmpl_cb;
398 uint8_t status;
399
400 alarm_cancel(btm_cb.devcb.read_local_name_timer);
401
402 /* If there was a callback address for read local name, call it */
403 btm_cb.devcb.p_rln_cmpl_cb = NULL;
404
405 if (p_cb) {
406 STREAM_TO_UINT8(status, p);
407
408 if (status == HCI_SUCCESS)
409 (*p_cb)(p);
410 else
411 (*p_cb)(NULL);
412 }
413 }
414
415 /*******************************************************************************
416 *
417 * Function BTM_SetDeviceClass
418 *
419 * Description This function is called to set the local device class
420 *
421 * Returns status of the operation
422 *
423 ******************************************************************************/
BTM_SetDeviceClass(DEV_CLASS dev_class)424 tBTM_STATUS BTM_SetDeviceClass(DEV_CLASS dev_class) {
425 if (btm_cb.devcb.dev_class == dev_class) return (BTM_SUCCESS);
426
427 btm_cb.devcb.dev_class = dev_class;
428
429 if (bluetooth::shim::GetController() == nullptr) return (BTM_DEV_RESET);
430
431 btsnd_hcic_write_dev_class(dev_class);
432
433 return (BTM_SUCCESS);
434 }
435
436 /*******************************************************************************
437 *
438 * Function BTM_ReadDeviceClass
439 *
440 * Description This function is called to read the local device class
441 *
442 * Returns the device class
443 *
444 ******************************************************************************/
BTM_ReadDeviceClass(void)445 DEV_CLASS BTM_ReadDeviceClass(void) { return btm_cb.devcb.dev_class; }
446
447 /*******************************************************************************
448 *
449 * Function BTM_VendorSpecificCommand
450 *
451 * Description Send a vendor specific HCI command to the controller.
452 *
453 * Notes
454 * Opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC.
455 *
456 ******************************************************************************/
BTM_VendorSpecificCommand(uint16_t opcode,uint8_t param_len,uint8_t * p_param_buf,tBTM_VSC_CMPL_CB * p_cb)457 void BTM_VendorSpecificCommand(uint16_t opcode, uint8_t param_len,
458 uint8_t* p_param_buf, tBTM_VSC_CMPL_CB* p_cb) {
459 log::verbose("BTM: Opcode: 0x{:04X}, ParamLen: {}.", opcode, param_len);
460
461 /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */
462 btsnd_hcic_vendor_spec_cmd(opcode, param_len, p_param_buf, p_cb);
463 }
464
465 /*******************************************************************************
466 *
467 * Function BTM_WritePageTimeout
468 *
469 * Description Send HCI Write Page Timeout.
470 *
471 ******************************************************************************/
BTM_WritePageTimeout(uint16_t timeout)472 void BTM_WritePageTimeout(uint16_t timeout) {
473 log::verbose("BTM: BTM_WritePageTimeout: Timeout: {}.", timeout);
474
475 /* Send the HCI command */
476 btsnd_hcic_write_page_tout(timeout);
477 }
478
479 /*******************************************************************************
480 *
481 * Function BTM_WriteVoiceSettings
482 *
483 * Description Send HCI Write Voice Settings command.
484 * See hcidefs.h for settings bitmask values.
485 *
486 ******************************************************************************/
BTM_WriteVoiceSettings(uint16_t settings)487 void BTM_WriteVoiceSettings(uint16_t settings) {
488 log::verbose("BTM: BTM_WriteVoiceSettings: Settings: 0x{:04x}.", settings);
489
490 /* Send the HCI command */
491 btsnd_hcic_write_voice_settings((uint16_t)(settings & 0x03ff));
492 }
493
494 /*******************************************************************************
495 *
496 * Function BTM_EnableTestMode
497 *
498 * Description Send HCI the enable device under test command.
499 *
500 * Note: Controller can only be taken out of this mode by
501 * resetting the controller.
502 *
503 * Returns
504 * BTM_SUCCESS Command sent.
505 * BTM_NO_RESOURCES If out of resources to send the command.
506 *
507 *
508 ******************************************************************************/
BTM_EnableTestMode(void)509 tBTM_STATUS BTM_EnableTestMode(void) {
510 uint8_t cond;
511
512 log::verbose("BTM: BTM_EnableTestMode");
513
514 /* set auto accept connection as this is needed during test mode */
515 /* Allocate a buffer to hold HCI command */
516 cond = HCI_DO_AUTO_ACCEPT_CONNECT;
517 btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP,
518 HCI_FILTER_COND_NEW_DEVICE, &cond, sizeof(cond));
519
520 /* put device to connectable mode */
521 if (BTM_SetConnectability(BTM_CONNECTABLE) != BTM_SUCCESS) {
522 return BTM_NO_RESOURCES;
523 }
524
525 /* put device to discoverable mode */
526 if (BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE) != BTM_SUCCESS) {
527 return BTM_NO_RESOURCES;
528 }
529
530 /* mask off all of event from controller */
531 bluetooth::shim::BTM_ClearEventMask();
532
533 /* Send the HCI command */
534 btsnd_hcic_enable_test_mode();
535 return (BTM_SUCCESS);
536 }
537
538 /*******************************************************************************
539 *
540 * Function BTM_DeleteStoredLinkKey
541 *
542 * Description This function is called to delete link key for the specified
543 * device addresses from the NVRAM storage attached to the
544 * Bluetooth controller.
545 *
546 * Parameters: bd_addr - Addresses of the devices
547 * p_cb - Call back function to be called to return
548 * the results
549 *
550 ******************************************************************************/
BTM_DeleteStoredLinkKey(const RawAddress * bd_addr,tBTM_CMPL_CB * p_cb)551 tBTM_STATUS BTM_DeleteStoredLinkKey(const RawAddress* bd_addr,
552 tBTM_CMPL_CB* p_cb) {
553 /* Read and Write STORED link key stems from a legacy use-case and is no
554 * longer expected to be used. Disable explicitly for Floss and queue overall
555 * deletion from Fluoride.
556 */
557 #if !defined(TARGET_FLOSS)
558 /* Check if the previous command is completed */
559 if (btm_sec_cb.devcb.p_stored_link_key_cmpl_cb) return (BTM_BUSY);
560
561 bool delete_all_flag = !bd_addr;
562
563 log::verbose("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: {}",
564 delete_all_flag);
565
566 btm_sec_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;
567 if (!bd_addr) {
568 /* This is to delete all link keys */
569 /* We don't care the BD address. Just pass a non zero pointer */
570 RawAddress local_bd_addr = RawAddress::kEmpty;
571 btsnd_hcic_delete_stored_key(local_bd_addr, delete_all_flag);
572 } else {
573 btsnd_hcic_delete_stored_key(*bd_addr, delete_all_flag);
574 }
575 #endif
576
577 return (BTM_SUCCESS);
578 }
579
580 /*******************************************************************************
581 *
582 * Function btm_delete_stored_link_key_complete
583 *
584 * Description This function is called when the command complete message
585 * is received from the HCI for the delete stored link key
586 * command.
587 *
588 * Returns void
589 *
590 ******************************************************************************/
btm_delete_stored_link_key_complete(uint8_t * p,uint16_t evt_len)591 void btm_delete_stored_link_key_complete(uint8_t* p, uint16_t evt_len) {
592 tBTM_CMPL_CB* p_cb = btm_sec_cb.devcb.p_stored_link_key_cmpl_cb;
593 tBTM_DELETE_STORED_LINK_KEY_COMPLETE result;
594
595 /* If there was a callback registered for read stored link key, call it */
596 btm_sec_cb.devcb.p_stored_link_key_cmpl_cb = NULL;
597
598 if (p_cb) {
599 /* Set the call back event to indicate command complete */
600 result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS;
601
602 if (evt_len < 3) {
603 log::error("Malformatted event packet, too short");
604 return;
605 }
606
607 /* Extract the result fields from the HCI event */
608 STREAM_TO_UINT8(result.status, p);
609 STREAM_TO_UINT16(result.num_keys, p);
610
611 /* Call the call back and pass the result */
612 (*p_cb)(&result);
613 }
614 }
615