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

Commit 83f968e2 authored by Hemant Gupta's avatar Hemant Gupta
Browse files

GAP: Retain the old COD if already present

Retain the old COD as the initial value if the device
entry already present in the list and entry is not in use.

Change-Id: I99b7269b1976ef7458c6568441e6e3c1e015a75f
parent 3270c976
Loading
Loading
Loading
Loading
+37 −3
Original line number Original line Diff line number Diff line
@@ -226,21 +226,55 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
    tBTM_SEC_DEV_REC *p_dev_rec = NULL;
    tBTM_SEC_DEV_REC *p_dev_rec = NULL;
    tBTM_INQ_INFO    *p_inq_info;
    tBTM_INQ_INFO    *p_inq_info;
    int               i;
    int               i;
    DEV_CLASS         old_cod;
    int               i_new_entry = BTM_SEC_MAX_DEVICE_RECORDS;
    int               i_old_entry = BTM_SEC_MAX_DEVICE_RECORDS;
    BTM_TRACE_EVENT ("btm_sec_alloc_dev");
    BTM_TRACE_EVENT ("btm_sec_alloc_dev");

    for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++)
    {
        /* look for old entry where device details are present */
        if (!(btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE) &&
             (!memcmp (btm_cb.sec_dev_rec[i].bd_addr, bd_addr, BD_ADDR_LEN)))
        {
            i_old_entry = i;
            BTM_TRACE_EVENT ("btm_sec_alloc_dev  old device found");
            break;
        }
    }

    for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++)
    for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++)
    {
    {
        if (!(btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE))
        if (!(btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE))
        {
        {
            p_dev_rec = &btm_cb.sec_dev_rec[i];
            i_new_entry = i;
            break;
            break;
        }
        }
    }
    }


    if (!p_dev_rec)
    if (i_new_entry == BTM_SEC_MAX_DEVICE_RECORDS) {
        p_dev_rec = btm_find_oldest_dev();
        p_dev_rec = btm_find_oldest_dev();

    }
    else {
        /* if the old device entry not present go with
            new entry */
        if(i_old_entry == BTM_SEC_MAX_DEVICE_RECORDS) {
            p_dev_rec = &btm_cb.sec_dev_rec[i_new_entry];
        }
        else {
            p_dev_rec = &btm_cb.sec_dev_rec[i_old_entry];
            memcpy (old_cod, p_dev_rec->dev_class, DEV_CLASS_LEN);
        }
    }
    memset (p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC));
    memset (p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC));


    /* Retain the old COD for device */
    if(i_old_entry != BTM_SEC_MAX_DEVICE_RECORDS) {
        BTM_TRACE_EVENT ("btm_sec_alloc_dev restoring cod ");
        memcpy (p_dev_rec->dev_class, old_cod, DEV_CLASS_LEN);

    }

    p_dev_rec->sec_flags = BTM_SEC_IN_USE;
    p_dev_rec->sec_flags = BTM_SEC_IN_USE;


    /* Check with the BT manager if details about remote device are known */
    /* Check with the BT manager if details about remote device are known */