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

Commit 9be22322 authored by Satya Calloji's avatar Satya Calloji Committed by Andre Eisenbach
Browse files

Unpair the other transport on a device paired

When unpair is initiated for LE or BR-EDR transport for a device,
close the link for other transport and unpair the device on
both transports, since both transports on a device are paired
due to cross key.

Original author: Priti Aghera <paghera@broadcom.com>
Change-Id: I13d4757eb056c4bd4c7cc0699ec61a28852702c5
parent c3890bf8
Loading
Loading
Loading
Loading
+89 −28
Original line number Diff line number Diff line
@@ -583,57 +583,118 @@ void bta_dm_set_visibility (tBTA_DM_MSG *p_data)

/*******************************************************************************
**
** Function         bta_dm_remove_device
** Function         bta_dm_process_remove_device
**
** Description      Removes device, Disconnects ACL link if required.
****
*******************************************************************************/
void bta_dm_remove_device (tBTA_DM_MSG *p_data)
void bta_dm_process_remove_device(BD_ADDR bd_addr)
{
    tBTA_DM_API_REMOVE_DEVICE *p_dev = &p_data->remove_dev;
    int i;
    tBTA_DM_SEC sec_event;

#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
     /* need to remove all pending background connection before unpair */
    BTA_GATTC_CancelOpen(0, p_dev->bd_addr, FALSE);
     BTA_GATTC_CancelOpen(0, bd_addr, FALSE);
#endif

     BTM_SecDeleteDevice(bd_addr);

#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
      /* remove all cached GATT information */
      BTA_GATTC_Refresh(bd_addr);
#endif

      if (bta_dm_cb.p_sec_cback)
      {
         tBTA_DM_SEC sec_event;
         bdcpy(sec_event.link_down.bd_addr, bd_addr);
         /* No connection, set status to success (acl disc code not valid) */
         sec_event.link_down.status = HCI_SUCCESS;
         bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event);
      }
}

/*******************************************************************************
**
** Function         bta_dm_remove_device
**
** Description      Removes device, disconnects ACL link if required.
****
*******************************************************************************/
void bta_dm_remove_device(tBTA_DM_MSG *p_data)
{
    tBTA_DM_API_REMOVE_DEVICE *p_dev = &p_data->remove_dev;
    if (p_dev == NULL)
        return;

    BD_ADDR other_address;
    bdcpy(other_address, p_dev->bd_addr);

    /* If ACL exists for the device in the remove_bond message*/
    BOOLEAN continue_delete_dev = FALSE;
    UINT8 other_transport = BT_TRANSPORT_INVALID;

    if (BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_LE) ||
        BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR))
    {
           APPL_TRACE_DEBUG("%s: ACL Up count  %d", __FUNCTION__,bta_dm_cb.device_list.count);
        /* Take the link down first, and mark the device for removal when disconnected */
        APPL_TRACE_DEBUG("%s: ACL Up count  %d", __func__, bta_dm_cb.device_list.count);
        continue_delete_dev = FALSE;

        for(i=0; i<bta_dm_cb.device_list.count; i++)
        /* Take the link down first, and mark the device for removal when disconnected */
        for(int i=0; i < bta_dm_cb.device_list.count; i++)
        {
            if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr))
            {
                bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
                btm_remove_acl( p_dev->bd_addr, bta_dm_cb.device_list.peer_device[i].transport);
                APPL_TRACE_DEBUG("%s:transport = %d", __FUNCTION__,
                APPL_TRACE_DEBUG("%s:transport = %d", __func__,
                                  bta_dm_cb.device_list.peer_device[i].transport);

                /* save the other transport to check if device is connected on other_transport */
                if(bta_dm_cb.device_list.peer_device[i].transport == BT_TRANSPORT_LE)
                   other_transport = BT_TRANSPORT_BR_EDR;
                else
                   other_transport = BT_TRANSPORT_LE;
                break;
            }
        }
    }

    else    /* Ok to remove the device in application layer */
    else
    {
        BTM_SecDeleteDevice(p_dev->bd_addr);
#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
        /* remove all cached GATT information */
        BTA_GATTC_Refresh(p_dev->bd_addr);
#endif
        continue_delete_dev = TRUE;
    }

        if( bta_dm_cb.p_sec_cback )
    // If it is DUMO device and device is paired as different address, unpair that device
    // if different address
    BOOLEAN continue_delete_other_dev = FALSE;
    if ((other_transport && (BTM_ReadConnectedTransportAddress(other_address, other_transport))) ||
      (!other_transport && (BTM_ReadConnectedTransportAddress(other_address, BT_TRANSPORT_BR_EDR) ||
       BTM_ReadConnectedTransportAddress(other_address, BT_TRANSPORT_LE))))
    {
            bdcpy(sec_event.link_down.bd_addr, p_dev->bd_addr);
            /* No connection, set status to success (acl disc code not valid) */
            sec_event.link_down.status = HCI_SUCCESS;
            bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event);
        continue_delete_other_dev = FALSE;
        /* Take the link down first, and mark the device for removal when disconnected */
        for(int i=0; i < bta_dm_cb.device_list.count; i++)
        {
            if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, other_address))
            {
                bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
                btm_remove_acl(other_address,bta_dm_cb.device_list.peer_device[i].transport);
                break;
            }
        }
    }
    else
    {
        APPL_TRACE_DEBUG("%s: continue to delete the other dev ", __func__);
        continue_delete_other_dev = TRUE;
    }

    /* Delete the device mentioned in the msg */
    if (continue_delete_dev)
        bta_dm_process_remove_device(p_dev->bd_addr);

    /* Delete the other paired device too */
    BD_ADDR dummy_bda = {0};
    if (continue_delete_other_dev && (bdcmp(other_address, dummy_bda) != 0))
        bta_dm_process_remove_device(other_address);
}

