Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eee64f45 authored by Chaojing Sun's avatar Chaojing Sun Committed by Andre Eisenbach
Browse files

Cross transport key mapping fixes

Change-Id: I22d97303054eccc876c4a9c7c0a50e369ff4fa62
parent 74b022d5
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -2279,10 +2279,8 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
                                    bta_dm_search_cb.services_to_search
                                    );
            }
            if (transport == BT_TRANSPORT_LE)            /*
            if ( bta_dm_search_cb.p_btm_inq_info != NULL &&
                 bta_dm_search_cb.p_btm_inq_info->results.device_type == BT_DEVICE_TYPE_BLE &&
                 (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK))*/

            if (transport == BT_TRANSPORT_LE)
            {
                if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK)
                {
@@ -2730,14 +2728,15 @@ static UINT8 bta_dm_new_link_key_cback(BD_ADDR bd_addr, DEV_CLASS dev_class,
        memcpy(p_auth_cmpl->key, key, LINK_KEY_LEN);
        sec_event.auth_cmpl.fail_reason = HCI_SUCCESS;

        // Report the BR link key based on the BR/EDR address and type
        BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, &sec_event.auth_cmpl.addr_type);

        if(bta_dm_cb.p_sec_cback)
        {
            bta_dm_cb.p_sec_cback(event, &sec_event);
    }
    }
    else
    {
        APPL_TRACE_WARNING(" bta_dm_new_link_key_cback() Received AMP Key??  ");
        APPL_TRACE_WARNING("%s() Received AMP Key", __func__);
    }

    return BTM_CMD_STARTED;
@@ -2766,18 +2765,14 @@ static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev
        memcpy(sec_event.auth_cmpl.bd_name, bd_name, (BD_NAME_LEN-1));
        sec_event.auth_cmpl.bd_name[BD_NAME_LEN-1] = 0;

/*      taken care of by memset [above]
        sec_event.auth_cmpl.key_present = FALSE;
        sec_event.auth_cmpl.success = FALSE;
*/
        // Report the BR link key based on the BR/EDR address and type
        BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, &sec_event.auth_cmpl.addr_type);
        sec_event.auth_cmpl.fail_reason = (UINT8)result;

        if(bta_dm_cb.p_sec_cback)
        {
            bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event);
        }
        /* delete this device entry from Sec Dev DB */
        bta_dm_remove_sec_dev_entry(bd_addr);

        bta_dm_remove_sec_dev_entry(bd_addr);
    }

    return BTM_SUCCESS;
