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

Commit 75d8fea4 authored by Priti Aghera's avatar Priti Aghera
Browse files

Reload Hid info only for bonded device

Check if the device is bonded before loadind HID device information
after BT reset. If the HID info exists in NVRAM for unbonded device,
the device will not be able to repair.
bug 14837902

Change-Id: I5e6d5e8c5344ca8ae18f102e40867745d3f460ab
parent 5033e67f
Loading
Loading
Loading
Loading
+92 −34
Original line number Diff line number Diff line
@@ -427,6 +427,44 @@ static int cfg2prop(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
    return ret;
}

/*******************************************************************************
**
** Function         btif_in_fetch_bonded_devices
**
** Description      Internal helper function to fetch the bonded devices
**                  from NVRAM
**
** Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
**
*******************************************************************************/
static bt_status_t btif_in_fetch_bonded_device(char *bdstr)
{
    BOOLEAN bt_linkkey_file_found=FALSE;
    int device_type;

        int type = BTIF_CFG_TYPE_BIN;
        LINK_KEY link_key;
        int size = sizeof(link_key);
        if(btif_config_get("Remote", bdstr, "LinkKey", (char*)link_key, &size, &type))
        {
            int linkkey_type;
            if(btif_config_get_int("Remote", bdstr, "LinkKeyType", &linkkey_type))
            {
                bt_linkkey_file_found = TRUE;
            }
            else
            {
                bt_linkkey_file_found = FALSE;
            }
        }
        if((btif_in_fetch_bonded_ble_device(bdstr, FALSE, NULL) != BT_STATUS_SUCCESS)
                && (!bt_linkkey_file_found))
        {
            BTIF_TRACE_DEBUG1("Remote device:%s, no link key or ble key found", bdstr);
            return BT_STATUS_FAIL;
        }
    return BT_STATUS_SUCCESS;
}

/*******************************************************************************
**
@@ -1130,6 +1168,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b
    bt_bdaddr_t bd_addr;
    BD_ADDR bta_bd_addr;
    BOOLEAN is_device_added =FALSE;
    BOOLEAN key_found = FALSE;
    tBTA_LE_KEY_VALUE *p;

    if(!btif_config_get_int("Remote", remote_bd_addr,"DevType", &device_type))
@@ -1171,6 +1210,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b
                    BTIF_TRACE_DEBUG1("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));
@@ -1194,6 +1234,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b

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

            memset(buf, 0, sizeof(buf));
@@ -1220,6 +1261,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b

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

            memset(buf, 0, sizeof(buf));
@@ -1242,6 +1284,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b

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

            memset(buf, 0, sizeof(buf));
@@ -1264,6 +1307,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b

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

            /* Fill in the bonded devices */
@@ -1273,7 +1317,10 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b
                btif_gatts_add_bonded_dev_from_nv(bta_bd_addr);
            }

            if(key_found)
                return BT_STATUS_SUCCESS;
            else
                return BT_STATUS_FAIL;
    }
    return BT_STATUS_FAIL;
}
@@ -1375,6 +1422,8 @@ bt_status_t btif_storage_load_bonded_hid_info(void)
        kpos = btif_config_next_key(kpos, "Remote", kname, &kname_size);
        BTIF_TRACE_DEBUG2("Remote device:%s, size:%d", kname, kname_size);
        int value;
        if(btif_in_fetch_bonded_device(kname) == BT_STATUS_SUCCESS)
        {
            if(btif_config_get_int("Remote", kname, "HidAttrMask", &value))
            {
                attr_mask = (uint16_t)value;
@@ -1422,6 +1471,15 @@ bt_status_t btif_storage_load_bonded_hid_info(void)
                            app_id, dscp_info);
                }
            }
        }
        else
        {
            if(btif_config_get_int("Remote", kname, "HidAttrMask", &value))
            {
                btif_storage_remove_hid_info(&bd_addr);
                str2bd(kname, &bd_addr);
            }
        }
    } while(kpos != -1);

    return BT_STATUS_SUCCESS;