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

Commit f5eb7853 authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

Add flag indicating encrypted connections to btif_dm_get_connection_state()

Add a check to btif_dm_get_connection_state() to see if the currently
active connection is encrypted.

Bug: 19186961
Change-Id: I27bcc6e296d272ffd17c0bbe97631ffa4df57ccd
parent b9b58865
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -113,6 +113,9 @@ BOOLEAN blacklistPairingRetries(BD_ADDR bd_addr)
#define BOND_TYPE_PERSISTENT  1
#define BOND_TYPE_TEMPORARY   2

#define ENCRYPTED_BREDR       2
#define ENCRYPTED_LE          4

typedef struct
{
    bt_bond_state_t state;
@@ -701,13 +704,33 @@ void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
** Function         btif_dm_get_connection_state
**
** Description      Returns whether the remote device is currently connected
**                  and whether encryption is active for the connection
**
** Returns          0 if not connected
** Returns          0 if not connected; 1 if connected and > 1 if connection is
**                  encrypted
**
*******************************************************************************/
uint16_t btif_dm_get_connection_state(const bt_bdaddr_t *bd_addr)
{
    return BTA_DmGetConnectionState((UINT8 *)bd_addr->address);
    uint8_t *bda = (uint8_t*)bd_addr->address;
    uint16_t rc = BTA_DmGetConnectionState(bda);

    if (rc != 0)
    {
        uint8_t flags = 0;

        BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_BR_EDR);
        BTIF_TRACE_DEBUG("%s: security flags (BR/EDR)=0x%02x", __FUNCTION__, flags);
        if (flags & BTM_SEC_FLAG_ENCRYPTED)
            rc |= ENCRYPTED_BREDR;

        BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_LE);
        BTIF_TRACE_DEBUG("%s: security flags (LE)=0x%02x", __FUNCTION__, flags);
        if (flags & BTM_SEC_FLAG_ENCRYPTED)
            rc |= ENCRYPTED_LE;
    }

    return rc;
}

/*******************************************************************************