• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 for the Bluetooth Security Manager
22  *
23  ******************************************************************************/
24 
25 #pragma once
26 #include <cstdint>
27 #include "stack/btm/security_device_record.h"
28 #include "stack/include/btm_api_types.h"
29 #include "stack/include/hci_error_code.h"
30 #include "stack/include/security_client_callbacks.h"
31 #include "types/hci_role.h"
32 
33 #define BTM_SEC_MAX_COLLISION_DELAY (5000)
34 
35 /*******************************************************************************
36  *             L O C A L    F U N C T I O N     P R O T O T Y P E S            *
37  ******************************************************************************/
38 tBTM_SEC_SERV_REC* btm_sec_find_first_serv(bool is_originator, uint16_t psm);
39 
40 tBTM_SEC_DEV_REC* btm_sec_find_dev_by_sec_state(uint8_t state);
41 
42 /*******************************************************************************
43  *
44  * Function         BTM_SecRegister
45  *
46  * Description      Application manager calls this function to register for
47  *                  security services.  There can be one and only one
48  *                  application saving link keys.  BTM allows only first
49  *                  registration.
50  *
51  * Returns          true if registered OK, else false
52  *
53  ******************************************************************************/
54 bool BTM_SecRegister(const tBTM_APPL_INFO* p_cb_info);
55 
56 /*******************************************************************************
57  *
58  * Function         BTM_SecAddRmtNameNotifyCallback
59  *
60  * Description      Any profile can register to be notified when name of the
61  *                  remote device is resolved.
62  *
63  * Returns          true if registered OK, else false
64  *
65  ******************************************************************************/
66 bool BTM_SecAddRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback);
67 
68 /*******************************************************************************
69  *
70  * Function         BTM_SecDeleteRmtNameNotifyCallback
71  *
72  * Description      Any profile can deregister notification when a new Link Key
73  *                  is generated per connection.
74  *
75  * Returns          true if OK, else false
76  *
77  ******************************************************************************/
78 bool BTM_SecDeleteRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback);
79 
80 /*******************************************************************************
81  *
82  * Function         BTM_GetSecurityFlags
83  *
84  * Description      Get security flags for the device
85  *
86  * Returns          bool    true or false is device found
87  *
88  ******************************************************************************/
89 bool BTM_GetSecurityFlags(const RawAddress& bd_addr, uint8_t* p_sec_flags);
90 
91 /*******************************************************************************
92  *
93  * Function         BTM_GetSecurityFlagsByTransport
94  *
95  * Description      Get security flags for the device on a particular transport
96  *
97  * Returns          bool    true or false is device found
98  *
99  ******************************************************************************/
100 bool BTM_GetSecurityFlagsByTransport(const RawAddress& bd_addr,
101                                      uint8_t* p_sec_flags,
102                                      tBT_TRANSPORT transport);
103 
104 bool BTM_IsEncrypted(const RawAddress& bd_addr, tBT_TRANSPORT transport);
105 bool BTM_IsLinkKeyAuthed(const RawAddress& bd_addr, tBT_TRANSPORT transport);
106 bool BTM_IsLinkKeyKnown(const RawAddress& bd_addr, tBT_TRANSPORT transport);
107 bool BTM_IsAuthenticated(const RawAddress& bd_addr, tBT_TRANSPORT transport);
108 
109 /*******************************************************************************
110  *
111  * Function         BTM_SetPinType
112  *
113  * Description      Set PIN type for the device.
114  *
115  * Returns          void
116  *
117  ******************************************************************************/
118 void BTM_SetPinType(uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_code_len);
119 
120 /*******************************************************************************
121  *
122  * Function         BTM_SetSecurityLevel
123  *
124  * Description      Register service security level with Security Manager
125  *
126  * Parameters:      is_originator - true if originating the connection
127  *                  p_name      - Name of the service relevant only if
128  *                                authorization will show this name to user.
129  *                                Ignored if BT_MAX_SERVICE_NAME_LEN is 0.
130  *                  service_id  - service ID for the service passed to
131  *                                authorization callback
132  *                  sec_level   - bit mask of the security features
133  *                  psm         - L2CAP PSM
134  *                  mx_proto_id - protocol ID of multiplexing proto below
135  *                  mx_chan_id  - channel ID of multiplexing proto below
136  *
137  * Returns          true if registered OK, else false
138  *
139  ******************************************************************************/
140 bool BTM_SetSecurityLevel(bool is_originator, const char* p_name,
141                           uint8_t service_id, uint16_t sec_level, uint16_t psm,
142                           uint32_t mx_proto_id, uint32_t mx_chan_id);
143 
144 /*******************************************************************************
145  *
146  * Function         BTM_SecClrService
147  *
148  * Description      Removes specified service record(s) from the security
149  *                  database. All service records with the specified name are
150  *                  removed. Typically used only by devices with limited RAM so
151  *                  that it can reuse an old security service record.
152  *
153  *                  Note: Unpredictable results may occur if a service is
154  *                      cleared that is still in use by an application/profile.
155  *
156  * Parameters       Service ID - Id of the service to remove. '0' removes all
157  *                          service records (except SDP).
158  *
159  * Returns          Number of records that were freed.
160  *
161  ******************************************************************************/
162 uint8_t BTM_SecClrService(uint8_t service_id);
163 
164 /*******************************************************************************
165  *
166  * Function         BTM_SecClrServiceByPsm
167  *
168  * Description      Removes specified service record from the security database.
169  *                  All service records with the specified psm are removed.
170  *                  Typically used by L2CAP to free up the service record used
171  *                  by dynamic PSM clients when the channel is closed.
172  *                  The given psm must be a virtual psm.
173  *
174  * Parameters       Service ID - Id of the service to remove. '0' removes all
175  *                          service records (except SDP).
176  *
177  * Returns          Number of records that were freed.
178  *
179  ******************************************************************************/
180 uint8_t BTM_SecClrServiceByPsm(uint16_t psm);
181 
182 /*******************************************************************************
183  *
184  * Function         BTM_PINCodeReply
185  *
186  * Description      This function is called after Security Manager submitted
187  *                  PIN code request to the UI.
188  *
189  * Parameters:      bd_addr      - Address of the device for which PIN was
190  *                                 requested
191  *                  res          - result of the operation BTM_SUCCESS
192  *                                 if success
193  *                  pin_len      - length in bytes of the PIN Code
194  *                  p_pin        - pointer to array with the PIN Code
195  *
196  ******************************************************************************/
197 void BTM_PINCodeReply(const RawAddress& bd_addr, uint8_t res, uint8_t pin_len,
198                       uint8_t* p_pin);
199 
200 /*******************************************************************************
201  *
202  * Function         btm_sec_bond_by_transport
203  *
204  * Description      this is the bond function that will start either SSP or SMP.
205  *
206  * Parameters:      bd_addr      - Address of the device to bond
207  *                  pin_len      - length in bytes of the PIN Code
208  *                  p_pin        - pointer to array with the PIN Code
209  *
210  *  Note: After 2.1 parameters are not used and preserved here not to change API
211  ******************************************************************************/
212 tBTM_STATUS btm_sec_bond_by_transport(const RawAddress& bd_addr,
213                                       tBT_TRANSPORT transport, uint8_t pin_len,
214                                       uint8_t* p_pin);
215 
216 /*******************************************************************************
217  *
218  * Function         BTM_SecBond
219  *
220  * Description      This function is called to perform bonding with peer device.
221  *                  If the connection is already up, but not secure, pairing
222  *                  is attempted.  If already paired BTM_SUCCESS is returned.
223  *
224  * Parameters:      bd_addr      - Address of the device to bond
225  *                  transport    - doing SSP over BR/EDR or SMP over LE
226  *                  pin_len      - length in bytes of the PIN Code
227  *                  p_pin        - pointer to array with the PIN Code
228  *
229  *  Note: After 2.1 parameters are not used and preserved here not to change API
230  ******************************************************************************/
231 tBTM_STATUS BTM_SecBond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
232                         tBT_TRANSPORT transport, int device_type,
233                         uint8_t pin_len, uint8_t* p_pin);
234 
235 /*******************************************************************************
236  *
237  * Function         BTM_SecBondCancel
238  *
239  * Description      This function is called to cancel ongoing bonding process
240  *                  with peer device.
241  *
242  * Parameters:      bd_addr      - Address of the peer device
243  *                  transport    - false for BR/EDR link; true for LE link
244  *
245  ******************************************************************************/
246 tBTM_STATUS BTM_SecBondCancel(const RawAddress& bd_addr);
247 
248 /*******************************************************************************
249  *
250  * Function         BTM_SecGetDeviceLinkKeyType
251  *
252  * Description      This function is called to obtain link key type for the
253  *                  device.
254  *                  it returns BTM_SUCCESS if link key is available, or
255  *                  BTM_UNKNOWN_ADDR if Security Manager does not know about
256  *                  the device or device record does not contain link key info
257  *
258  * Returns          BTM_LKEY_TYPE_IGNORE if link key is unknown, link type
259  *                  otherwise.
260  *
261  ******************************************************************************/
262 tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType(const RawAddress& bd_addr);
263 
264 /*******************************************************************************
265  *
266  * Function         BTM_SetEncryption
267  *
268  * Description      This function is called to ensure that connection is
269  *                  encrypted.  Should be called only on an open connection.
270  *                  Typically only needed for connections that first want to
271  *                  bring up unencrypted links, then later encrypt them.
272  *
273  * Parameters:      bd_addr       - Address of the peer device
274  *                  transport     - Link transport
275  *                  p_callback    - Pointer to callback function called if
276  *                                  this function returns PENDING after required
277  *                                  procedures are completed.  Can be set to
278  *                                  NULL if status is not desired.
279  *                  p_ref_data    - pointer to any data the caller wishes to
280  *                                  receive in the callback function upon
281  *                                  completion. can be set to NULL if not used.
282  *                  sec_act       - LE security action, unused for BR/EDR
283  *
284  * Returns          BTM_SUCCESS   - already encrypted
285  *                  BTM_PENDING   - command will be returned in the callback
286  *                  BTM_WRONG_MODE- connection not up.
287  *                  BTM_BUSY      - security procedures are currently active
288  *                  BTM_MODE_UNSUPPORTED - if security manager not linked in.
289  *
290  ******************************************************************************/
291 tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
292                               tBT_TRANSPORT transport,
293                               tBTM_SEC_CALLBACK* p_callback, void* p_ref_data,
294                               tBTM_BLE_SEC_ACT sec_act);
295 
296 bool BTM_SecIsSecurityPending(const RawAddress& bd_addr);
297 
298 /*******************************************************************************
299  *
300  * Function         BTM_ConfirmReqReply
301  *
302  * Description      This function is called to confirm the numeric value for
303  *                  Simple Pairing in response to BTM_SP_CFM_REQ_EVT
304  *
305  * Parameters:      res           - result of the operation BTM_SUCCESS if
306  *                                  success
307  *                  bd_addr       - Address of the peer device
308  *
309  ******************************************************************************/
310 void BTM_ConfirmReqReply(tBTM_STATUS res, const RawAddress& bd_addr);
311 
312 /*******************************************************************************
313  *
314  * Function         BTM_PasskeyReqReply
315  *
316  * Description      This function is called to provide the passkey for
317  *                  Simple Pairing in response to BTM_SP_KEY_REQ_EVT
318  *
319  * Parameters:      res     - result of the operation BTM_SUCCESS if success
320  *                  bd_addr - Address of the peer device
321  *                  passkey - numeric value in the range of
322  *                  BTM_MIN_PASSKEY_VAL(0) -
323  *                  BTM_MAX_PASSKEY_VAL(999999(0xF423F)).
324  *
325  ******************************************************************************/
326 void BTM_PasskeyReqReply(tBTM_STATUS res, const RawAddress& bd_addr,
327                          uint32_t passkey);
328 
329 /*******************************************************************************
330  *
331  * Function         BTM_ReadLocalOobData
332  *
333  * Description      This function is called to read the local OOB data from
334  *                  LM
335  *
336  ******************************************************************************/
337 void BTM_ReadLocalOobData(void);
338 
339 /*******************************************************************************
340  *
341  * Function         BTM_RemoteOobDataReply
342  *
343  * Description      This function is called to provide the remote OOB data for
344  *                  Simple Pairing in response to BTM_SP_RMT_OOB_EVT
345  *
346  * Parameters:      bd_addr     - Address of the peer device
347  *                  c           - simple pairing Hash C.
348  *                  r           - simple pairing Randomizer  C.
349  *
350  ******************************************************************************/
351 void BTM_RemoteOobDataReply(tBTM_STATUS res, const RawAddress& bd_addr,
352                             const Octet16& c, const Octet16& r);
353 
354 /*******************************************************************************
355  *
356  * Function         BTM_BothEndsSupportSecureConnections
357  *
358  * Description      This function is called to check if both the local device
359  *                  and the peer device specified by bd_addr support BR/EDR
360  *                  Secure Connections.
361  *
362  * Parameters:      bd_addr - address of the peer
363  *
364  * Returns          true if BR/EDR Secure Connections are supported by both
365  *                  local and the remote device, else false.
366  *
367  ******************************************************************************/
368 bool BTM_BothEndsSupportSecureConnections(const RawAddress& bd_addr);
369 
370 /*******************************************************************************
371  *
372  * Function         BTM_PeerSupportsSecureConnections
373  *
374  * Description      This function is called to check if the peer supports
375  *                  BR/EDR Secure Connections.
376  *
377  * Parameters:      bd_addr - address of the peer
378  *
379  * Returns          true if BR/EDR Secure Connections are supported by the peer,
380  *                  else false.
381  *
382  ******************************************************************************/
383 bool BTM_PeerSupportsSecureConnections(const RawAddress& bd_addr);
384 
385 /*******************************************************************************
386  *
387  * Function         btm_sec_l2cap_access_req
388  *
389  * Description      This function is called by the L2CAP to grant permission to
390  *                  establish L2CAP connection to or from the peer device.
391  *
392  * Parameters:      bd_addr       - Address of the peer device
393  *                  psm           - L2CAP PSM
394  *                  is_originator - true if protocol above L2CAP originates
395  *                                  connection
396  *                  p_callback    - Pointer to callback function called if
397  *                                  this function returns PENDING after required
398  *                                  procedures are complete. MUST NOT BE NULL.
399  *
400  * Returns          tBTM_STATUS
401  *
402  ******************************************************************************/
403 tBTM_STATUS btm_sec_l2cap_access_req(const RawAddress& bd_addr, uint16_t psm,
404                                      bool is_originator,
405                                      tBTM_SEC_CALLBACK* p_callback,
406                                      void* p_ref_data);
407 
408 // Allow enforcing security by specific requirement (from shim layer).
409 tBTM_STATUS btm_sec_l2cap_access_req_by_requirement(
410     const RawAddress& bd_addr, uint16_t security_required, bool is_originator,
411     tBTM_SEC_CALLBACK* p_callback, void* p_ref_data);
412 
413 /*******************************************************************************
414  *
415  * Function         btm_sec_mx_access_request
416  *
417  * Description      This function is called by all Multiplexing Protocols
418  *during establishing connection to or from peer device to grant permission
419  *to establish application connection.
420  *
421  * Parameters:      bd_addr       - Address of the peer device
422  *                  psm           - L2CAP PSM
423  *                  is_originator - true if protocol above L2CAP originates
424  *                                  connection
425  *                  mx_proto_id   - protocol ID of the multiplexer
426  *                  mx_chan_id    - multiplexer channel to reach application
427  *                  p_callback    - Pointer to callback function called if
428  *                                  this function returns PENDING after
429  *required procedures are completed p_ref_data    - Pointer to any reference
430  *data needed by the the callback function.
431  *
432  * Returns          BTM_CMD_STARTED
433  *
434  ******************************************************************************/
435 tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr,
436                                       bool is_originator,
437                                       uint16_t security_requirement,
438                                       tBTM_SEC_CALLBACK* p_callback,
439                                       void* p_ref_data);
440 
441 /*******************************************************************************
442  *
443  * Function         btm_sec_conn_req
444  *
445  * Description      This function is when the peer device is requesting
446  *                  connection
447  *
448  * Returns          void
449  *
450  ******************************************************************************/
451 void btm_sec_conn_req(const RawAddress& bda, uint8_t* dc);
452 
453 /*******************************************************************************
454  *
455  * Function         btm_create_conn_cancel_complete
456  *
457  * Description      This function is called when the command complete message
458  *                  is received from the HCI for the create connection cancel
459  *                  command.
460  *
461  * Returns          void
462  *
463  ******************************************************************************/
464 void btm_create_conn_cancel_complete(uint8_t* p);
465 
466 /*******************************************************************************
467  *
468  * Function         btm_sec_dev_reset
469  *
470  * Description      This function should be called after device reset
471  *
472  * Returns          void
473  *
474  ******************************************************************************/
475 void btm_sec_dev_reset(void);
476 
477 /*******************************************************************************
478  *
479  * Function         btm_sec_abort_access_req
480  *
481  * Description      This function is called by the L2CAP or RFCOMM to abort
482  *                  the pending operation.
483  *
484  * Parameters:      bd_addr       - Address of the peer device
485  *
486  * Returns          void
487  *
488  ******************************************************************************/
489 void btm_sec_abort_access_req(const RawAddress& bd_addr);
490 
491 bool is_state_getting_name(void* data, void* context);
492 
493 /*******************************************************************************
494  *
495  * Function         btm_sec_rmt_name_request_complete
496  *
497  * Description      This function is called when remote name was obtained from
498  *                  the peer device
499  *
500  * Returns          void
501  *
502  ******************************************************************************/
503 void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr,
504                                        uint8_t* p_bd_name, tHCI_STATUS status);
505 
506 /*******************************************************************************
507  *
508  * Function         btm_sec_rmt_host_support_feat_evt
509  *
510  * Description      This function is called when the
511  *                  HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT is received
512  *
513  * Returns          void
514  *
515  ******************************************************************************/
516 void btm_sec_rmt_host_support_feat_evt(uint8_t* p);
517 
518 /*******************************************************************************
519  *
520  * Function         btm_io_capabilities_req
521  *
522  * Description      This function is called when LM request for the IO
523  *                  capability of the local device and
524  *                  if the OOB data is present for the device in the event
525  *
526  * Returns          void
527  *
528  ******************************************************************************/
529 void btm_io_capabilities_req(const RawAddress& p);
530 
531 /*******************************************************************************
532  *
533  * Function         btm_io_capabilities_rsp
534  *
535  * Description      This function is called when the IO capability of the
536  *                  specified device is received
537  *
538  * Returns          void
539  *
540  ******************************************************************************/
541 void btm_io_capabilities_rsp(uint8_t* p);
542 
543 /*******************************************************************************
544  *
545  * Function         btm_proc_sp_req_evt
546  *
547  * Description      This function is called to process/report
548  *                  HCI_USER_CONFIRMATION_REQUEST_EVT
549  *                  or HCI_USER_PASSKEY_REQUEST_EVT
550  *                  or HCI_USER_PASSKEY_NOTIFY_EVT
551  *
552  * Returns          void
553  *
554  ******************************************************************************/
555 void btm_proc_sp_req_evt(tBTM_SP_EVT event, uint8_t* p);
556 
557 /*******************************************************************************
558  *
559  * Function         btm_simple_pair_complete
560  *
561  * Description      This function is called when simple pairing process is
562  *                  complete
563  *
564  * Returns          void
565  *
566  ******************************************************************************/
567 void btm_simple_pair_complete(uint8_t* p);
568 
569 /*******************************************************************************
570  *
571  * Function         btm_rem_oob_req
572  *
573  * Description      This function is called to process/report
574  *                  HCI_REMOTE_OOB_DATA_REQUEST_EVT
575  *
576  * Returns          void
577  *
578  ******************************************************************************/
579 void btm_rem_oob_req(uint8_t* p);
580 
581 /*******************************************************************************
582  *
583  * Function         btm_read_local_oob_complete
584  *
585  * Description      This function is called when read local oob data is
586  *                  completed by the LM
587  *
588  * Returns          void
589  *
590  ******************************************************************************/
591 void btm_read_local_oob_complete(uint8_t* p);
592 
593 /*******************************************************************************
594  *
595  * Function         btm_sec_auth_complete
596  *
597  * Description      This function is when authentication of the connection is
598  *                  completed by the LM
599  *
600  * Returns          void
601  *
602  ******************************************************************************/
603 void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status);
604 
605 /*******************************************************************************
606  *
607  * Function         btm_sec_encrypt_change
608  *
609  * Description      This function is when encryption of the connection is
610  *                  completed by the LM
611  *
612  * Returns          void
613  *
614  ******************************************************************************/
615 void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status,
616                             uint8_t encr_enable);
617 
618 /*******************************************************************************
619  *
620  * Function         btm_sec_connected
621  *
622  * Description      This function is when a connection to the peer device is
623  *                  established
624  *
625  * Returns          void
626  *
627  ******************************************************************************/
628 void btm_sec_connected(const RawAddress& bda, uint16_t handle,
629                        tHCI_STATUS status, uint8_t enc_mode,
630                        tHCI_ROLE assigned_role = HCI_ROLE_PERIPHERAL);
631 
632 /*******************************************************************************
633  *
634  * Function         btm_sec_disconnect
635  *
636  * Description      This function is called to disconnect HCI link
637  *
638  * Returns          btm status
639  *
640  ******************************************************************************/
641 tBTM_STATUS btm_sec_disconnect(uint16_t handle, tHCI_STATUS reason);
642 
643 /*******************************************************************************
644  *
645  * Function         btm_sec_disconnected
646  *
647  * Description      This function is when a connection to the peer device is
648  *                  dropped
649  *
650  * Returns          void
651  *
652  ******************************************************************************/
653 void btm_sec_disconnected(uint16_t handle, tHCI_STATUS reason);
654 
655 /** This function is called when a new connection link key is generated */
656 void btm_sec_link_key_notification(const RawAddress& p_bda,
657                                    const Octet16& link_key, uint8_t key_type);
658 
659 /*******************************************************************************
660  *
661  * Function         btm_sec_link_key_request
662  *
663  * Description      This function is called when controller requests link key
664  *
665  * Returns          Pointer to the record or NULL
666  *
667  ******************************************************************************/
668 void btm_sec_link_key_request(uint8_t* p_event);
669 
670 /*******************************************************************************
671  *
672  * Function         btm_sec_pin_code_request
673  *
674  * Description      This function is called when controller requests PIN code
675  *
676  * Returns          Pointer to the record or NULL
677  *
678  ******************************************************************************/
679 void btm_sec_pin_code_request(uint8_t* p_event);
680 
681 /*******************************************************************************
682  *
683  * Function         btm_sec_update_clock_offset
684  *
685  * Description      This function is called to update clock offset
686  *
687  * Returns          void
688  *
689  ******************************************************************************/
690 void btm_sec_update_clock_offset(uint16_t handle, uint16_t clock_offset);
691 
692 /*******************************************************************************
693  *
694  * Function         btm_sec_execute_procedure
695  *
696  * Description      This function is called to start required security
697  *                  procedure.  There is a case when multiplexing protocol
698  *                  calls this function on the originating side, connection to
699  *                  the peer will not be established.  This function in this
700  *                  case performs only authorization.
701  *
702  * Returns          BTM_SUCCESS     - permission is granted
703  *                  BTM_CMD_STARTED - in process
704  *                  BTM_NO_RESOURCES  - permission declined
705  *
706  ******************************************************************************/
707 tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec);
708 
709 /*******************************************************************************
710  *
711  * Function         btm_sec_find_first_serv
712  *
713  * Description      Look for the first record in the service database
714  *                  with specified PSM
715  *
716  * Returns          Pointer to the record or NULL
717  *
718  ******************************************************************************/
719 tBTM_SEC_SERV_REC* btm_sec_find_first_serv(bool is_originator, uint16_t psm);
720 
721 bool is_sec_state_equal(void* data, void* context);
722 
723 /*******************************************************************************
724  *
725  * Function         btm_sec_find_dev_by_sec_state
726  *
727  * Description      Look for the record in the device database for the device
728  *                  which is being authenticated or encrypted
729  *
730  * Returns          Pointer to the record or NULL
731  *
732  ******************************************************************************/
733 tBTM_SEC_DEV_REC* btm_sec_find_dev_by_sec_state(uint8_t state);
734 
735 /*******************************************************************************
736  *
737  * Function         btm_sec_dev_rec_cback_event
738  *
739  * Description      This function calls the callback function with the given
740  *                  result and clear the callback function.
741  *
742  * Parameters:      void
743  *
744  ******************************************************************************/
745 void btm_sec_dev_rec_cback_event(tBTM_SEC_DEV_REC* p_dev_rec, tBTM_STATUS res,
746                                  bool is_le_transport);
747 
748 /*******************************************************************************
749  *
750  * Function         btm_sec_clear_ble_keys
751  *
752  * Description      This function is called to clear out the BLE keys.
753  *                  Typically when devices are removed in BTM_SecDeleteDevice,
754  *                  or when a new BT Link key is generated.
755  *
756  * Returns          void
757  *
758  ******************************************************************************/
759 void btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC* p_dev_rec);
760 
761 /*******************************************************************************
762  *
763  * Function         btm_sec_is_a_bonded_dev
764  *
765  * Description       Is the specified device is a bonded device
766  *
767  * Returns          true - dev is bonded
768  *
769  ******************************************************************************/
770 bool btm_sec_is_a_bonded_dev(const RawAddress& bda);
771 
772 /*******************************************************************************
773  *
774  * Function         btm_sec_set_peer_sec_caps
775  *
776  * Description      This function is called to set sm4 and rmt_sec_caps fields
777  *                  based on the available peer device features.
778  *
779  * Returns          void
780  *
781  ******************************************************************************/
782 void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
783                                bool sc_supported,
784                                bool hci_role_switch_supported,
785                                bool br_edr_supported, bool le_supported);
786 
787 /*******************************************************************************
788  *
789  * Function         btm_sec_cr_loc_oob_data_cback_event
790  *
791  * Description      This function is called to pass the local oob up to caller
792  *
793  * Returns          void
794  *
795  ******************************************************************************/
796 void btm_sec_cr_loc_oob_data_cback_event(const RawAddress& address,
797                                          tSMP_LOC_OOB_DATA loc_oob_data);
798 
799 // Return DEV_CLASS (uint8_t[3]) of bda. If record doesn't exist, create one.
800 const uint8_t* btm_get_dev_class(const RawAddress& bda);
801