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

Commit 4c3d7f15 authored by Priti Aghera's avatar Priti Aghera Committed by Matthew Xie
Browse files

Fixed unpair and reconnect issue with certain non-pointing hid devices

Hid info would not be removed from storage if COD is
NON_KEYBOARD_NON_POINTING. Due to this the device will
be added to stack even if it is unpaired and subsequent connections
will fail.
bug 8055549

Change-Id: Ib493fc165120de3c71398f5fe24b17f31fa5fc3e
parent 30ddcc2d
Loading
Loading
Loading
Loading

system/btif/src/btif_dm.c

100755 → 100644
+30 −12
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@
#define COD_HID_KEYBOARD                    0x0540
#define COD_HID_POINTING                    0x0580
#define COD_HID_COMBO                       0x05C0
#define COD_HID_MAJOR                       0x0500
#define COD_AV_HEADSETS                     0x0404
#define COD_AV_HANDSFREE                    0x0408
#define COD_AV_HEADPHONES                   0x0418
@@ -238,6 +239,24 @@ BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
    return FALSE;
}

BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
{
    uint32_t    remote_cod;
    bt_property_t prop_name;

    /* check if we already have it in our btif_storage cache */
    BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
                               sizeof(uint32_t), &remote_cod);
    if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
                                &prop_name) == BT_STATUS_SUCCESS)
    {
        if ((remote_cod & 0x700) == cod)
            return TRUE;
    }

    return FALSE;
}

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 */
@@ -408,9 +427,7 @@ void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
{
     bdstr_t bdstr;
     /*special handling for HID devices */
     if (check_cod(bd_addr, COD_HID_POINTING) ||
        check_cod(bd_addr, COD_HID_KEYBOARD) ||
        check_cod(bd_addr, COD_HID_COMBO))
     if (check_cod_hid(bd_addr, COD_HID_MAJOR))
    {
        #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
        if(remove_hid_bond(bd_addr) != BTA_SUCCESS)
@@ -1182,7 +1199,8 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)

            /*special handling for HID devices */
            #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
            if (check_cod(&bd_addr, COD_HID_KEYBOARD )|| check_cod(&bd_addr, COD_HID_COMBO) || check_cod(&bd_addr, COD_HID_POINTING)) {
            if (check_cod_hid(&bd_addr, COD_HID_MAJOR))
            {
                btif_hh_remove_device(bd_addr);
            }
            #endif
+4 −9
Original line number Diff line number Diff line
@@ -601,6 +601,7 @@ bt_status_t btif_hh_connect(bt_bdaddr_t *bd_addr)
            return BT_STATUS_FAIL;
        }
    }

    if (added_dev == NULL ||
        (added_dev->attr_mask & HID_NORMALLY_CONNECTABLE) != 0 ||
        (added_dev->attr_mask & HID_RECONN_INIT) == 0)
@@ -610,20 +611,14 @@ bt_status_t btif_hh_connect(bt_bdaddr_t *bd_addr)
        BD_ADDR *bda = (BD_ADDR*)bd_addr;
        BTA_HhOpen(*bda, BTA_HH_PROTO_RPT_MODE, sec_mask);
    }
    else {
    else 
    {
        // This device shall be connected from the host side.
        BTIF_TRACE_ERROR2("%s: Error, device %s can only be reconnected from device side",
             __FUNCTION__, bda_str);
        //TODO
       /* if ((remote_class & BT_DEV_CLASS_MASK) == BT_DEV_CLASS_HID_POINTING) {
            //SIG_HH_CONNECTION, *bda, HH_CONN_STATUS_FAILED_MOUSE_FROM_HOST);
        }
        else {
           // SIG_HH_CONNECTION, *bda, HH_CONN_STATUS_FAILED_KBD_FROM_HOST);
        }*/
        return BT_STATUS_FAIL;

    }

    HAL_CBACK(bt_hh_callbacks, connection_state_cb, bd_addr, BTHH_CONN_STATE_CONNECTING);
    return BT_STATUS_SUCCESS;
}