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