How to get the public/static random address when a device uses a resolvable private address?
When a device is connected to a peer device, it assigns a handle to each connection. If the peripheral bonds with a particular central (Central 1), then it assigns a connection handle to that device only. A connection handle can have any one of these values 4, 3, 2, 1, or 0. When there is no bonded device, handle ‘4’ is assigned to all connections. After bonding with a particular device, it uses that particular connection handle only to the bonded device. For all other connections, the remaining free handles (3, 2, 1, or 0) are used. The limit on the number of connection handles is due to the limit on the number of bonded devices (four).
During the pairing process, devices exchange the keys and public/static random addresses. After exchanging the keys, the CYBLE_EVT_GAP_KEYINFO_EXCHNGE_CMPLT event will trigger. Now, you should get the public/static random address of the peer device. When bonding with the peer device, the public/static random address will be stored in the flash. The peer device may use public/static random/resolvable private addresses for connection. The address used for connection is stored in the bonded list. If the device changes the resolvable private address (RPA) for the next connection, the bonded list will be updated with this new address. Using APi CyBle_GapGetPeerDevSecurityKeyInfo (), we can get the stored public/static random address of the device. It fetches the data stored from flash.