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?

  • Hi,

    June20 said:

    Edit: Central looks very tricky. hrs_c has whitelist-ing stuffs but it's related to peers

    pm_peer_id_t says it is uint16_t, how does it carry whitelist data??

    does central has something like ble_advertising_whitelist_reply()?

    my central's NRF_BLE_SCAN_EVT_CONNECTED display totally different ble address compare to my peripheral's device address(NRF_FICR->DEVICEADDR[0,1]), is it possible?

    Just as with peripherals, you don't need the peer manager to whitelist addresses. You can do it manually. But for a central this is related to scanning, and not advertising. Also as with the peripheral examples, you can see how it is done with the peer manager, but just replace the peer manager calls to get the whitelist from the peer manager with a whitelist you make yourself (which is just a list of addresses). I understand you already have referred to examples\ble_central\ble_app_hrs_c\main.c, and that is a good reference. Here you have the whitelist being handled mostly in the whitelist_load() and on_whitelist_req() functions. Remove the pm_* calls, and add code handling the whitelis manually, just like in the peripheral example I showed yesterday.

    Another point though is that whitelisting might not be relevant on the central. It is mostly useful when using IRKs as then the stack will handle address resolution etc. for you. If you just have a specific static address you want to connect to, then you can simply select to connect to that address. If you look at the scan_init() implementation in the same example you can see it filters on different things. You can simply filter on the address, and that is that.

    June20 said:

    Peripheral's side doesn't respond much but central's side constantly find connection and get disconnected for reason 2 and 3e

    what does it mean unknown connection identifier?

    I believe BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHEDd is due to constantly trying to connect?

    I guess this is with the whitelisting code? That has whitelisted a device I used to test, so you need to change the hard coded address to use another device. BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED (0x3e) is the expected disconnect reason when trying to connect with a device that use whitelist and you are not in it. That is because the peripheral will simply ignore connections from a central that is not in the whitelist. I am not sure why/where you would see BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER (2), though..

  • Einar Thorsrud said:
    Remove the pm_* calls, and add code handling the whitelis manually, just like in the peripheral example I showed yesterday.

    I was asking for help on this part because central/scanner's API seems very different. Is sd_ble_gap_whitelist_set() enough for adding whitelist? A bit confusing because you added whitelist before advertising start and added again(?) during BLE_ADV_EVT_WHITELIST_REQUEST (which can be handled with ble_advertising_whitelist_reply)

    Will adding whitelist with sd_ble_gap_whitelist_set() be enough before scanning? In whitelist_req and whitelist_load, there seems nothing but nrf_ble_scan_params_set() if I remove all pm_* and peer_*.

    About the filter part, assuming peripheral is using whitelist with specific address (though BLE_GAP_ADDR_TYPE_RANDOM_STATIC), will there be any trouble connecting each other?

    I know this one is bizarre, can gap address change or different when it is connected? I read ble address then added it UICR to connect it immediately but central's NRF_BLE_SCAN_EVT_CONNECTED is displaying totally different address when attempting to connect(then get disconnected).

    EDIT: I did try filter on the central's side (disabled whitelist) while peripheral whitelist enabled. The problem still persisting is NRF_BLE_SCAN_EVT_CONNECTED - it is displaying different address then what I set on address filter. Funny thing is I'm getting NRF_BLE_SCAN_EVT_FILTER_MATCH.

    I tried disabling whitelist on peripheral's side and it got connected this time. The problem is that the connected address is displaying totally different address ( I added nrf_log_info of p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr on BLE_GAP_EVT_CONNECTED. Like central's case, it is displaying totally different address). 

    address difference eg:

    Central's device address (NRF_FICR->DEVICEADDR[0,1]):

    (hex) B331 9540 C817
    (bin) 1011 0011 0011 0001 1001 0101 0100 0000 1100 1000 0001 0111

    What peripheral is connected to (p_ble_evt->evt.gap_evt.params.connected.peer_addr.addr[0~5]):

    (hex) 4095 31B3 17C8
    (bin) 0100 0000 1001 0101 0011 0001 1011 0011 0001 0111 1100 1000

    EDIT2: I found interesting pattern looking at both device: address array 123456 turns into 432165. Is it intended? does it affect filter and whitelist?

    EDIT3: Holy Christ! I've been doing it wrong! after arranging peripheral's whitelist address in order/pattern I found, it worked! Scanner's filter address order is the same but peripheral's whitelist address has to be rearranged.

    My Question changes: with whitelist and filter added, is bonding/pairing necessary? Can I get rid of both? I want to reduce connection time .

  • Hi,

    June20 said:
    with whitelist and filter added, is bonding/pairing necessary? Can I get rid of both? I want to reduce connection time .

    That depends on your goal. With whitelisting, you ensure that only whitelisted peers can be connected. This is not related to pairing/bonding (other than in the cases where the devices use a resolvable address, the peer needs the IRK which it gets when bonding).

    However, the primary point of pairing/bonding is to establish an encryption key that is used to encrypt the link. If you only whitelist, you will not have this, and anyone can listen in on the communication. Also, with bonding, some state information like the services etc. is stored between connections, and this is sometimes useful. If you only want to ensure that two specific devices can connect, and don't care about the other things (most notably encryption), then using only whitelisting is fine.

  • I guess I'll leave it on in case of no-address. 

    Does pairing/bonding affect power consumption?

    Can you please add rough code of central whitelisting just in case I decide to add IRK address please?

    I planning to change this thread into public since I didn't post my code, is it ok?

    Seriously, those sample codes you added for peripheral was really helpful because sorting out APIs based on limited examples are VERY difficult, especially when functions' name are different based on SDK or version.

    Always, thank you for answering.

  • June20 said:
    Does pairing/bonding affect power consumption?

    The pairing procedure can consume a bit of power, especially if you use LESC. But this is a one time operation. Using encrypted packets on the link does not contribute significantly to power consumption.

    June20 said:
    Can you please add rough code of central whitelisting just in case I decide to add IRK address please?

    If you want to use IRK (to use resolvable private address), then you need to bond. There are examples of bonding and whitelisting as central, for instance GATT Service Server Example Application. If you want to use resolvable address (in any role), you can refer to this post.

    June20 said:
    I planning to change this thread into public since I didn't post my code, is it ok?

    Yes, that is more than OK. Public threads are preferable Slight smile

Related