@@ -4390,7 +4385,7 @@ static UINT8 bta_dm_ble_smp_cback (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_D

        case BTM_LE_COMPLT_EVT:
            bdcpy(sec_event.auth_cmpl.bd_addr, bda);
            BTM_ReadDevInfo(bda, &dev_type, &sec_event.auth_cmpl.addr_type);
            BTM_ReadDevInfo(bda, &sec_event.auth_cmpl.dev_type, &sec_event.auth_cmpl.addr_type);
            p_name = BTM_SecReadDevName(bda);
            if (p_name != NULL)
            {
@@ -5417,7 +5412,7 @@ static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
            /* make sure the string is terminated */
            p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0;

            p_msg->disc_result.result.disc_res.device_type = BT_DEVICE_TYPE_BLE;
            p_msg->disc_result.result.disc_res.device_type |= BT_DEVICE_TYPE_BLE;
            if ( bta_dm_search_cb.ble_raw_used > 0 )
            {
                p_msg->disc_result.result.disc_res.p_raw_data = GKI_getbuf(bta_dm_search_cb.ble_raw_used);
+1 −0
Original line number Diff line number Diff line
@@ -763,6 +763,7 @@ typedef struct
    UINT8           fail_reason;        /* The HCI reason/error code for when success=FALSE */
#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
    tBLE_ADDR_TYPE  addr_type;      /* peer device address type */
    tBT_DEVICE_TYPE dev_type;
#endif
} tBTA_DM_AUTH_CMPL;

+9 −9
Original line number Diff line number Diff line
@@ -31,15 +31,15 @@

tBTE_APPL_CFG bte_appl_cfg =
{
#if SMP_INCLUDED == TRUE && SMP_LE_SC_INCLUDED == TRUE
#if SMP_INCLUDED == TRUE
    BTA_LE_AUTH_REQ_SC_MITM_BOND, // Authentication requirements
#else
    BTM_AUTH_SPGB_YES,            // Authentication requirements
#endif
    BTM_LOCAL_IO_CAPS_BLE, // I/O capabilities
    7,                  // Initiaor key size
    7,                  // Responder key size
    16                  // Maximum key size
    BTM_LOCAL_IO_CAPS_BLE,
    BTM_BLE_INITIATOR_KEY_SIZE,
    BTM_BLE_RESPONDER_KEY_SIZE,
    BTM_BLE_MAX_KEY_SIZE
};
#endif

@@ -426,10 +426,10 @@ void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap,
    if (bte_appl_cfg.ble_io_cap <=4)
        *p_io_cap = bte_appl_cfg.ble_io_cap;

    if (bte_appl_cfg.ble_init_key<=7)
    if (bte_appl_cfg.ble_init_key <= BTM_BLE_INITIATOR_KEY_SIZE)
        *p_init_key = bte_appl_cfg.ble_init_key;

    if (bte_appl_cfg.ble_resp_key<=7)
    if (bte_appl_cfg.ble_resp_key <= BTM_BLE_RESPONDER_KEY_SIZE)
        *p_resp_key = bte_appl_cfg.ble_resp_key;

    if (bte_appl_cfg.ble_max_key_size > 7 && bte_appl_cfg.ble_max_key_size <= 16)
+68 −35
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ typedef struct
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
    BOOLEAN is_le_only;
    BOOLEAN is_le_nc; /* LE Numeric comparison */
    BD_ADDR static_bdaddr;
    btif_dm_ble_cb_t ble;
#endif
} btif_dm_pairing_cb_t;
@@ -203,7 +204,6 @@ typedef struct

static skip_sdp_entry_t sdp_blacklist[] = {{76}}; //Apple Mouse and Keyboard


/* This flag will be true if HCI_Inquiry is in progress */
static BOOLEAN btif_dm_inquiry_in_progress = FALSE;

@@ -486,15 +486,20 @@ BOOLEAN check_sdp_bl(const bt_bdaddr_t *remote_bdaddr)

static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state)
{
    /* Send bonding state only once - based on outgoing/incoming we may receive duplicates */
    // Send bonding state only once - based on outgoing/incoming we may receive duplicates
    if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING))
    {
        // Cross key pairing so send callback for static address
        if (pairing_cb.static_bdaddr != NULL)
            HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
        return;
    }

    if (pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
    {
        state = BT_BOND_STATE_NONE;
    }
    BTIF_TRACE_DEBUG("%s: state=%d prev_state=%d", __FUNCTION__, state, pairing_cb.state);

    BTIF_TRACE_DEBUG("%s: state=%d, prev_state=%d, sdp_attempts = %d", __func__,
                      state, pairing_cb.state, pairing_cb.sdp_attempts);

    HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);

@@ -502,12 +507,12 @@ static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond
    {
        pairing_cb.state = state;
        bdcpy(pairing_cb.bd_addr, bd_addr->address);
    }
    else
    {
    } else {
        if (!pairing_cb.sdp_attempts)
            memset(&pairing_cb, 0, sizeof(pairing_cb));
        else
            BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__);
    }

}

/* store remote version in bt config to always have access
@@ -531,8 +536,7 @@ static void btif_update_remote_version_property(bt_bdaddr_t *p_bd)

    if (btm_status == BTM_SUCCESS)
    {
        /* always update cache to ensure we have availability whenever BTM API
           is not populated */
        // Always update cache to ensure we have availability whenever BTM API is not populated
        info.manufacturer = mfct_set;
        info.sub_ver = lmp_subver;
        info.version = lmp_ver;