/*******************************************************************************
+51 −0
Original line number Diff line number Diff line
@@ -652,6 +652,57 @@ void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR
    BTM_TRACE_DEBUG ("btm_find_dev_type - device_type = %d addr_type = %d", *p_dev_type , *p_addr_type);
}


/*******************************************************************************
**
** Function         BTM_ReadConnectedTransportAddress
**
** Description      This function is called to read the paired device/address type of other device paired
**                  corresponding to the BD_address
**
** Parameter        remote_bda: remote device address, carry out the transport address
**                  transport: active transport
**
** Return           TRUE if an active link is identified; FALSE otherwise
**
*******************************************************************************/
BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, tBT_TRANSPORT transport)
{
    tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(remote_bda);
    tACL_CONN *p = btm_bda_to_acl(remote_bda, transport);

    /* if no device can be located, return */
    if (p_dev_rec == NULL)
        return FALSE;

    if (transport == BT_TRANSPORT_BR_EDR)
    {
        if (btm_bda_to_acl(p_dev_rec->bd_addr, transport) != NULL)
        {
            memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
            return TRUE;
        }
        else if (p_dev_rec->device_type & BT_DEVICE_TYPE_BREDR)
        {
            memcpy(remote_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
        }
        else
            memset(remote_bda, 0, BD_ADDR_LEN);
        return FALSE;
    }

    if (transport == BT_TRANSPORT_LE)
    {
        memcpy(remote_bda, p_dev_rec->ble.pseudo_addr, BD_ADDR_LEN);
        if (btm_bda_to_acl(p_dev_rec->ble.pseudo_addr, transport) != NULL)
            return TRUE;
        else
            return FALSE;
    }

    return FALSE;
}

/*******************************************************************************
**
** Function         BTM_BleReceiverTest
+12 −12
Original line number Diff line number Diff line
@@ -176,21 +176,21 @@ BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr)
{
    tBTM_SEC_DEV_REC *p_dev_rec;

    if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) || BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR))
    if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
        BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR))
    {
        BTM_TRACE_WARNING("BTM_SecDeleteDevice FAILED: Cannot Delete when connection is active");
        return(FALSE);
        BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active", __func__);
        return FALSE;
    }

    if ((p_dev_rec = btm_find_dev (bd_addr)) == NULL)
        return(FALSE);

    if ((p_dev_rec = btm_find_dev(bd_addr)) != NULL)
    {
        btm_sec_free_dev(p_dev_rec);
        /* Tell controller to get rid of the link key, if it has one stored */
        BTM_DeleteStoredLinkKey (p_dev_rec->bd_addr, NULL);
    }

    /* Tell controller to get rid of the link key if it has one stored */
    BTM_DeleteStoredLinkKey (bd_addr, NULL);

    return(TRUE);
    return TRUE;
}

/*******************************************************************************
+1 −1
Original line number Diff line number Diff line
@@ -508,7 +508,7 @@ typedef struct
typedef UINT8 tBLE_ADDR_TYPE;
#define BLE_ADDR_TYPE_MASK      (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC)


#define BT_TRANSPORT_INVALID   0
#define BT_TRANSPORT_BR_EDR    1
#define BT_TRANSPORT_LE        2
typedef UINT8 tBT_TRANSPORT;
+17 −0
Original line number Diff line number Diff line
@@ -1428,6 +1428,23 @@ extern UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length);
extern void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type,
                                     tBLE_ADDR_TYPE *p_addr_type);


/*******************************************************************************
**
** Function         BTM_ReadConnectedTransportAddress
**
** Description      This function is called to read the paired device/address type of other device paired
**                  corresponding to the BD_address
**
** Parameter        remote_bda: remote device address, carry out the transport address
**                  transport: active transport
**
** Return           TRUE if an active link is identified; FALSE otherwise
**
*******************************************************************************/
extern BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda,
                                                 tBT_TRANSPORT transport);

/*******************************************************************************
**
** Function         BTM_BleBroadcast