Pairing specific pairs among many

Hello, we're trying to make products using BLE with nRF52840(central) and nRF52833(peripheral).

We did make custom boards and also made a program that once paired(bonded), it won't connect with others.

(eg, once nRF52840 and nRF52833 is paired, it will not connect with others)

We were wondering is there a way to make specific central connect with specific peripheral?

Is there a way to make each central/peripheral unique so that pairing process can be done without interference?

We got concerned that wrongly paired(or bonded) devices might ship out.

At our current stage, pairing wrong central/peripheral is possible.

Other infos.

nRF52840-central has 2 buttons, while nRF52833-peripheral has none

We're using SDK 17.1.0 S140 Segger Studio

has NUS(communication) and BAS(battery check) BLE services

thanks

edit:

extra question: is there a way to write certain unique number/MAC address on flash during flash write and then read it during application?

How do I know which address of flash is used or not?(want to avoid  collision with bonded info)

Is there a download tool beside nRF Connect Programmer?

Parents
  • Hi Joon,

    None of the pm_* APIs are relevant if you don't use bonding. I referred to pm_whitelist_get() just to see where it gets the whitelist (which is simply a list of addresses) from the peer manager and how to use it.

    You can see a very simple way to do whitelisting manually here:

    diff --git a/examples/ble_peripheral/ble_app_hrs/main.c b/examples/ble_peripheral/ble_app_hrs/main.c
    index 8e7c6f1..4bbfadc 100644
    --- a/examples/ble_peripheral/ble_app_hrs/main.c
    +++ b/examples/ble_peripheral/ble_app_hrs/main.c
    @@ -130,6 +130,8 @@
     
     #define DEAD_BEEF                           0xDEADBEEF                              /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
     
    +#define WHITELIST_ADDRESS {0xD8, 0x1E, 0x41, 0x50, 0x54, 0xE4}
    +
     
     BLE_HRS_DEF(m_hrs);                                                 /**< Heart rate service instance. */
     BLE_BAS_DEF(m_bas);                                                 /**< Structure used to identify the battery service. */
    @@ -189,6 +191,27 @@ static void delete_bonds(void)
     }
     
     
    +/**@brief Function for setting filtered whitelist.
    + *
    + * @param[in] skip  Filter passed to @ref pm_peer_id_list.
    + */
    +static void whitelist_set(void)
    +{
    +    ret_code_t err_code;
    +
    +    ble_gap_addr_t whitelist_addr =
    +    {
    +        .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
    +        .addr = WHITELIST_ADDRESS
    +    };
    +
    +    ble_gap_addr_t const * const p_whitelist_addr = &whitelist_addr;
    +
    +    err_code = sd_ble_gap_whitelist_set(&p_whitelist_addr, 1);
    +    APP_ERROR_CHECK(err_code);
    +}
    +
    +
     /**@brief Function for starting advertising.
      */
     void advertising_start(bool erase_bonds)
    @@ -202,6 +225,8 @@ void advertising_start(bool erase_bonds)
         {
             ret_code_t err_code;
     
    +        whitelist_set();
    +
             err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
             APP_ERROR_CHECK(err_code);
         }
    @@ -663,9 +688,9 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
     
         switch (ble_adv_evt)
         {
    -        case BLE_ADV_EVT_FAST:
    -            NRF_LOG_INFO("Fast advertising.");
    -            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
    +        case BLE_ADV_EVT_FAST_WHITELIST:
    +            NRF_LOG_INFO("Fast advertising with whitelist.");
    +            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_WHITELIST);
                 APP_ERROR_CHECK(err_code);
                 break;
     
    @@ -673,6 +698,25 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
                 sleep_mode_enter();
                 break;
     
    +        case BLE_ADV_EVT_WHITELIST_REQUEST:
    +        {
    +            NRF_LOG_INFO("Whitelist request")
    +            ble_gap_addr_t whitelist_addr =
    +            {
    +                .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
    +                .addr = WHITELIST_ADDRESS
    +            };
    +
    +            // Apply the whitelist.
    +            err_code = ble_advertising_whitelist_reply(&m_advertising,
    +                                                       &whitelist_addr,
    +                                                       1,
    +                                                       NULL,
    +                                                       0);
    +            APP_ERROR_CHECK(err_code);
    +        }
    +        break;
    +
             default:
                 break;
         }
    @@ -881,6 +925,7 @@ static void advertising_init(void)
         init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
         init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
     
    +    init.config.ble_adv_whitelist_enabled          = true;
         init.config.ble_adv_fast_enabled  = true;
         init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
         init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    

    (this is not very elegant as I just did minimal changes needed for the HRS example without caring about code duplication. As you can see if you compare with the HID mouse example it is basically the same thing, just that you provide the list of addresses (or just one address in this case) yourself instead of getting it from the peer manager.

Reply
  • Hi Joon,

    None of the pm_* APIs are relevant if you don't use bonding. I referred to pm_whitelist_get() just to see where it gets the whitelist (which is simply a list of addresses) from the peer manager and how to use it.

    You can see a very simple way to do whitelisting manually here:

    diff --git a/examples/ble_peripheral/ble_app_hrs/main.c b/examples/ble_peripheral/ble_app_hrs/main.c
    index 8e7c6f1..4bbfadc 100644
    --- a/examples/ble_peripheral/ble_app_hrs/main.c
    +++ b/examples/ble_peripheral/ble_app_hrs/main.c
    @@ -130,6 +130,8 @@
     
     #define DEAD_BEEF                           0xDEADBEEF                              /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
     
    +#define WHITELIST_ADDRESS {0xD8, 0x1E, 0x41, 0x50, 0x54, 0xE4}
    +
     
     BLE_HRS_DEF(m_hrs);                                                 /**< Heart rate service instance. */
     BLE_BAS_DEF(m_bas);                                                 /**< Structure used to identify the battery service. */
    @@ -189,6 +191,27 @@ static void delete_bonds(void)
     }
     
     
    +/**@brief Function for setting filtered whitelist.
    + *
    + * @param[in] skip  Filter passed to @ref pm_peer_id_list.
    + */
    +static void whitelist_set(void)
    +{
    +    ret_code_t err_code;
    +
    +    ble_gap_addr_t whitelist_addr =
    +    {
    +        .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
    +        .addr = WHITELIST_ADDRESS
    +    };
    +
    +    ble_gap_addr_t const * const p_whitelist_addr = &whitelist_addr;
    +
    +    err_code = sd_ble_gap_whitelist_set(&p_whitelist_addr, 1);
    +    APP_ERROR_CHECK(err_code);
    +}
    +
    +
     /**@brief Function for starting advertising.
      */
     void advertising_start(bool erase_bonds)
    @@ -202,6 +225,8 @@ void advertising_start(bool erase_bonds)
         {
             ret_code_t err_code;
     
    +        whitelist_set();
    +
             err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
             APP_ERROR_CHECK(err_code);
         }
    @@ -663,9 +688,9 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
     
         switch (ble_adv_evt)
         {
    -        case BLE_ADV_EVT_FAST:
    -            NRF_LOG_INFO("Fast advertising.");
    -            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
    +        case BLE_ADV_EVT_FAST_WHITELIST:
    +            NRF_LOG_INFO("Fast advertising with whitelist.");
    +            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_WHITELIST);
                 APP_ERROR_CHECK(err_code);
                 break;
     
    @@ -673,6 +698,25 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
                 sleep_mode_enter();
                 break;
     
    +        case BLE_ADV_EVT_WHITELIST_REQUEST:
    +        {
    +            NRF_LOG_INFO("Whitelist request")
    +            ble_gap_addr_t whitelist_addr =
    +            {
    +                .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
    +                .addr = WHITELIST_ADDRESS
    +            };
    +
    +            // Apply the whitelist.
    +            err_code = ble_advertising_whitelist_reply(&m_advertising,
    +                                                       &whitelist_addr,
    +                                                       1,
    +                                                       NULL,
    +                                                       0);
    +            APP_ERROR_CHECK(err_code);
    +        }
    +        break;
    +
             default:
                 break;
         }
    @@ -881,6 +925,7 @@ static void advertising_init(void)
         init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
         init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
     
    +    init.config.ble_adv_whitelist_enabled          = true;
         init.config.ble_adv_fast_enabled  = true;
         init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
         init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    

    (this is not very elegant as I just did minimal changes needed for the HRS example without caring about code duplication. As you can see if you compare with the HID mouse example it is basically the same thing, just that you provide the list of addresses (or just one address in this case) yourself instead of getting it from the peer manager.

Children
No Data
Related