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?