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