From 9e2c7ca4daece4288552a5ec171e409efff723fd Mon Sep 17 00:00:00 2001
From: Hui Peng <phui@google.com>
Date: Sun, 15 Oct 2023 10:06:18 +0000
Subject: [PATCH] [Invisalign2] Separate security apis from bta_api.h

Bug: 301661850
Test: mma packages/modules/Bluetooth
Change-Id: I55c60f4a91ae0a2ca1cda2045b48d960af756b90
---
 system/bta/ag/bta_ag_rfc.cc                |   1 +
 system/bta/av/bta_av_int.h                 |   1 +
 system/bta/csis/csis_client.cc             |   1 +
 system/bta/dm/bta_dm_act.cc                |   1 +
 system/bta/dm/bta_dm_int.h                 |   1 +
 system/bta/dm/bta_dm_sec_int.h             |   1 +
 system/bta/hf_client/bta_hf_client_rfc.cc  |   1 +
 system/bta/include/bta_api.h               | 493 +-------------------
 system/bta/include/bta_api_data_types.h    |  65 +++
 system/bta/include/bta_jv_api.h            |   1 +
 system/bta/include/bta_sec_api.h           | 496 +++++++++++++++++++++
 system/bta/jv/bta_jv_int.h                 |   1 +
 system/bta/pan/bta_pan_int.h               |   1 +
 system/bta/test/common/bta_dm_api_mock.h   |   1 +
 system/btif/co/bta_dm_co.cc                |   1 +
 system/btif/include/btif_dm.h              |   1 +
 system/btif/src/btif_hd.cc                 |   1 +
 system/btif/src/btif_hh.cc                 |   1 +
 system/btif/src/btif_iot_config.cc         |   1 +
 system/btif/src/btif_sock.cc               |   2 +-
 system/stack/avct/avct_api.cc              |   1 +
 system/stack/avct/avct_bcb_act.cc          |   2 +-
 system/stack/avct/avct_lcb_act.cc          |   1 +
 system/stack/avdt/avdt_api.cc              |   2 +-
 system/stack/bnep/bnep_api.cc              |   1 +
 system/stack/bnep/bnep_main.cc             |   1 +
 system/stack/hid/hidd_conn.cc              |   1 +
 system/stack/hid/hidh_conn.cc              |   2 +-
 system/test/mock/mock_bta_dm_api.h         |   1 +
 system/test/mock/mock_btif_co_bta_dm_co.cc |   1 +
 system/test/mock/mock_btif_dm.cc           |   1 +
 31 files changed, 590 insertions(+), 496 deletions(-)
 create mode 100644 system/bta/include/bta_api_data_types.h
 create mode 100644 system/bta/include/bta_sec_api.h

diff --git a/system/bta/ag/bta_ag_rfc.cc b/system/bta/ag/bta_ag_rfc.cc
index f07e07d980a..d56e48cf6a0 100644
--- a/system/bta/ag/bta_ag_rfc.cc
+++ b/system/bta/ag/bta_ag_rfc.cc
@@ -29,6 +29,7 @@
 #include <cstring>
 
 #include "bta/ag/bta_ag_int.h"
+#include "bta/include/bta_sec_api.h"
 #include "osi/include/osi.h"
 #include "stack/include/main_thread.h"
 #include "stack/include/port_api.h"
diff --git a/system/bta/av/bta_av_int.h b/system/bta/av/bta_av_int.h
index ecaef26db96..4cf4c6fad23 100644
--- a/system/bta/av/bta_av_int.h
+++ b/system/bta/av/bta_av_int.h
@@ -28,6 +28,7 @@
 #include <string>
 
 #include "bta/include/bta_av_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "bta/sys/bta_sys.h"
 #include "include/hardware/bt_av.h"
 #include "osi/include/list.h"
diff --git a/system/bta/csis/csis_client.cc b/system/bta/csis/csis_client.cc
index ed5547855c0..f5572eaf5a1 100644
--- a/system/bta/csis/csis_client.cc
+++ b/system/bta/csis/csis_client.cc
@@ -29,6 +29,7 @@
 
 #include "advertise_data_parser.h"
 #include "bta_api.h"
+#include "bta_sec_api.h"
 #include "bta_csis_api.h"
 #include "bta_gatt_api.h"
 #include "bta_gatt_queue.h"
diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc
index 2d19719240f..f5cfcb5116f 100644
--- a/system/bta/dm/bta_dm_act.cc
+++ b/system/bta/dm/bta_dm_act.cc
@@ -37,6 +37,7 @@
 #include "bta/dm/bta_dm_gatt_client.h"
 #include "bta/dm/bta_dm_int.h"
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "bta/include/bta_sdp_api.h"
 #include "bta/dm/bta_dm_sec_int.h"
 #include "bta/sys/bta_sys.h"
diff --git a/system/bta/dm/bta_dm_int.h b/system/bta/dm/bta_dm_int.h
index d76164d5987..8a203d0a6e3 100644
--- a/system/bta/dm/bta_dm_int.h
+++ b/system/bta/dm/bta_dm_int.h
@@ -31,6 +31,7 @@
 
 #include "bt_target.h"  // Must be first to define build configuration
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "bta/include/bta_gatt_api.h"
 #include "bta/sys/bta_sys.h"
 #include "main/shim/dumpsys.h"
