Maximum number of devices that can be paired

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_3572401
Level 3
Level 3
First like received

I am using CYBT-343026-EVAL with WICED 6.2 now.

Could you tell me how many BT-Headset can pairing to this module at the same time?

If the number can change,could you tell me where can I change it?shjlaxel.lin_1746341goto-t_2353976user_437857088user_140663973

0 Likes
1 Solution

num_bond is a macro defination need to be added by yourself. You can define it with 10 for 10 paired devices' infromation to store.

View solution in original post

0 Likes
4 Replies
Owen_Zhang123
Moderator
Moderator
Moderator
5 questions asked 500 solutions authored 250 sign-ins

You need to make some change with the function headset_save_link_keys and headset_read_link_keys if you want to save more pairing information. The following code is a snip about the function. The device can store a fixed number of bonding devices(parameter "num_bond" in the code). The new device will overwrite the old one if the size is full. Please modify your own code with the reference of the snip.

wiced_bool_t headset_save_link_keys(wiced_bt_device_link_keys_t *p_keys)

{

    uint8_t                     bytes_written = 0, bytes_read;

    wiced_result_t              result;

    uint8_t                     nvram_id = HEADSET_NVRAM_ID;

    wiced_bt_device_link_keys_t keys;

    uint8_t                     i=0;

    uint8_t                     device_saved=0;

    uint8_t                     device_id=0;

    // there might be a situation where the keys are already saved, for example in dual mode

    // device the br/edr keys can be present when we are doing le pairing

    for(i=0; i<num_bond; i++)

    {

        bytes_read = wiced_hal_read_nvram(nvram_id+i, sizeof(wiced_bt_device_link_keys_t), (uint8_t *)&keys, &result);

        WICED_BT_TRACE("keys.bd_addr:%B p_keys:%B keys static:%B p_keys:%B\n", keys.bd_addr, p_keys->bd_addr, keys.key_data.static_addr, p_keys->key_data.static_addr);

        if ((bytes_read == sizeof(wiced_bt_device_link_keys_t)) &&

        (memcmp(p_keys->bd_addr, keys.bd_addr, BD_ADDR_LEN) == 0))

        {

            WICED_BT_TRACE("Device address already exist: %d", nvram_id+i);

            bytes_written = wiced_hal_write_nvram(nvram_id+i, sizeof(wiced_bt_device_link_keys_t), (uint8_t *)p_keys, &result);

            device_saved=1;

            break;

        }

    }

    if(device_saved==0)

    {

        wiced_hal_read_nvram(nvram_id+num_bond,sizeof(uint8_t),(uint8_t *)&device_id, &result);

        bytes_written = wiced_hal_write_nvram(device_id+nvram_id, sizeof(wiced_bt_device_link_keys_t), (uint8_t *)p_keys, &result);

        WICED_BT_TRACE("Saved %d bytes at id:%d result:%d\n", bytes_written, device_id, result);

        device_id++;

        if(device_id >= num_bond)

        {

            device_id=0;

        }

        wiced_hal_write_nvram(nvram_id+num_bond, sizeof(uint8_t), (uint8_t *)&device_id, &result);

        return (bytes_written == sizeof (wiced_bt_device_link_keys_t));

    }

    // try to figure out what is being updated

//    if (p_keys->key_data.le_keys_available_mask != 0)

//    {

//        WICED_BT_TRACE("updating LE keys\n");

//        keys.key_data.le_keys_available_mask = p_keys->key_data.le_keys_available_mask;

//        keys.key_data.ble_addr_type          = p_keys->key_data.ble_addr_type;

//        keys.key_data.static_addr_type       = p_keys->key_data.static_addr_type;

//        memcpy (keys.key_data.static_addr, p_keys->key_data.static_addr, sizeof(p_keys->key_data.static_addr));

//        memcpy (&keys.key_data.le_keys, &p_keys->key_data.le_keys, sizeof(p_keys->key_data.le_keys));

//    }

//    else

//    {

//        WICED_BT_TRACE("updating BR/EDR keys\n");

//        keys.key_data.br_edr_key_type       = p_keys->key_data.br_edr_key_type;

//        memcpy (keys.key_data.br_edr_key, p_keys->key_data.br_edr_key, sizeof(p_keys->key_data.br_edr_key));

//    }

//    WICED_BT_TRACE("Saved %d bytes at id:%d result:%d\n", bytes_written, nvram_id, result);

    return WICED_TRUE;

}

/*

* This function is called to read keys for specific bdaddr

*/

wiced_bool_t headset_read_link_keys(wiced_bt_device_link_keys_t *p_keys)

{

    uint8_t                     bytes_read;

    wiced_result_t              result;

    wiced_bt_device_link_keys_t keys;

    uint8_t                     nvram_id = HEADSET_NVRAM_ID;

    uint8_t                     i;

    uint8_t                     find_flag=0;

    for(i=0; i<num_bond; i++)

    {

        bytes_read = wiced_hal_read_nvram(nvram_id+i, sizeof(wiced_bt_device_link_keys_t), (uint8_t *)&keys, &result);

        WICED_BT_TRACE("keys.bd_addr:%B p_keys:%B keys static:%B p_keys:%B\n", keys.bd_addr, p_keys->bd_addr, keys.key_data.static_addr, p_keys->key_data.static_addr);

        if ((bytes_read == sizeof(wiced_bt_device_link_keys_t)) &&

        (memcmp(p_keys->bd_addr, keys.bd_addr, BD_ADDR_LEN) == 0))

        {

            WICED_BT_TRACE("Device address already exist: %d", nvram_id+i);

            bytes_read = wiced_hal_read_nvram(nvram_id+i, sizeof(wiced_bt_device_link_keys_t), (uint8_t *)p_keys, &result);

            find_flag=1;

            return (bytes_read == sizeof (wiced_bt_device_link_keys_t));

        }

    }

    if(find_flag == 0)

    {

        return NULL;

    }

}

num_bond is not defined in your change.

Where should it be defined and what number should it be defined?shjluser_437857088goto-t_2353976

0 Likes

num_bond is a macro defination need to be added by yourself. You can define it with 10 for 10 paired devices' infromation to store.

0 Likes

Whether I can change max number  of pairing device if I changed my own code to your upon code .

I have tried some way to change Max number of pairing device.

I changed here.hci_control.h:Line:79

[#define HCI_CONTROL_AG_NUM_SCB          2           /* Max simultaneous connections to HFs */]

I changed HCI_CONTROL_AG_NUM_SCB from 2 to 1.

The result is CYBT-343026-EVAL can only pair to 1 device only at the same time .

Then I changed HCI_CONTROL_AG_NUM_SCB from 1 to 3.

The result is CYBT-343026-EVAL can  not pair to 3 device,it just can pair to 2 device only.

I guess there is a restriction exits somewhere.I am finding it.

Do you know it?shjlgoto-t_2353976user_437857088user_140663973

0 Likes