@@ -591,7 +595,15 @@ static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
    num_properties++;

    /* device type */
    bt_property_t prop_name;
    uint8_t remote_dev_type;
    BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_TYPE_OF_DEVICE,
                                sizeof(uint8_t), &remote_dev_type);
    if (btif_storage_get_remote_device_property(&bdaddr, &prop_name) == BT_STATUS_SUCCESS)
         dev_type = remote_dev_type | device_type;
    else
         dev_type = device_type;

    BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                        BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
    status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
@@ -663,14 +675,14 @@ static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transpor
    }
    if((btif_config_get_int((char const *)&bdstr,"DevType", &device_type) &&
       (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) &&
       (device_type == BT_DEVICE_TYPE_BLE)) || (transport == BT_TRANSPORT_LE))
       (device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) || (transport == BT_TRANSPORT_LE))
    {
        BTA_DmAddBleDevice(bd_addr->address, addr_type, BT_DEVICE_TYPE_BLE);
        BTA_DmAddBleDevice(bd_addr->address, addr_type, device_type);
    }
#endif

#if BLE_INCLUDED == TRUE
    if(is_hid && device_type != BT_DEVICE_TYPE_BLE)
    if(is_hid && (device_type & BT_DEVICE_TYPE_BLE) == 0)
#else
    if(is_hid)
#endif
@@ -708,6 +720,7 @@ void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
    if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS)
#endif
    {
         BTIF_TRACE_DEBUG("%s: Removing HH device", __func__);
         BTA_DmRemoveDevice((UINT8 *)bd_addr->address);
    }
}
@@ -1039,6 +1052,8 @@ static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
    bt_bond_state_t state = BT_BOND_STATE_NONE;
    BOOLEAN skip_sdp = FALSE;

    BTIF_TRACE_DEBUG("%s: bond state=%d", __func__, pairing_cb.state);

    bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
    if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
    {
@@ -1070,6 +1085,9 @@ static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
    // Skip SDP for certain  HID Devices
    if (p_auth_cmpl->success)
    {
        btif_storage_set_remote_addr_type(&bd_addr, p_auth_cmpl->addr_type);
        btif_update_remote_properties(p_auth_cmpl->bd_addr,
                                      p_auth_cmpl->bd_name, NULL, p_auth_cmpl->dev_type);
        pairing_cb.timeout_retries = 0;
        status = BT_STATUS_SUCCESS;
        state = BT_BOND_STATE_BONDED;
@@ -1104,17 +1122,25 @@ static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
        {
            /* Trigger SDP on the device */
            pairing_cb.sdp_attempts = 1;;
            /* If bonded due to cross-key, save the static address too*/
            if(pairing_cb.state == BT_BOND_STATE_BONDING &&
              (bdcmp(p_auth_cmpl->bd_addr, pairing_cb.bd_addr) != 0))
            {
                BTIF_TRACE_DEBUG("%s: bonding initiated due to cross key, adding static address",
                                 __func__);
                bdcpy(pairing_cb.static_bdaddr, p_auth_cmpl->bd_addr);
            }

            if(btif_dm_inquiry_in_progress)
                btif_dm_cancel_discovery();

            btif_dm_get_remote_services(&bd_addr);
        }
            /* Do not call bond_state_changed_cb yet. Wait till fetch remote service is complete */
        // Do not call bond_state_changed_cb yet. Wait until remote service discovery is complete
    }
    else
    {
         /*Map the HCI fail reason  to  bt status  */
        // Map the HCI fail reason  to  bt status
        switch(p_auth_cmpl->fail_reason)
        {
            case HCI_ERR_PAGE_TIMEOUT:
@@ -1428,12 +1454,19 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param)
            ** bond_state_changed needs to be sent prior to remote_device_property
            */
            if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
                (bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0)&&
                ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) ||
                 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr) == 0)) &&
                  pairing_cb.sdp_attempts > 0)
            {
                 BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
                                   __FUNCTION__);
                 pairing_cb.sdp_attempts  = 0;

                 // If bonding occured due to cross-key pairing, send bonding callback
                 // for static address now
                 if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr) == 0)
                    bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);

                 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
            }

