How to delete specific bonding info in Peripheral when Central has "forgotten" the pairing/bonding

This is my environment:

IDE: VSC

SDK: NCS v2.2.0

Central - iOS or Android phone running custom App, or an nRF52832 on custom hardware

Peripheral - nRF52832 on custom hardware

In our application, we have a Peripheral that can, at various times during its operation, be paired and bonded to any number of Centrals (at the moment, I've set this limit to 10).  Connections to the Peripheral require pairing/bonding with the Central. If I get more than 10 different Centrals attempting to connect over the lifetime of the device, I need to start removing old pairing/bonding information.  Alternatively, if a Central has deleted its pairing/bonding info for whatever reason, and then subsequently wants to connect to the Peripheral, I need to first remove the old pairing/bonding info on the Peripheral associated with that Central, and then re-establish new pairing/bonding info.

The catch is, I don't want to ever remove the pairing/bonding info that has been established and stored after a connection to my Peripheral from the Central that is running on my other set of custom hardware.  This device has no way of agreeing to a new pair/bond request out in the field (its set up in the factory to only talk with specific Peripherals), so I don't want to ever remove that.

In my firmware to date, if I get a situation where a Central that has forgotten its pairing/bonding info tries to connect to the Peripheral, I make this call:

static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	#ifdef DEBUG
		printk("ERROR: Pairing failed conn: %s, reason %d\n", addr, reason);
	#endif

	if (reason == BT_SECURITY_ERR_AUTH_REQUIREMENT) {
		#ifdef DEBUG_BLE
			printk("INFO: Removing pairing info\n");
		#endif
		bt_unpair(BT_ID_DEFAULT, BT_ADDR_LE_ANY);
	}

	bonded_to_client = false;

	bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
}

The bt_unpair(BT_ID_DEFAULT, BT_ADDR_LE_ANY) removes EVERYTHING.  Which is not what I want to do.

So, I have two questions:

  1. In the situation where the Central has forgotten the pairing/bonding info, and I only want to delete the info associated with that Central from my Peripheral, how do I establish what the correct id and addr are to include in my call to bt_unpair(id, addr)?
  2. When I get to 10 Centrals with pairing/bonding info, how do I start writing over the top of old ones, but avoid writing over the info associated with my Client that uses the nRF52832 on my custom hardware?  i.e. how do I find out what its id and addr are so that I can somehow prevent this being written over or removed?

Regards,

Mike

Parents Reply Children
Related