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

Commit 05736f53 authored by Zhihai Xu's avatar Zhihai Xu
Browse files

Unable to connect to a Motorola s705 until Bluetooth was toggled of and back on

we should use the same role as the previous connection, if phone walk out of range,
and reconnect back from remote device.
bug:10648781

Change-Id: I6abd77067d26769067ba2fbd45d9e8f75cf7c764
parent 9927a55f
Loading
Loading
Loading
Loading
+49 −1
Original line number Diff line number Diff line
@@ -47,6 +47,52 @@ static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read

#define BTM_DEV_REPLY_TIMEOUT   3       /* 3 second timeout waiting for responses */

/*******************************************************************************
**
** Function         btm_save_remote_device_role
**
** Description      This function is to save remote device role
**
** Returns          void
**
*******************************************************************************/
static void btm_save_remote_device_role(BD_ADDR bd_addr, UINT8 role)
{
    UINT8 i, j;
    if (role == BTM_ROLE_UNDEFINED) return;

    for (i = 0; i < BTM_ROLE_DEVICE_NUM; i++) {
        if ((btm_cb.previous_connected_role[i] != BTM_ROLE_UNDEFINED) &&
            (!bdcmp(bd_addr, btm_cb.previous_connected_remote_addr[i]))) {
            break;
        }
    }

    if (i < BTM_ROLE_DEVICE_NUM) {
        UINT8 end;
        if (i < btm_cb.front) {
            for (j = i; j > 0; j--) {
                bdcpy(btm_cb.previous_connected_remote_addr[j],
                    btm_cb.previous_connected_remote_addr[j-1]);
            }
            bdcpy(btm_cb.previous_connected_remote_addr[0],
                btm_cb.previous_connected_remote_addr[BTM_ROLE_DEVICE_NUM-1]);
            end = BTM_ROLE_DEVICE_NUM-1;
        } else {
            end = i;
        }

        for (j = end; j > btm_cb.front; j--) {
            bdcpy(btm_cb.previous_connected_remote_addr[j],
                btm_cb.previous_connected_remote_addr[j-1]);
        }
    }

    bdcpy(btm_cb.previous_connected_remote_addr[btm_cb.front], bd_addr);
    btm_cb.previous_connected_role[btm_cb.front] = role;
    btm_cb.front = (btm_cb.front + 1) % BTM_ROLE_DEVICE_NUM;
}

/*******************************************************************************
**
** Function         btm_acl_init
@@ -158,6 +204,7 @@ void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
    {
        p->hci_handle = hci_handle;
        p->link_role  = link_role;
        btm_save_remote_device_role(bda, link_role);
#if BLE_INCLUDED == TRUE
        p->is_le_link = is_le_link;
#endif
@@ -175,6 +222,7 @@ void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
            p->in_use            = TRUE;
            p->hci_handle        = hci_handle;
            p->link_role         = link_role;
            btm_save_remote_device_role(bda, link_role);
            p->link_up_issued    = FALSE;

#if BLE_INCLUDED == TRUE
@@ -2194,7 +2242,7 @@ void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)

        /* Update cached value */
        p->link_role = new_role;

        btm_save_remote_device_role(p_bda, new_role);
        /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */
        if (new_role == BTM_ROLE_MASTER)
        {
+7 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ typedef char tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1];
*/
#define BTM_MAX_SCN      PORT_MAX_RFC_PORTS

/* Definition for number of the remote device role saved
*/
#define BTM_ROLE_DEVICE_NUM      4

/* Define masks for supported and exception 2.0 ACL packet types
*/
#define BTM_ACL_SUPPORTED_PKTS_MASK      (HCI_PKT_TYPES_MASK_DM1        | \
@@ -892,6 +896,9 @@ typedef struct
    tBTM_PCM2_ACTION        pcm2_action;
#endif

    BD_ADDR previous_connected_remote_addr[BTM_ROLE_DEVICE_NUM];
    UINT8   previous_connected_role[BTM_ROLE_DEVICE_NUM];
    UINT8   front; /* front index of the role table */
} tBTM_CB;


+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ tBTM_CB btm_cb;
*******************************************************************************/
void btm_init (void)
{
    UINT8 i;
    /* All fields are cleared; nonzero fields are reinitialized in appropriate function */
    memset(&btm_cb, 0, sizeof(tBTM_CB));

@@ -56,6 +57,9 @@ void btm_init (void)
#else
    btm_cb.trace_level = BT_TRACE_LEVEL_NONE;    /* No traces */
#endif
    for (i = 0; i < BTM_ROLE_DEVICE_NUM; i++) {
        btm_cb.previous_connected_role[i] = BTM_ROLE_UNDEFINED;
    }
    /* Initialize BTM component structures */
    btm_inq_db_init();                  /* Inquiry Database and Structures */
    btm_acl_init();                     /* ACL Database and Structures */
+1 −1
Original line number Diff line number Diff line
@@ -585,7 +585,7 @@ extern tL2C_LCB *l2cu_find_lcb_by_bd_addr (BD_ADDR p_bd_addr);
extern tL2C_LCB *l2cu_find_lcb_by_handle (UINT16 handle);
extern void     l2cu_update_lcb_4_bonding (BD_ADDR p_bd_addr, BOOLEAN is_bonding);

extern UINT8    l2cu_get_conn_role (tL2C_LCB *p_this_lcb);
extern UINT8    l2cu_get_conn_role (BD_ADDR bd_addr);
extern BOOLEAN  l2cu_set_acl_priority (BD_ADDR bd_addr, UINT8 priority, BOOLEAN reset_after_rs);

extern void     l2cu_enqueue_ccb (tL2C_CCB *p_ccb);
+2 −2
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ BOOLEAN l2c_link_hci_conn_req (BD_ADDR bd_addr)
            if (!btm_dev_support_switch (bd_addr))
                p_lcb->link_role = HCI_ROLE_SLAVE;
            else
                p_lcb->link_role = l2cu_get_conn_role(p_lcb);
                p_lcb->link_role = l2cu_get_conn_role(bd_addr);
        }

        /* Tell the other side we accept the connection */
@@ -119,7 +119,7 @@ BOOLEAN l2c_link_hci_conn_req (BD_ADDR bd_addr)
        if (!btm_dev_support_switch (bd_addr))
            p_lcb->link_role = HCI_ROLE_SLAVE;
        else
            p_lcb->link_role = l2cu_get_conn_role(p_lcb);
            p_lcb->link_role = l2cu_get_conn_role(bd_addr);

        btsnd_hcic_accept_conn (bd_addr, p_lcb->link_role);

Loading