+73 −183
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
 *
 *
 */
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
@@ -215,6 +216,7 @@ static void btif_in_split_uuids_string_to_list(char *str, bt_uuid_t *p_uuid,
    } while (*p_start != 0);
    *p_num_uuid = num;
}

static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
{
    bdstr_t bdstr = {0};
@@ -307,6 +309,7 @@ static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
    }
    return TRUE;
}

static int cfg2prop(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
{
    bdstr_t bdstr = {0};
@@ -542,19 +545,44 @@ static bt_status_t btif_in_fetch_bonded_devices(btif_bonded_devices_t *p_bonded_
    return BT_STATUS_SUCCESS;
}

/************************************************************************************
**  Externs
************************************************************************************/
static void btif_read_le_key(const uint8_t key_type, const size_t key_len, bt_bdaddr_t bd_addr,
                 const uint8_t addr_type, const bool add_key, bool *device_added, bool *key_found)
{
    assert(device_added);
    assert(key_found);

/************************************************************************************
**  Functions
************************************************************************************/
    char buffer[100];
    memset(buffer, 0, sizeof(buffer));

    if (btif_storage_get_ble_bonding_key(&bd_addr, key_type, buffer, key_len) == BT_STATUS_SUCCESS)
    {
        if (add_key)
        {
            BD_ADDR bta_bd_addr;
            bdcpy(bta_bd_addr, bd_addr.address);

            if (!device_added)
            {
                BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                *device_added = true;
            }
            BTA_DmAddBleKey(bta_bd_addr, (tBTA_LE_KEY_VALUE *)buffer, key_type);
        }

        *key_found = true;
    }
}

/*******************************************************************************
 * Functions
 *
 * Functions are synchronous and can be called by both from internal modules
 * such as BTIF_DM and by external entiries from HAL via BTIF_context_switch.
 * For OUT parameters, the caller is expected to provide the memory.
 * Caller is expected to provide a valid pointer to 'property->value' based on
 * the property->type.
 *******************************************************************************/

/** functions are synchronous.
 * functions can be called by both internal modules such as BTIF_DM and by external entiries from HAL via BTIF_context_switch
 * For OUT parameters,  caller is expected to provide the memory.
 * Caller is expected to provide a valid pointer to 'property->value' based on the property->type
 */
/*******************************************************************************
**
** Function         btif_storage_get_adapter_property
@@ -1157,184 +1185,48 @@ bt_status_t btif_in_fetch_bonded_ble_device(const char *remote_bd_addr,int add,
{
    int device_type;
    int addr_type;
    char buf[100];
    UINT32 i;
    bt_bdaddr_t bd_addr;
    BD_ADDR bta_bd_addr;
    BOOLEAN is_device_added =FALSE;
    BOOLEAN key_found = FALSE;
    tBTA_LE_KEY_VALUE *p;
    bool device_added = false;
    bool key_found = false;

    if (!btif_config_get_int(remote_bd_addr, "DevType", &device_type))
        return BT_STATUS_FAIL;
    if(device_type == BT_DEVICE_TYPE_BLE)
    {
            BTIF_TRACE_DEBUG("%s %s found a BLE device", __FUNCTION__,remote_bd_addr);
            string_to_bdaddr(remote_bd_addr, &bd_addr);
            bdcpy(bta_bd_addr, bd_addr.address);
            if (btif_storage_get_remote_addr_type(&bd_addr, &addr_type) != BT_STATUS_SUCCESS)
            {
                return BT_STATUS_FAIL;
            }

            memset(buf, 0, sizeof(buf));
            if (btif_storage_get_ble_bonding_key(&bd_addr,
                                                 BTIF_DM_LE_KEY_PENC,
                                                 buf,
                                                 sizeof(btif_dm_ble_penc_keys_t)) == BT_STATUS_SUCCESS)
            {
                if(add)
                {
                    if (!is_device_added)
                    {
                        BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                        is_device_added = TRUE;
                    }
                    p = (tBTA_LE_KEY_VALUE *)buf;
                    for (i=0; i<16; i++)
                    {
                        BTIF_TRACE_DEBUG("penc_key.ltk[%d]=0x%02x",i,p->penc_key.ltk[i]);
                    }
                    for (i=0; i<8; i++)
                    {
                        BTIF_TRACE_DEBUG("penc_key.rand[%d]=0x%02x",i,p->penc_key.rand[i]);
                    }
                    BTIF_TRACE_DEBUG("p->penc_key.ediv=0x%04x",p->penc_key.ediv);
                    BTIF_TRACE_DEBUG("p->penc_key.sec_level=0x%02x",p->penc_key.sec_level);
                    BTIF_TRACE_DEBUG("p->penc_key.key_size=0x%02x",p->penc_key.key_size);
                    BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_PENC);
                }
                key_found = TRUE;
            }

            memset(buf, 0, sizeof(buf));
            if (btif_storage_get_ble_bonding_key(&bd_addr,
                                                 BTIF_DM_LE_KEY_PID,
                                                 buf,
                                                 sizeof(btif_dm_ble_pid_keys_t)) == BT_STATUS_SUCCESS)
            {
                if(add)
                {
                    if (!is_device_added)
                    {
                        BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                        is_device_added = TRUE;
                    }
                    p = (tBTA_LE_KEY_VALUE *)buf;
                    for (i=0; i<16; i++)
                    {
                        BTIF_TRACE_DEBUG("p->pid_key.irk[%d]=0x%02x"
                                            ,i,p->pid_key.irk[i]);
                    }
                    BTIF_TRACE_DEBUG("p->pid_key.addr_type=%d",p->pid_key.addr_type);
                    for (i=0; i<BD_ADDR_LEN; i++)
                    {
                        BTIF_TRACE_DEBUG("p->pid_key.static_addr[%d]=%02x"
                                            ,i,p->pid_key.static_addr[i]);
                    }

                    BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_PID);
                }
                key_found = TRUE;
            }

            if (btif_storage_get_ble_bonding_key(&bd_addr, BTIF_DM_LE_KEY_LID, buf,
                                    sizeof(btif_dm_ble_pid_keys_t))== BT_STATUS_SUCCESS)
            {
                if(add)
                {
                    if (!is_device_added)
    if ((device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE)
    {
                        BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                        is_device_added = TRUE;
                    }
                    p = (tBTA_LE_KEY_VALUE *)buf;
                    for (i=0; i<BD_ADDR_LEN; i++)
                    {
                        BTIF_TRACE_DEBUG("p->pid_key.static_addr[%d]=%02x"
                                            ,i,p->pid_key.static_addr[i]);
                    }
        BTIF_TRACE_DEBUG("%s Found a LE device: %s", __func__, remote_bd_addr);

                    BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_LID);
                }
                key_found = TRUE;
            }
        string_to_bdaddr(remote_bd_addr, &bd_addr);
        bdcpy(bta_bd_addr, bd_addr.address);

            memset(buf, 0, sizeof(buf));
            if (btif_storage_get_ble_bonding_key(&bd_addr,
                                                 BTIF_DM_LE_KEY_PCSRK,
                                                 buf,
                                                 sizeof(btif_dm_ble_pcsrk_keys_t)) == BT_STATUS_SUCCESS)
            {
                if(add)
                {
                    if (!is_device_added)
        if (btif_storage_get_remote_addr_type(&bd_addr, &addr_type) != BT_STATUS_SUCCESS)
        {
                        BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                        is_device_added = TRUE;
            addr_type = BLE_ADDR_PUBLIC;
            btif_storage_set_remote_addr_type(&bd_addr, BLE_ADDR_PUBLIC);
        }

                    p = (tBTA_LE_KEY_VALUE *)buf;
                    for (i=0; i<16; i++)
                    {
                        BTIF_TRACE_DEBUG("p->pcsrk_key.csrk[%d]=0x%02x",i, p->psrk_key.csrk[i]);
                    }
                    BTIF_TRACE_DEBUG("p->pcsrk_key.counter=0x%08x",p->psrk_key.counter);
                    BTIF_TRACE_DEBUG("p->pcsrk_key.sec_level=0x%02x",p->psrk_key.sec_level);
        btif_read_le_key(BTIF_DM_LE_KEY_PENC, sizeof(btif_dm_ble_penc_keys_t),
                         bd_addr, addr_type, add, &device_added, &key_found);

                    BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_PCSRK);
                }
                key_found = TRUE;
            }
        btif_read_le_key(BTIF_DM_LE_KEY_PID, sizeof(btif_dm_ble_pid_keys_t),
                         bd_addr, addr_type, add, &device_added, &key_found);

            memset(buf, 0, sizeof(buf));
            if (btif_storage_get_ble_bonding_key(&bd_addr,
                                                 BTIF_DM_LE_KEY_LENC,
                                                 buf,
                                                 sizeof(btif_dm_ble_lenc_keys_t)) == BT_STATUS_SUCCESS)
            {
                if(add)
                {
                    if (!is_device_added)
                    {
                        BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                        is_device_added = TRUE;
                    }
                    p = (tBTA_LE_KEY_VALUE *)buf;
                    BTIF_TRACE_DEBUG("p->lenc_key.div=0x%04x",p->lenc_key.div);
                    BTIF_TRACE_DEBUG("p->lenc_key.key_size=0x%02x",p->lenc_key.key_size);
                    BTIF_TRACE_DEBUG("p->lenc_key.sec_level=0x%02x",p->lenc_key.sec_level);
        btif_read_le_key(BTIF_DM_LE_KEY_LID, sizeof(btif_dm_ble_pid_keys_t),
                         bd_addr, addr_type, add, &device_added, &key_found);

                    BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_LENC);
                }
                key_found = TRUE;
            }
        btif_read_le_key(BTIF_DM_LE_KEY_PCSRK, sizeof(btif_dm_ble_pcsrk_keys_t),
                         bd_addr, addr_type, add, &device_added, &key_found);

            memset(buf, 0, sizeof(buf));
            if (btif_storage_get_ble_bonding_key(&bd_addr,
                                                 BTIF_DM_LE_KEY_LCSRK,
                                                 buf,
                                                 sizeof(btif_dm_ble_lcsrk_keys_t)) == BT_STATUS_SUCCESS)
            {
                if(add)
                {
                    if (!is_device_added)
                    {
                        BTA_DmAddBleDevice(bta_bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
                        is_device_added = TRUE;
                    }
                    p = (tBTA_LE_KEY_VALUE *)buf;
                    BTIF_TRACE_DEBUG("p->lcsrk_key.div=0x%04x",p->lcsrk_key.div);
                    BTIF_TRACE_DEBUG("p->lcsrk_key.counter=0x%08x",p->lcsrk_key.counter);
                    BTIF_TRACE_DEBUG("p->lcsrk_key.sec_level=0x%02x",p->lcsrk_key.sec_level);
        btif_read_le_key(BTIF_DM_LE_KEY_LENC, sizeof(btif_dm_ble_lenc_keys_t),
                         bd_addr, addr_type, add, &device_added, &key_found);

                    BTA_DmAddBleKey (bta_bd_addr, (tBTA_LE_KEY_VALUE *)buf, BTIF_DM_LE_KEY_LCSRK);
                }
                key_found = TRUE;
            }
        btif_read_le_key(BTIF_DM_LE_KEY_LCSRK, sizeof(btif_dm_ble_lcsrk_keys_t),
                         bd_addr, addr_type, add, &device_added, &key_found);

            /* Fill in the bonded devices */
            if (is_device_added)
        // Fill in the bonded devices
        if (device_added)
        {
            memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t));
            btif_gatts_add_bonded_dev_from_nv(bta_bd_addr);
@@ -1342,8 +1234,6 @@ bt_status_t btif_in_fetch_bonded_ble_device(const char *remote_bd_addr,int add,

        if (key_found)
            return BT_STATUS_SUCCESS;
            else
                return BT_STATUS_FAIL;
    }
    return BT_STATUS_FAIL;
}
Loading