diff --git a/system/bta/dm/bta_dm_sec_int.h b/system/bta/dm/bta_dm_sec_int.h
index 53c3ebe5237..f52a5542fd5 100644
--- a/system/bta/dm/bta_dm_sec_int.h
+++ b/system/bta/dm/bta_dm_sec_int.h
@@ -19,6 +19,7 @@
 #include <memory>
 
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "osi/include/osi.h"  // UNUSED_ATTR
 
 typedef struct {
diff --git a/system/bta/hf_client/bta_hf_client_rfc.cc b/system/bta/hf_client/bta_hf_client_rfc.cc
index e9e73e5028e..55dcf60d6a2 100644
--- a/system/bta/hf_client/bta_hf_client_rfc.cc
+++ b/system/bta/hf_client/bta_hf_client_rfc.cc
@@ -26,6 +26,7 @@
 
 #include <cstdint>
 
+#include "bta/include/bta_sec_api.h"
 #include "bta/hf_client/bta_hf_client_int.h"
 #include "osi/include/allocator.h"
 #include "osi/include/osi.h"  // UNUSED_ATTR
diff --git a/system/bta/include/bta_api.h b/system/bta/include/bta_api.h
index 46c88835718..f3671a4bf4d 100644
--- a/system/bta/include/bta_api.h
+++ b/system/bta/include/bta_api.h
@@ -43,41 +43,8 @@
 #include "types/bluetooth/uuid.h"
 #include "types/bt_transport.h"
 #include "types/raw_address.h"
+#include "bta_api_data_types.h"
 
-/*****************************************************************************
- *  Constants and data types
- ****************************************************************************/
-
-/* Status Return Value */
-typedef enum : uint8_t {
-  BTA_SUCCESS = 0, /* Successful operation. */
-  BTA_FAILURE = 1, /* Generic failure. */
-  BTA_PENDING = 2, /* API cannot be completed right now */
-  BTA_BUSY = 3,
-  BTA_NO_RESOURCES = 4,
-  BTA_WRONG_MODE = 5,
-} tBTA_STATUS;
-
-#ifndef CASE_RETURN_TEXT
-#define CASE_RETURN_TEXT(code) \
-  case code:                   \
-    return #code
-#endif
-
-inline std::string bta_status_text(const tBTA_STATUS& status) {
-  switch (status) {
-    CASE_RETURN_TEXT(BTA_SUCCESS);
-    CASE_RETURN_TEXT(BTA_FAILURE);
-    CASE_RETURN_TEXT(BTA_PENDING);
-    CASE_RETURN_TEXT(BTA_BUSY);
-    CASE_RETURN_TEXT(BTA_NO_RESOURCES);
-    CASE_RETURN_TEXT(BTA_WRONG_MODE);
-    default:
-      return base::StringPrintf("UNKNOWN[%d]", status);
-  }
-}
-
-#undef CASE_RETURN_TEXT
 
 /*
  * Service ID
@@ -121,15 +88,6 @@ typedef uint8_t tBTA_SERVICE_ID;
 
 typedef uint32_t tBTA_SERVICE_MASK;
 
-/* Security Setting Mask */
-#define BTA_SEC_AUTHENTICATE \
-  (BTM_SEC_IN_AUTHENTICATE | \
-   BTM_SEC_OUT_AUTHENTICATE) /* Authentication required. */
-#define BTA_SEC_ENCRYPT \
-  (BTM_SEC_IN_ENCRYPT | BTM_SEC_OUT_ENCRYPT) /* Encryption required. */
-
-typedef uint16_t tBTA_SEC;
-
 #define BTA_APP_ID_PAN_MULTI 0xFE /* app id for pan multiple connection */
 #define BTA_ALL_APP_ID 0xFF
 
@@ -224,116 +182,6 @@ typedef enum: uint8_t {
   BTA_DM_LINK_UP_FAILED_EVT = 34,    /* Create connection failed event */
 } tBTA_DM_ACL_EVT;
 
-typedef enum : uint8_t {
-  /* Security Callback Events */
-  BTA_DM_PIN_REQ_EVT = 2,          /* PIN request. */
-  BTA_DM_AUTH_CMPL_EVT = 3,        /* Authentication complete indication. */
-  BTA_DM_AUTHORIZE_EVT = 4,        /* Authorization request. */
-  BTA_DM_BOND_CANCEL_CMPL_EVT = 9, /* Bond cancel complete indication */
-  BTA_DM_SP_CFM_REQ_EVT = 10,   /* Simple Pairing User Confirmation request */
-  BTA_DM_SP_KEY_NOTIF_EVT = 11, /* Simple Pairing Passkey Notification */
-  BTA_DM_BLE_KEY_EVT = 15,      /* BLE SMP key event for peer device keys */
-  BTA_DM_BLE_SEC_REQ_EVT = 16,  /* BLE SMP security request */
-  BTA_DM_BLE_PASSKEY_NOTIF_EVT = 17, /* SMP passkey notification event */
-  BTA_DM_BLE_PASSKEY_REQ_EVT = 18,   /* SMP passkey request event */
-  BTA_DM_BLE_OOB_REQ_EVT = 19,       /* SMP OOB request event */
-  BTA_DM_BLE_LOCAL_IR_EVT = 20,      /* BLE local IR event */
-  BTA_DM_BLE_LOCAL_ER_EVT = 21,      /* BLE local ER event */
-  BTA_DM_BLE_NC_REQ_EVT = 22,        /* SMP Numeric Comparison request event */
-  BTA_DM_SP_RMT_OOB_EXT_EVT =
-      23, /* Simple Pairing Remote OOB Extended Data request. */
-  BTA_DM_BLE_AUTH_CMPL_EVT = 24, /* BLE Auth complete */
-  BTA_DM_DEV_UNPAIRED_EVT = 25,
-  BTA_DM_ENER_INFO_READ = 28,      /* Energy info read */
-  BTA_DM_BLE_SC_OOB_REQ_EVT = 29,  /* SMP SC OOB request event */
-  BTA_DM_BLE_CONSENT_REQ_EVT = 30, /* SMP consent request event */
-  BTA_DM_BLE_SC_CR_LOC_OOB_EVT = 31, /* SMP SC Create Local OOB request event */
-  BTA_DM_REPORT_BONDING_EVT = 32,    /*handle for pin or key missing*/
-  BTA_DM_LE_ADDR_ASSOC_EVT = 33,     /* identity address association event */
-  BTA_DM_SIRK_VERIFICATION_REQ_EVT = 35,
-} tBTA_DM_SEC_EVT;
-
-/* Structure associated with BTA_DM_PIN_REQ_EVT */
-typedef struct {
-  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
-   * order */
-  RawAddress bd_addr;  /* BD address peer device. */
-  DEV_CLASS dev_class; /* Class of Device */
-  BD_NAME bd_name;     /* Name of peer device. */
-  bool min_16_digit;   /* true if the pin returned must be at least 16 digits */
-} tBTA_DM_PIN_REQ;
-
-/* BLE related definition */
-
-#define BTA_DM_AUTH_FAIL_BASE (HCI_ERR_MAX_ERR + 10)
-
-/* Converts SMP error codes defined in smp_api.h to SMP auth fail reasons below.
- */
-#define BTA_DM_AUTH_CONVERT_SMP_CODE(x) (BTA_DM_AUTH_FAIL_BASE + (x))
-
-#define BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL \
-  (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_AUTH_FAIL)
-#define BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL \
-  (BTA_DM_AUTH_FAIL_BASE + SMP_CONFIRM_VALUE_ERR)
-#define BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT \
-  (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_NOT_SUPPORT)
-#define BTA_DM_AUTH_SMP_UNKNOWN_ERR \
-  (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_FAIL_UNKNOWN)
-#define BTA_DM_AUTH_SMP_CONN_TOUT (BTA_DM_AUTH_FAIL_BASE + SMP_CONN_TOUT)
-
-typedef uint8_t tBTA_LE_KEY_TYPE; /* can be used as a bit mask */
-
-typedef union {
-  tBTM_LE_PENC_KEYS penc_key;  /* received peer encryption key */
-  tBTM_LE_PCSRK_KEYS psrk_key; /* received peer device SRK */
-  tBTM_LE_PID_KEYS pid_key;    /* peer device ID key */
-  tBTM_LE_LENC_KEYS
-      lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
-  tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
-  tBTM_LE_PID_KEYS lid_key; /* local device ID key for the particular remote */
-} tBTA_LE_KEY_VALUE;
-
-#define BTA_BLE_LOCAL_KEY_TYPE_ID 1
-#define BTA_BLE_LOCAL_KEY_TYPE_ER 2
-typedef uint8_t tBTA_DM_BLE_LOCAL_KEY_MASK;
-
-typedef struct {
-  Octet16 ir;
-  Octet16 irk;
-  Octet16 dhk;
-} tBTA_BLE_LOCAL_ID_KEYS;
-
-#define BTA_DM_SEC_GRANTED BTA_SUCCESS
-#define BTA_DM_SEC_PAIR_NOT_SPT BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT
-typedef uint8_t tBTA_DM_BLE_SEC_GRANT;
-
-/* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */
-typedef struct {
-  RawAddress bd_addr; /* peer address */
-  BD_NAME bd_name; /* peer device name */
-} tBTA_DM_BLE_SEC_REQ;
-
-typedef struct {
-  RawAddress bd_addr; /* peer address */
-  tBTM_LE_KEY_TYPE key_type;
-  tBTM_LE_KEY_VALUE* p_key_value;
-} tBTA_DM_BLE_KEY;
-
-/* Structure associated with BTA_DM_AUTH_CMPL_EVT */
-typedef struct {
-  RawAddress bd_addr;  /* BD address peer device. */
-  BD_NAME bd_name;     /* Name of peer device. */
-  bool key_present;    /* Valid link key value in key element */
-  LinkKey key;         /* Link key associated with peer device. */
-  uint8_t key_type;    /* The type of Link Key */
-  bool success;        /* true of authentication succeeded, false if failed. */
-  tHCI_REASON
-      fail_reason; /* The HCI reason/error code for when success=false */
-  tBLE_ADDR_TYPE addr_type; /* Peer device address type */
-  tBT_DEVICE_TYPE dev_type;
-  bool is_ctkd; /* True if key is derived using CTKD procedure */
-} tBTA_DM_AUTH_CMPL;
-
 /* Structure associated with BTA_DM_LINK_UP_EVT */
 typedef struct {
   RawAddress bd_addr; /* BD address peer device. */
@@ -355,82 +203,6 @@ typedef struct {
   tHCI_STATUS status;
 } tBTA_DM_LINK_DOWN;
 
-/* Structure associated with BTA_DM_DEV_UNPAIRED_EVT */
-typedef struct {
-  RawAddress bd_addr; /* BD address peer device. */
-  tBT_TRANSPORT transport_link_type;
-} tBTA_DM_UNPAIR;
-
-#define BTA_AUTH_SP_YES                                                       \
-  BTM_AUTH_SP_YES /* 1 MITM Protection Required - Single Profile/non-bonding  \
-                    Use IO Capabilities to determine authentication procedure \
-                    */
-
-#define BTA_AUTH_DD_BOND \
-  BTM_AUTH_DD_BOND /* 2 this bit is set for dedicated bonding */
-#define BTA_AUTH_GEN_BOND \
-  BTM_AUTH_SPGB_NO /* 4 this bit is set for general bonding */
-#define BTA_AUTH_BONDS \
-  BTM_AUTH_BONDS /* 6 the general/dedicated bonding bits  */
-
-#define BTA_LE_AUTH_REQ_SC_MITM_BOND BTM_LE_AUTH_REQ_SC_MITM_BOND /* 1101 */
-
-/* Structure associated with BTA_DM_SP_CFM_REQ_EVT */
-typedef struct {
-  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
-   * order */
-  RawAddress bd_addr;  /* peer address */
-  DEV_CLASS dev_class; /* peer CoD */
-  BD_NAME bd_name;     /* peer device name */
-  uint32_t num_val; /* the numeric value for comparison. If just_works, do not
-                       show this number to UI */
-  bool just_works;  /* true, if "Just Works" association model */
-  tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
-  tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
-  tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of local device */
-  tBTM_IO_CAP rmt_io_caps;    // IO Capabilities of remote device
-} tBTA_DM_SP_CFM_REQ;
-
-/* Structure associated with BTA_DM_SP_KEY_NOTIF_EVT */
-typedef struct {
-  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
-   * order */
-  RawAddress bd_addr;  /* peer address */
-  DEV_CLASS dev_class; /* peer CoD */
-  BD_NAME bd_name;     /* peer device name */
-  uint32_t passkey; /* the numeric value for comparison. If just_works, do not
-                       show this number to UI */
-} tBTA_DM_SP_KEY_NOTIF;
-
-/* Structure associated with BTA_DM_SP_RMT_OOB_EVT */
-typedef struct {
-  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
-   * order */
-  RawAddress bd_addr;  /* peer address */
-  DEV_CLASS dev_class; /* peer CoD */
-  BD_NAME bd_name;     /* peer device name */
-} tBTA_DM_SP_RMT_OOB;
-
-/* Structure associated with BTA_DM_BOND_CANCEL_CMPL_EVT */
-typedef struct {
-  tBTA_STATUS result; /* true of bond cancel succeeded, false if failed. */
-} tBTA_DM_BOND_CANCEL_CMPL;
-
-/* Add to remove bond of key missing RC */
-typedef struct {
-  RawAddress bd_addr;
-} tBTA_DM_RC_UNPAIR;
-
-typedef struct {
-  Octet16 local_oob_c; /* Local OOB Data Confirmation/Commitment */
-  Octet16 local_oob_r; /* Local OOB Data Randomizer */
-} tBTA_DM_LOC_OOB_DATA;
-
-typedef struct {
-  RawAddress pairing_bda;
-  RawAddress id_addr;
-} tBTA_DM_PROC_ID_ADDR;
-
 typedef union {
   tBTA_DM_LINK_UP link_up;        /* ACL connection up event */
   tBTA_DM_LINK_UP_FAILED link_up_failed; /* ACL connection up failure event */
@@ -439,28 +211,6 @@ typedef union {
 
 typedef void(tBTA_DM_ACL_CBACK)(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data);
 
-/* Union of all security callback structures */
-typedef union {
-  tBTA_DM_PIN_REQ pin_req;        /* PIN request. */
-  tBTA_DM_AUTH_CMPL auth_cmpl;    /* Authentication complete indication. */
-  tBTA_DM_UNPAIR dev_unpair;      /* Remove bonding complete indication */
-  tBTA_DM_SP_CFM_REQ cfm_req;     /* user confirm request */
-  tBTA_DM_SP_KEY_NOTIF key_notif; /* passkey notification */
-  tBTA_DM_SP_RMT_OOB rmt_oob;     /* remote oob */
-  tBTA_DM_BOND_CANCEL_CMPL
-      bond_cancel_cmpl;               /* Bond Cancel Complete indication */
-  tBTA_DM_BLE_SEC_REQ ble_req;        /* BLE SMP related request */
-  tBTA_DM_BLE_KEY ble_key;            /* BLE SMP keys used when pairing */
-  tBTA_BLE_LOCAL_ID_KEYS ble_id_keys; /* IR event */
-  Octet16 ble_er;                     /* ER event data */
-  tBTA_DM_LOC_OOB_DATA local_oob_data; /* Local OOB data generated by us */
-  tBTA_DM_RC_UNPAIR delete_key_RC_to_unpair;
-  tBTA_DM_PROC_ID_ADDR proc_id_addr; /* Identity address event */
-} tBTA_DM_SEC;
-
-/* Security callback */
-typedef void(tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data);
-
 #define BTA_DM_BLE_PF_LIST_LOGIC_OR 1
 #define BTA_DM_BLE_PF_FILT_LOGIC_OR 0
 
@@ -852,107 +602,6 @@ void BTA_DmDiscover(const RawAddress& bd_addr, tBTA_DM_SEARCH_CBACK* p_cback,
 tBTA_STATUS BTA_DmGetCachedRemoteName(const RawAddress& remote_device,
                                       uint8_t** pp_cached_name);
 
-/*******************************************************************************
- *
- * Function         BTA_DmBond
- *
- * Description      This function initiates a bonding procedure with a peer
- *                  device by designated transport.  The bonding procedure
- *                  enables authentication and optionally encryption on the
- *                  Bluetooth link.
- *
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmBond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
-                tBT_TRANSPORT transport, tBT_DEVICE_TYPE device_type);
-
-/*******************************************************************************
- *
- * Function         BTA_DmBondCancel
- *
- * Description      This function cancels a bonding procedure with a peer
- *                  device.
- *
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmBondCancel(const RawAddress& bd_addr);
-
-/*******************************************************************************
- *
- * Function         BTA_DmPinReply
- *
- * Description      This function provides a PIN when one is requested by DM
- *                  during a bonding procedure.  The application should call
- *                  this function after the security callback is called with
- *                  a BTA_DM_PIN_REQ_EVT.
- *
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmPinReply(const RawAddress& bd_addr, bool accept, uint8_t pin_len,
-                    uint8_t* p_pin);
-
-/*******************************************************************************
- *
- * Function         BTA_DmLocalOob
- *
- * Description      This function retrieves the OOB data from local controller.
- *                  The result is reported by bta_dm_co_loc_oob().
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmLocalOob(void);
-
-/*******************************************************************************
- *
- * Function         BTA_DmConfirm
- *
- * Description      This function accepts or rejects the numerical value of the
- *                  Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmConfirm(const RawAddress& bd_addr, bool accept);
-
-/*******************************************************************************
- *
- * Function         BTA_DmAddDevice
- *
- * Description      This function adds a device to the security database list
- *                  of peer devices. This function would typically be called
- *                  at system startup to initialize the security database with
- *                  known peer devices.  This is a direct execution function
- *                  that may lock task scheduling on some platforms.
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
-                     const LinkKey& link_key, uint8_t key_type,
-                     uint8_t pin_length);
-
-/*******************************************************************************
- *
- * Function         BTA_DmRemoveDevice
- *
- * Description      This function removes a device from the security database.
- *                  This is a direct execution function that may lock task
- *                  scheduling on some platforms.
- *
- *
- * Returns          BTA_SUCCESS if successful.
- *                  BTA_FAIL if operation failed.
- *
- ******************************************************************************/
-tBTA_STATUS BTA_DmRemoveDevice(const RawAddress& bd_addr);
-
 /*******************************************************************************
  *
  * Function         BTA_GetEirService
@@ -1012,90 +661,6 @@ tBTA_STATUS BTA_DmSetLocalDiRecord(tSDP_DI_RECORD* p_device_info,
 void BTA_DmCloseACL(const RawAddress& bd_addr, bool remove_dev,
                     tBT_TRANSPORT transport);
 
-/* BLE related API functions */
-/*******************************************************************************
- *
- * Function         BTA_DmBleSecurityGrant
- *
- * Description      Grant security request access.
- *
- * Parameters:      bd_addr          - BD address of the peer
- *                  res              - security grant status.
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
-                            tBTA_DM_BLE_SEC_GRANT res);
-
-/*******************************************************************************
- *
- * Function         BTA_DmBlePasskeyReply
- *
- * Description      Send BLE SMP passkey reply.
- *
- * Parameters:      bd_addr          - BD address of the peer
- *                  accept           - passkey entry sucessful or declined.
- *                  passkey          - passkey value, must be a 6 digit number,
- *                                     can be lead by 0.
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmBlePasskeyReply(const RawAddress& bd_addr, bool accept,
-                           uint32_t passkey);
-
-/*******************************************************************************
- *
- * Function         BTA_DmBleConfirmReply
- *
- * Description      Send BLE SMP SC user confirmation reply.
- *
- * Parameters:      bd_addr          - BD address of the peer
- *                  accept           - numbers to compare are the same or
- *                                     different.
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmBleConfirmReply(const RawAddress& bd_addr, bool accept);
-
-/*******************************************************************************
- *
- * Function         BTA_DmAddBleDevice
- *
- * Description      Add a BLE device.  This function will be normally called
- *                  during host startup to restore all required information
- *                  for a LE device stored in the NVRAM.
- *
- * Parameters:      bd_addr          - BD address of the peer
- *                  dev_type         - Remote device's device type.
- *                  addr_type        - LE device address type.
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmAddBleDevice(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
-                        tBT_DEVICE_TYPE dev_type);
-
-/*******************************************************************************
- *
- * Function         BTA_DmAddBleKey
- *
- * Description      Add/modify LE device information.  This function will be
- *                  normally called during host startup to restore all required
- *                  information stored in the NVRAM.
- *
- * Parameters:      bd_addr          - BD address of the peer
- *                  p_le_key         - LE key values.
- *                  key_type         - LE SMP key type.
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmAddBleKey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
-                     tBTM_LE_KEY_TYPE key_type);
-
 /*******************************************************************************
  *
  * Function         BTA_DmSetBlePrefConnParams
@@ -1118,33 +683,6 @@ void BTA_DmSetBlePrefConnParams(const RawAddress& bd_addr,
                                 uint16_t peripheral_latency,
                                 uint16_t supervision_tout);
 
-/*******************************************************************************
- *
- * Function         BTA_DmSetEncryption
- *
- * Description      This function is called to ensure that connection is
- *                  encrypted.  Should be called only on an open connection.
- *                  Typically only needed for connections that first want to
- *                  bring up unencrypted links, then later encrypt them.
- *
- * Parameters:      bd_addr       - Address of the peer device
- *                  transport     - transport of the link to be encruypted
- *                  p_callback    - Pointer to callback function to indicat the
- *                                  link encryption status
- *                  sec_act       - This is the security action to indicate
- *                                  what kind of BLE security level is required
- *                                  for the BLE link if BLE is supported
- *                                  Note: This parameter is ignored for
- *                                        BR/EDR or if BLE is not supported.
- *
- * Returns          void
- *
- *
- ******************************************************************************/
-void BTA_DmSetEncryption(const RawAddress& bd_addr, tBT_TRANSPORT transport,
-                         tBTA_DM_ENCRYPT_CBACK* p_callback,
-                         tBTM_BLE_SEC_ACT sec_act);
-
 /*******************************************************************************
  *
  * Function         BTA_DmBleObserve
@@ -1196,35 +734,6 @@ void BTA_DmBleScan(bool start, uint8_t duration, bool low_latency_scan = false);
  ******************************************************************************/
 void BTA_DmBleCsisObserve(bool observe, tBTA_DM_SEARCH_CBACK* p_results_cb);
 
-/*******************************************************************************
- *
- * Function         BTA_DmSirkSecCbRegister
- *
- * Description      This procedure registeres in requested a callback for
- *                  verification by CSIS potential set member.
- *
- * Parameters       p_cback     - callback to member verificator
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmSirkSecCbRegister(tBTA_DM_SEC_CBACK* p_cback);
-
-/*******************************************************************************
- *
- * Function         BTA_DmSirkConfirmDeviceReply
- *
- * Description      This procedure confirms requested to validate set device.
- *
- * Parameters       bd_addr     - BD address of the peer
- *                  accept      - True if device is authorized by CSIS, false
- *                                otherwise.
- *
- * Returns          void
- *
- ******************************************************************************/
-void BTA_DmSirkConfirmDeviceReply(const RawAddress& bd_addr, bool accept);
-
 /*******************************************************************************
  *
  * Function         BTA_DmBleConfigLocalPrivacy
diff --git a/system/bta/include/bta_api_data_types.h b/system/bta/include/bta_api_data_types.h
new file mode 100644
index 00000000000..4a76cc82828
--- /dev/null
+++ b/system/bta/include/bta_api_data_types.h
@@ -0,0 +1,65 @@
+/******************************************************************************
+ *
+ * Copyright 2023 The Android Open Source Project
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <cstdint>
+#include <string>
+#include <base/strings/stringprintf.h>
+#include "types/raw_address.h"
+
+/*****************************************************************************
+ *  Constants and data types
+ ****************************************************************************/
+
+/* Status Return Value */
+typedef enum : uint8_t {
+  BTA_SUCCESS = 0, /* Successful operation. */
+  BTA_FAILURE = 1, /* Generic failure. */
+  BTA_PENDING = 2, /* API cannot be completed right now */
+  BTA_BUSY = 3,
+  BTA_NO_RESOURCES = 4,
+  BTA_WRONG_MODE = 5,
+} tBTA_STATUS;
+
+#ifndef CASE_RETURN_TEXT
+#define CASE_RETURN_TEXT(code) \
+  case code:                   \
+    return #code
+#endif
+
+inline std::string bta_status_text(const tBTA_STATUS& status) {
+  switch (status) {
+    CASE_RETURN_TEXT(BTA_SUCCESS);
+    CASE_RETURN_TEXT(BTA_FAILURE);
+    CASE_RETURN_TEXT(BTA_PENDING);
+    CASE_RETURN_TEXT(BTA_BUSY);
+    CASE_RETURN_TEXT(BTA_NO_RESOURCES);
+    CASE_RETURN_TEXT(BTA_WRONG_MODE);
+    default:
+      return base::StringPrintf("UNKNOWN[%d]", status);
+  }
+}
+
+#undef CASE_RETURN_TEXT
+
+typedef struct {
+  RawAddress pairing_bda;
+  RawAddress id_addr;
+} tBTA_DM_PROC_ID_ADDR;
+
diff --git a/system/bta/include/bta_jv_api.h b/system/bta/include/bta_jv_api.h
index aa9dcfa8a1b..440e24944fa 100644
--- a/system/bta/include/bta_jv_api.h
+++ b/system/bta/include/bta_jv_api.h
@@ -29,6 +29,7 @@
 
 #include "bt_target.h"  // Must be first to define build configuration
 #include "bta/include/bta_api.h"
+#include "bta_sec_api.h"
 #include "stack/include/bt_hdr.h"
 #include "stack/include/l2c_api.h"
 #include "types/bluetooth/uuid.h"
diff --git a/system/bta/include/bta_sec_api.h b/system/bta/include/bta_sec_api.h
new file mode 100644
index 00000000000..d06fc43bbe1
--- /dev/null
+++ b/system/bta/include/bta_sec_api.h
@@ -0,0 +1,496 @@
+/******************************************************************************
+ *
+ * Copyright 2023 The Android Open Source Project
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <base/strings/stringprintf.h>
+#include <base/functional/callback.h>
+
+#include <cstdint>
+#include <vector>
+
+#include "bt_target.h"  // Must be first to define build configuration
+#include "stack/include/bt_octets.h"
+#include "stack/include/bt_types.h"
+#include "stack/include/btm_api_types.h"
+#include "stack/include/btm_ble_api_types.h"
+#include "stack/include/hci_error_code.h"
+#include "types/ble_address_with_type.h"
+#include "types/bt_transport.h"
+#include "types/raw_address.h"
+
+#include "bta_api_data_types.h"
+
+/* Security Setting Mask */
+#define BTA_SEC_AUTHENTICATE \
+  (BTM_SEC_IN_AUTHENTICATE | \
+   BTM_SEC_OUT_AUTHENTICATE) /* Authentication required. */
+#define BTA_SEC_ENCRYPT \
+  (BTM_SEC_IN_ENCRYPT | BTM_SEC_OUT_ENCRYPT) /* Encryption required. */
+
+typedef uint16_t tBTA_SEC;
+
+typedef enum : uint8_t {
+  /* Security Callback Events */
+  BTA_DM_PIN_REQ_EVT = 2,          /* PIN request. */
+  BTA_DM_AUTH_CMPL_EVT = 3,        /* Authentication complete indication. */
+  BTA_DM_AUTHORIZE_EVT = 4,        /* Authorization request. */
+  BTA_DM_BOND_CANCEL_CMPL_EVT = 9, /* Bond cancel complete indication */
+  BTA_DM_SP_CFM_REQ_EVT = 10,   /* Simple Pairing User Confirmation request */
+  BTA_DM_SP_KEY_NOTIF_EVT = 11, /* Simple Pairing Passkey Notification */
+  BTA_DM_BLE_KEY_EVT = 15,      /* BLE SMP key event for peer device keys */
+  BTA_DM_BLE_SEC_REQ_EVT = 16,  /* BLE SMP security request */
+  BTA_DM_BLE_PASSKEY_NOTIF_EVT = 17, /* SMP passkey notification event */
+  BTA_DM_BLE_PASSKEY_REQ_EVT = 18,   /* SMP passkey request event */
+  BTA_DM_BLE_OOB_REQ_EVT = 19,       /* SMP OOB request event */
+  BTA_DM_BLE_LOCAL_IR_EVT = 20,      /* BLE local IR event */
+  BTA_DM_BLE_LOCAL_ER_EVT = 21,      /* BLE local ER event */
+  BTA_DM_BLE_NC_REQ_EVT = 22,        /* SMP Numeric Comparison request event */
+  BTA_DM_SP_RMT_OOB_EXT_EVT =
+      23, /* Simple Pairing Remote OOB Extended Data request. */
+  BTA_DM_BLE_AUTH_CMPL_EVT = 24, /* BLE Auth complete */
+  BTA_DM_DEV_UNPAIRED_EVT = 25,
+  BTA_DM_ENER_INFO_READ = 28,      /* Energy info read */
+  BTA_DM_BLE_SC_OOB_REQ_EVT = 29,  /* SMP SC OOB request event */
+  BTA_DM_BLE_CONSENT_REQ_EVT = 30, /* SMP consent request event */
+  BTA_DM_BLE_SC_CR_LOC_OOB_EVT = 31, /* SMP SC Create Local OOB request event */
+  BTA_DM_REPORT_BONDING_EVT = 32,    /*handle for pin or key missing*/
+  BTA_DM_LE_ADDR_ASSOC_EVT = 33,     /* identity address association event */
+  BTA_DM_SIRK_VERIFICATION_REQ_EVT = 35,
+} tBTA_DM_SEC_EVT;
+
+/* Structure associated with BTA_DM_PIN_REQ_EVT */
+typedef struct {
+  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
+   * order */
+  RawAddress bd_addr;  /* BD address peer device. */
+  DEV_CLASS dev_class; /* Class of Device */
+  BD_NAME bd_name;     /* Name of peer device. */
+  bool min_16_digit;   /* true if the pin returned must be at least 16 digits */
+} tBTA_DM_PIN_REQ;
+
+/* BLE related definition */
+
+#define BTA_DM_AUTH_FAIL_BASE (HCI_ERR_MAX_ERR + 10)
+
+/* Converts SMP error codes defined in smp_api.h to SMP auth fail reasons below.
+ */
+#define BTA_DM_AUTH_CONVERT_SMP_CODE(x) (BTA_DM_AUTH_FAIL_BASE + (x))
+
+#define BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL \
+  (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_AUTH_FAIL)
+#define BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL \
+  (BTA_DM_AUTH_FAIL_BASE + SMP_CONFIRM_VALUE_ERR)
+#define BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT \
+  (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_NOT_SUPPORT)
+#define BTA_DM_AUTH_SMP_UNKNOWN_ERR \
+  (BTA_DM_AUTH_FAIL_BASE + SMP_PAIR_FAIL_UNKNOWN)
+#define BTA_DM_AUTH_SMP_CONN_TOUT (BTA_DM_AUTH_FAIL_BASE + SMP_CONN_TOUT)
+
+typedef uint8_t tBTA_LE_KEY_TYPE; /* can be used as a bit mask */
+
+typedef union {
+  tBTM_LE_PENC_KEYS penc_key;  /* received peer encryption key */
+  tBTM_LE_PCSRK_KEYS psrk_key; /* received peer device SRK */
+  tBTM_LE_PID_KEYS pid_key;    /* peer device ID key */
+  tBTM_LE_LENC_KEYS
+      lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
+  tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
+  tBTM_LE_PID_KEYS lid_key; /* local device ID key for the particular remote */
+} tBTA_LE_KEY_VALUE;
+
+#define BTA_BLE_LOCAL_KEY_TYPE_ID 1
+#define BTA_BLE_LOCAL_KEY_TYPE_ER 2
+typedef uint8_t tBTA_DM_BLE_LOCAL_KEY_MASK;
+
+typedef struct {
+  Octet16 ir;
+  Octet16 irk;
+  Octet16 dhk;
+} tBTA_BLE_LOCAL_ID_KEYS;
+
+#define BTA_DM_SEC_GRANTED BTA_SUCCESS
+#define BTA_DM_SEC_PAIR_NOT_SPT BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT
+typedef uint8_t tBTA_DM_BLE_SEC_GRANT;
+
+/* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */
+typedef struct {
+  RawAddress bd_addr; /* peer address */
+  BD_NAME bd_name; /* peer device name */
+} tBTA_DM_BLE_SEC_REQ;
+
+typedef struct {
+  RawAddress bd_addr; /* peer address */
+  tBTM_LE_KEY_TYPE key_type;
+  tBTM_LE_KEY_VALUE* p_key_value;
+} tBTA_DM_BLE_KEY;
+
+/* Structure associated with BTA_DM_AUTH_CMPL_EVT */
+typedef struct {
+  RawAddress bd_addr;  /* BD address peer device. */
+  BD_NAME bd_name;     /* Name of peer device. */
+  bool key_present;    /* Valid link key value in key element */
+  LinkKey key;         /* Link key associated with peer device. */
+  uint8_t key_type;    /* The type of Link Key */
+  bool success;        /* true of authentication succeeded, false if failed. */
+  tHCI_REASON
+      fail_reason; /* The HCI reason/error code for when success=false */
+  tBLE_ADDR_TYPE addr_type; /* Peer device address type */
+  tBT_DEVICE_TYPE dev_type;
+  bool is_ctkd; /* True if key is derived using CTKD procedure */
+} tBTA_DM_AUTH_CMPL;
+
+/* Structure associated with BTA_DM_DEV_UNPAIRED_EVT */
+typedef struct {
+  RawAddress bd_addr; /* BD address peer device. */
+  tBT_TRANSPORT transport_link_type;
+} tBTA_DM_UNPAIR;
+
+#define BTA_AUTH_SP_YES                                                       \
+  BTM_AUTH_SP_YES /* 1 MITM Protection Required - Single Profile/non-bonding  \
+                    Use IO Capabilities to determine authentication procedure \
+                    */
+
+#define BTA_AUTH_DD_BOND \
+  BTM_AUTH_DD_BOND /* 2 this bit is set for dedicated bonding */
+#define BTA_AUTH_GEN_BOND \
+  BTM_AUTH_SPGB_NO /* 4 this bit is set for general bonding */
+#define BTA_AUTH_BONDS \
+  BTM_AUTH_BONDS /* 6 the general/dedicated bonding bits  */
+
+#define BTA_LE_AUTH_REQ_SC_MITM_BOND BTM_LE_AUTH_REQ_SC_MITM_BOND /* 1101 */
+
+/* Structure associated with BTA_DM_SP_CFM_REQ_EVT */
+typedef struct {
+  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
+   * order */
+  RawAddress bd_addr;  /* peer address */
+  DEV_CLASS dev_class; /* peer CoD */
+  BD_NAME bd_name;     /* peer device name */
+  uint32_t num_val; /* the numeric value for comparison. If just_works, do not
+                       show this number to UI */
+  bool just_works;  /* true, if "Just Works" association model */
+  tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
+  tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */
+  tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of local device */
+  tBTM_IO_CAP rmt_io_caps;    // IO Capabilities of remote device
+} tBTA_DM_SP_CFM_REQ;
+
+/* Structure associated with BTA_DM_SP_KEY_NOTIF_EVT */
+typedef struct {
+  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
+   * order */
+  RawAddress bd_addr;  /* peer address */
+  DEV_CLASS dev_class; /* peer CoD */
+  BD_NAME bd_name;     /* peer device name */
+  uint32_t passkey; /* the numeric value for comparison. If just_works, do not
+                       show this number to UI */
+} tBTA_DM_SP_KEY_NOTIF;
+
+/* Structure associated with BTA_DM_SP_RMT_OOB_EVT */
+typedef struct {
+  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
+   * order */
+  RawAddress bd_addr;  /* peer address */
+  DEV_CLASS dev_class; /* peer CoD */
+  BD_NAME bd_name;     /* peer device name */
+} tBTA_DM_SP_RMT_OOB;
+
+/* Structure associated with BTA_DM_BOND_CANCEL_CMPL_EVT */
+typedef struct {
+  tBTA_STATUS result; /* true of bond cancel succeeded, false if failed. */
+} tBTA_DM_BOND_CANCEL_CMPL;
+
+/* Add to remove bond of key missing RC */
+typedef struct {
+  RawAddress bd_addr;
+} tBTA_DM_RC_UNPAIR;
+
+typedef struct {
+  Octet16 local_oob_c; /* Local OOB Data Confirmation/Commitment */
+  Octet16 local_oob_r; /* Local OOB Data Randomizer */
+} tBTA_DM_LOC_OOB_DATA;
+
+/* Union of all security callback structures */
+typedef union {
+  tBTA_DM_PIN_REQ pin_req;        /* PIN request. */
+  tBTA_DM_AUTH_CMPL auth_cmpl;    /* Authentication complete indication. */
+  tBTA_DM_UNPAIR dev_unpair;      /* Remove bonding complete indication */
+  tBTA_DM_SP_CFM_REQ cfm_req;     /* user confirm request */
+  tBTA_DM_SP_KEY_NOTIF key_notif; /* passkey notification */
+  tBTA_DM_SP_RMT_OOB rmt_oob;     /* remote oob */
+  tBTA_DM_BOND_CANCEL_CMPL
+      bond_cancel_cmpl;               /* Bond Cancel Complete indication */
+  tBTA_DM_BLE_SEC_REQ ble_req;        /* BLE SMP related request */
+  tBTA_DM_BLE_KEY ble_key;            /* BLE SMP keys used when pairing */
+  tBTA_BLE_LOCAL_ID_KEYS ble_id_keys; /* IR event */
+  Octet16 ble_er;                     /* ER event data */
+  tBTA_DM_LOC_OOB_DATA local_oob_data; /* Local OOB data generated by us */
+  tBTA_DM_RC_UNPAIR delete_key_RC_to_unpair;
+  tBTA_DM_PROC_ID_ADDR proc_id_addr; /* Identity address event */
+} tBTA_DM_SEC;
+
+/* Security callback */
+typedef void(tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data);
+
+/* Encryption callback*/
+typedef void(tBTA_DM_ENCRYPT_CBACK)(const RawAddress& bd_addr,
+                                    tBT_TRANSPORT transport,
+                                    tBTA_STATUS result);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmBond
+ *
+ * Description      This function initiates a bonding procedure with a peer
+ *                  device by designated transport.  The bonding procedure
+ *                  enables authentication and optionally encryption on the
+ *                  Bluetooth link.
+ *
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmBond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
+                tBT_TRANSPORT transport, tBT_DEVICE_TYPE device_type);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmBondCancel
+ *
+ * Description      This function cancels a bonding procedure with a peer
+ *                  device.
+ *
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmBondCancel(const RawAddress& bd_addr);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmPinReply
+ *
+ * Description      This function provides a PIN when one is requested by DM
+ *                  during a bonding procedure.  The application should call
+ *                  this function after the security callback is called with
+ *                  a BTA_DM_PIN_REQ_EVT.
+ *
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmPinReply(const RawAddress& bd_addr, bool accept, uint8_t pin_len,
+                    uint8_t* p_pin);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmLocalOob
+ *
+ * Description      This function retrieves the OOB data from local controller.
+ *                  The result is reported by bta_dm_co_loc_oob().
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmLocalOob(void);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmConfirm
+ *
+ * Description      This function accepts or rejects the numerical value of the
+ *                  Simple Pairing process on BTA_DM_SP_CFM_REQ_EVT
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmConfirm(const RawAddress& bd_addr, bool accept);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmAddDevice
+ *
+ * Description      This function adds a device to the security database list
+ *                  of peer devices. This function would typically be called
+ *                  at system startup to initialize the security database with
+ *                  known peer devices.  This is a direct execution function
+ *                  that may lock task scheduling on some platforms.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
+                     const LinkKey& link_key, uint8_t key_type,
+                     uint8_t pin_length);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmRemoveDevice
+ *
+ * Description      This function removes a device from the security database.
+ *                  This is a direct execution function that may lock task
+ *                  scheduling on some platforms.
+ *
+ *
+ * Returns          BTA_SUCCESS if successful.
+ *                  BTA_FAIL if operation failed.
+ *
+ ******************************************************************************/
+tBTA_STATUS BTA_DmRemoveDevice(const RawAddress& bd_addr);
+
+
+/* BLE related API functions */
+/*******************************************************************************
+ *
+ * Function         BTA_DmBleSecurityGrant
+ *
+ * Description      Grant security request access.
+ *
+ * Parameters:      bd_addr          - BD address of the peer
+ *                  res              - security grant status.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
+                            tBTA_DM_BLE_SEC_GRANT res);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmBlePasskeyReply
+ *
+ * Description      Send BLE SMP passkey reply.
+ *
+ * Parameters:      bd_addr          - BD address of the peer
+ *                  accept           - passkey entry successful or declined.
+ *                  passkey          - passkey value, must be a 6 digit number,
+ *                                     can be lead by 0.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmBlePasskeyReply(const RawAddress& bd_addr, bool accept,
+                           uint32_t passkey);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmBleConfirmReply
+ *
+ * Description      Send BLE SMP SC user confirmation reply.
+ *
+ * Parameters:      bd_addr          - BD address of the peer
+ *                  accept           - numbers to compare are the same or
+ *                                     different.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmBleConfirmReply(const RawAddress& bd_addr, bool accept);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmAddBleDevice
+ *
+ * Description      Add a BLE device.  This function will be normally called
+ *                  during host startup to restore all required information
+ *                  for a LE device stored in the NVRAM.
+ *
+ * Parameters:      bd_addr          - BD address of the peer
+ *                  dev_type         - Remote device's device type.
+ *                  addr_type        - LE device address type.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmAddBleDevice(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
+                        tBT_DEVICE_TYPE dev_type);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmAddBleKey
+ *
+ * Description      Add/modify LE device information.  This function will be
+ *                  normally called during host startup to restore all required
+ *                  information stored in the NVRAM.
+ *
+ * Parameters:      bd_addr          - BD address of the peer
+ *                  p_le_key         - LE key values.
+ *                  key_type         - LE SMP key type.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmAddBleKey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
+                     tBTM_LE_KEY_TYPE key_type);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmSetEncryption
+ *
+ * Description      This function is called to ensure that connection is
+ *                  encrypted.  Should be called only on an open connection.
+ *                  Typically only needed for connections that first want to
+ *                  bring up unencrypted links, then later encrypt them.
+ *
+ * Parameters:      bd_addr       - Address of the peer device
+ *                  transport     - transport of the link to be encruypted
+ *                  p_callback    - Pointer to callback function to indicat the
+ *                                  link encryption status
+ *                  sec_act       - This is the security action to indicate
+ *                                  what kind of BLE security level is required
+ *                                  for the BLE link if BLE is supported
+ *                                  Note: This parameter is ignored for
+ *                                        BR/EDR or if BLE is not supported.
+ *
+ * Returns          void
+ *
+ *
+ ******************************************************************************/
+void BTA_DmSetEncryption(const RawAddress& bd_addr, tBT_TRANSPORT transport,
+                         tBTA_DM_ENCRYPT_CBACK* p_callback,
+                         tBTM_BLE_SEC_ACT sec_act);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmSirkSecCbRegister
+ *
+ * Description      This procedure registeres in requested a callback for
+ *                  verification by CSIS potential set member.
+ *
+ * Parameters       p_cback     - callback to member verificator
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmSirkSecCbRegister(tBTA_DM_SEC_CBACK* p_cback);
+
+/*******************************************************************************
+ *
+ * Function         BTA_DmSirkConfirmDeviceReply
+ *
+ * Description      This procedure confirms requested to validate set device.
+ *
+ * Parameters       bd_addr     - BD address of the peer
+ *                  accept      - True if device is authorized by CSIS, false
+ *                                otherwise.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void BTA_DmSirkConfirmDeviceReply(const RawAddress& bd_addr, bool accept);
diff --git a/system/bta/jv/bta_jv_int.h b/system/bta/jv/bta_jv_int.h
index 6b2c648d428..0c5900b1101 100644
--- a/system/bta/jv/bta_jv_int.h
+++ b/system/bta/jv/bta_jv_int.h
@@ -28,6 +28,7 @@
 #include <unordered_set>
 
 #include "bta/include/bta_jv_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "stack/include/bt_hdr.h"
 #include "stack/include/rfcdefs.h"
 #include "types/bluetooth/uuid.h"
diff --git a/system/bta/pan/bta_pan_int.h b/system/bta/pan/bta_pan_int.h
index cb99f151f17..8bd7d057f2d 100644
--- a/system/bta/pan/bta_pan_int.h
+++ b/system/bta/pan/bta_pan_int.h
@@ -27,6 +27,7 @@
 #include <cstdint>
 
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "bta/include/bta_pan_api.h"
 #include "bta/sys/bta_sys.h"
 #include "osi/include/fixed_queue.h"
diff --git a/system/bta/test/common/bta_dm_api_mock.h b/system/bta/test/common/bta_dm_api_mock.h
index 0fd39c226a0..005a24ab7c5 100644
--- a/system/bta/test/common/bta_dm_api_mock.h
+++ b/system/bta/test/common/bta_dm_api_mock.h
@@ -20,6 +20,7 @@
 #include <gmock/gmock.h>
 
 #include "bta_api.h"
+#include "bta_sec_api.h"
 #include "bta_dm_api.h"
 
 namespace dm {
diff --git a/system/btif/co/bta_dm_co.cc b/system/btif/co/bta_dm_co.cc
index 34b2c208b91..dd258c4066b 100644
--- a/system/btif/co/bta_dm_co.cc
+++ b/system/btif/co/bta_dm_co.cc
@@ -16,6 +16,7 @@
  *
  ******************************************************************************/
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "bte_appl.h"
 #include "stack/include/btm_api_types.h"
 
diff --git a/system/btif/include/btif_dm.h b/system/btif/include/btif_dm.h
index fa3691cc477..5cf51ce4341 100644
--- a/system/btif/include/btif_dm.h
+++ b/system/btif/include/btif_dm.h
@@ -20,6 +20,7 @@
 #define BTIF_DM_H
 
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "bte_appl.h"
 #include "btif_uid.h"
 #include "types/raw_address.h"
diff --git a/system/btif/src/btif_hd.cc b/system/btif/src/btif_hd.cc
index 5509d44b515..d6f46cd21d2 100644
--- a/system/btif/src/btif_hd.cc
+++ b/system/btif/src/btif_hd.cc
@@ -33,6 +33,7 @@
 
 #include "bt_target.h"  // Must be first to define build configuration
 #include "bta/include/bta_hd_api.h"
+#include "bta_sec_api.h"
 #include "bta/sys/bta_sys.h"
 #include "btif/include/btif_common.h"
 #include "btif/include/btif_profile_storage.h"
diff --git a/system/btif/src/btif_hh.cc b/system/btif/src/btif_hh.cc
index 1b06baf7386..b636c5d2554 100644
--- a/system/btif/src/btif_hh.cc
+++ b/system/btif/src/btif_hh.cc
@@ -33,6 +33,7 @@
 
 #include <cstdint>
 
+#include "bta_sec_api.h"
 #include "bta_hh_co.h"
 #include "btif/include/btif_common.h"
 #include "btif/include/btif_profile_storage.h"
diff --git a/system/btif/src/btif_iot_config.cc b/system/btif/src/btif_iot_config.cc
index d944f32979c..f79654081c1 100644
--- a/system/btif/src/btif_iot_config.cc
+++ b/system/btif/src/btif_iot_config.cc
@@ -18,6 +18,7 @@
 
 #include "bt_target.h"
 #include "bta_api.h"
+#include "bta_sec_api.h"
 #include "btif_storage.h"
 #include "device/include/device_iot_config.h"
 #include "stack/include/btm_ble_api.h"
diff --git a/system/btif/src/btif_sock.cc b/system/btif/src/btif_sock.cc
index 63dfa490c8e..bf0e2281fc6 100644
--- a/system/btif/src/btif_sock.cc
+++ b/system/btif/src/btif_sock.cc
@@ -29,7 +29,7 @@
 
 #include <atomic>
 
-#include "bta_api.h"
+#include "bta_sec_api.h"
 #include "btif_common.h"
 #include "btif_config.h"
 #include "btif_metrics_logging.h"
diff --git a/system/stack/avct/avct_api.cc b/system/stack/avct/avct_api.cc
index 1a8d6c6637a..6129e89420f 100644
--- a/system/stack/avct/avct_api.cc
+++ b/system/stack/avct/avct_api.cc
@@ -29,6 +29,7 @@
 #include "avct_int.h"
 #include "bt_target.h"
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "btm_api.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
diff --git a/system/stack/avct/avct_bcb_act.cc b/system/stack/avct/avct_bcb_act.cc
index 178a6605ffc..4c306fc60d5 100644
--- a/system/stack/avct/avct_bcb_act.cc
+++ b/system/stack/avct/avct_bcb_act.cc
@@ -34,7 +34,7 @@
 #include "avct_api.h"
 #include "avct_int.h"
 #include "bt_target.h"
-#include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "btm_api.h"
 #include "osi/include/allocator.h"
 #include "osi/include/log.h"
diff --git a/system/stack/avct/avct_lcb_act.cc b/system/stack/avct/avct_lcb_act.cc
index 446f69dbfaa..78cdef9e317 100644
--- a/system/stack/avct/avct_lcb_act.cc
+++ b/system/stack/avct/avct_lcb_act.cc
@@ -30,6 +30,7 @@
 #include "avct_int.h"
 #include "bt_target.h"
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "btm_api.h"
 #include "device/include/device_iot_config.h"
 #include "osi/include/allocator.h"
diff --git a/system/stack/avdt/avdt_api.cc b/system/stack/avdt/avdt_api.cc
index 13f73a648f2..0786cf6263c 100644
--- a/system/stack/avdt/avdt_api.cc
+++ b/system/stack/avdt/avdt_api.cc
@@ -30,7 +30,7 @@
 #include "avdt_int.h"
 #include "avdtc_api.h"
 #include "bt_target.h"
-#include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "btm_api.h"
 #include "l2c_api.h"
 #include "main/shim/dumpsys.h"
diff --git a/system/stack/bnep/bnep_api.cc b/system/stack/bnep/bnep_api.cc
index c3948b9e841..d707a8b6ec6 100644
--- a/system/stack/bnep/bnep_api.cc
+++ b/system/stack/bnep/bnep_api.cc
@@ -29,6 +29,7 @@
 
 #include "bnep_int.h"
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "osi/include/allocator.h"
 #include "stack/include/bt_hdr.h"
 #include "stack/include/bt_psm_types.h"
diff --git a/system/stack/bnep/bnep_main.cc b/system/stack/bnep/bnep_main.cc
index b10c1c9bfd3..e831d4d9413 100644
--- a/system/stack/bnep/bnep_main.cc
+++ b/system/stack/bnep/bnep_main.cc
@@ -31,6 +31,7 @@
 #include "bnep_int.h"
 #include "bt_target.h"
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "device/include/controller.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
diff --git a/system/stack/hid/hidd_conn.cc b/system/stack/hid/hidd_conn.cc
index 73f0e9a98bb..83eabc72148 100644
--- a/system/stack/hid/hidd_conn.cc
+++ b/system/stack/hid/hidd_conn.cc
@@ -30,6 +30,7 @@
 #include <cstdint>
 
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "osi/include/allocator.h"
 #include "stack/hid/hidd_int.h"
 #include "stack/include/bt_hdr.h"
diff --git a/system/stack/hid/hidh_conn.cc b/system/stack/hid/hidh_conn.cc
index d4ecb369808..8ec5bc852f4 100644
--- a/system/stack/hid/hidh_conn.cc
+++ b/system/stack/hid/hidh_conn.cc
@@ -28,7 +28,7 @@
 #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
 #include <string.h>
 
-#include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "hiddefs.h"
 #include "hidh_api.h"
 #include "hidh_int.h"
diff --git a/system/test/mock/mock_bta_dm_api.h b/system/test/mock/mock_bta_dm_api.h
index d34e7ae9514..d9acacdd6e0 100644
--- a/system/test/mock/mock_bta_dm_api.h
+++ b/system/test/mock/mock_bta_dm_api.h
@@ -31,6 +31,7 @@
 #include <vector>
 
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "stack/include/bt_device_type.h"
 #include "stack/include/bt_octets.h"
 #include "types/ble_address_with_type.h"
diff --git a/system/test/mock/mock_btif_co_bta_dm_co.cc b/system/test/mock/mock_btif_co_bta_dm_co.cc
index 633c416ab2b..63cbfc13899 100644
--- a/system/test/mock/mock_btif_co_bta_dm_co.cc
+++ b/system/test/mock/mock_btif_co_bta_dm_co.cc
@@ -21,6 +21,7 @@
 #include <cstdint>
 
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "bta/sys/bta_sys.h"
 #include "internal_include/bte_appl.h"
 #include "stack/include/btm_api_types.h"
diff --git a/system/test/mock/mock_btif_dm.cc b/system/test/mock/mock_btif_dm.cc
index c052f57ebb7..9038ad0c477 100644
--- a/system/test/mock/mock_btif_dm.cc
+++ b/system/test/mock/mock_btif_dm.cc
@@ -22,6 +22,7 @@
 #include <cstdint>
 
 #include "bta/include/bta_api.h"
+#include "bta/include/bta_sec_api.h"
 #include "include/hardware/bluetooth.h"
 #include "internal_include/bte_appl.h"
 #include "test/common/mock_functions.h"
-- 
GitLab