Max connections and bonds (NCS)

I'm using NCS 2.6.0 for developing a subsystem consisting of a nRF52840-based Central and a number of nRF52840-based Peripheral devices.

First off, I get there are Kconfig controls for the maximum number of connections (CONFIG_BT_MAX_CONN) and bonds (CONFIG_BT_MAX_PAIRED).  I've seen posts that explain that the SoftDevices had limits for connections; for S140, it's 20.  Does that still apply to NCS, or is there a guide for NCS for what to set MAX_CONN for different devices?  Is MAX_PAIRED similarly constrained by the device or by available flash memory for storing bond info?

I'm also guessing that the bond info is stored in the "storage partition" - along with anything else that is being stored via NVS by the application.  Which, if true, would suggest that the number of bonds competes with the amount and rate of application stored data.  This doesn't seem right.

Second, I'm looking for what happens when either the memory for bonds is exhausted or the number of bonds reaches MAX_PAIRED and another connection is attempted.

On the Central, after Discovery, bt_conn_set_security() is called to do the bonding.  I'm guessing the security_changed() callback will receive a bt_security_err code, but nothing in the list of codes suggests "out of memory".

Or perhaps I should check the number of current bonds against MAX_PAIRED and not attempt a bond if it's already maxed out.  I'm not seeing a means of getting the current number of bonds, short of calling bt_foreach_bond() and counting them... which seems clumsy.

Third, while trying to track down answers, I came to zephyr/subsys/bluetooth/hosts/keys.c and see an array of size MAX_PAIRED.  In RAM.  I also see an interesting control CONFIG_BT_KEYS_OVERWRITE_OLDEST which (per Kconfig) allows the oldest key to be recycled.  Is "key" equivalent to "bond information"?  I don't see any correspondence of the key_pool array and any NVS activity.  What am I missing?

Parents
  • Hello David and sorry about the wait,

    The maximum number of connections in the SoftDevice (SD) that is being used in nRF5 SDK is 20. The Softdevice Controller(SDC) that we recommend using in nRF Connect SDK is based on the same thing, so it is also 20. The maximum amount of paired devices however is different, and only constrained by available memory. 

    When it comes to what happens when you reach the max, see here.

    Regards,

    Elfving

  • Same as SoftDevice.  Got it, thanks.

    From the linked "Pair with max connections full (NCS)":
    "You should get some SMP application error if there isn't any more room for new bonds"
    Not very helpful. I need to know what to anticipate if this happens.
    The BMS sample referenced doesn't really help; it merely prints the error code if a failure occurs - any failure.
    The other post referenced, "NFC BLE Pair with max connections full", is for nRF SDK - Peer Manager - and doesn't help with NCS.

    What does CONFIG_BT_KEYS_OVERWRITE_OLDEST do in the context of "no more room for new bonds"?

Reply
  • Same as SoftDevice.  Got it, thanks.

    From the linked "Pair with max connections full (NCS)":
    "You should get some SMP application error if there isn't any more room for new bonds"
    Not very helpful. I need to know what to anticipate if this happens.
    The BMS sample referenced doesn't really help; it merely prints the error code if a failure occurs - any failure.
    The other post referenced, "NFC BLE Pair with max connections full", is for nRF SDK - Peer Manager - and doesn't help with NCS.

    What does CONFIG_BT_KEYS_OVERWRITE_OLDEST do in the context of "no more room for new bonds"?

Children
  • Hi David, Håkon E is travelling this week. He will attend to this issue when he is back in office next week.

  • Hello again David, sorry about the wait again, as well as my previous response. I see that this didn't answer all of your questions. 

    Regarding getting the number off all current bonds, there doesn't seem to be any functions available for this. I agree that counting through bt_foreach_bond() seems clumsy, but it might be the best. Atleast I guess you only need to do this during boot, and update it after bonding a new device. You could also have this number written to flash persistently if you prefer to do it that way. Of course if the number of bonds is too high counting it up will affect runtime somewhat. 

    David Ormand said:
    What does CONFIG_BT_KEYS_OVERWRITE_OLDEST do in the context of "no more room for new bonds"?

    It overwrites the oldest key if key storage is full, which might be practical for your usecase. You can also define what full means for you with CONFIG_BT_MAX_PAIRED, which you've allready mentioned. 

    David Ormand said:

    The other post referenced, "NFC BLE Pair with max connections full", is for nRF SDK - Peer Manager - and doesn't help with NCS.

    I'll looking into this, and will get back to you on how this error shows up. I think it will be an ENOMEM error somewhere.

    Regards,

    Elfving

Related