[nRF52833] Retrieve Advertising RPA Address during a Connection

Hi,

I'm working on a legacy program (Peripheral) using nRF52833 and nRF5 SDK using SoftDevice S113.

In my application, when a connection is established I need to know the Resolvable address that was active when the Central connected to my peripheral.

In my peripheral I'm using a Resolvable Random Private address that rotates every 30s using pm_privacy_set();

I tried calling sd_ble_gap_adv_addr_get() on BLE_EVT_CONNECTED, but the API fails since advertising is not enabled after a connection is established (and even if it succeeded, there is a race condition between the connection being established and the event being handled during which the RPA could have rotated).
Also I don't seem to be able to find any BLE GAP events that get triggered whenever the RPA rotates (if there is such event I could keep track of the latest active address after a rotation and use that when a connection is established)
What's the recommended/preferred way for knowing the RPA that my Peripheral was using during Advertising when the Central connected?
Thanks,
Marco
Parents
  • Hi Marco,

    The Softdevice does not include an event to signal the application when the address has been updated, unfortunately. However, as you may know, the RPA is also rotated when you start advertising. This can be utilized to enable the application control when the address is rotated instead of having the Softdevice perform it in the background.

    I discussed this case with the Softdevice team, and they suggested that you configured the advertiser with a 30 second timeout and to extend the .private_addr_cycle_s interval (i.e. set adv. timeout > .private_addr_cycle_s )  to ensure the address is only cycled when advertising is re-started. Then when you get the BLE_GAP_EVT_ADV_SET_TERMINATED after 30 seconds, you call adv. start again to restart the advertiser with a new RPA.

            /* Event reported by the adv. module when the Softdevice has raised the 
             * BLE_GAP_EVT_ADV_SET_TERMINATED event with reason BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_TIMEOUT
             */
            case BLE_ADV_EVT_IDLE:
            {
                ble_gap_addr_t addr;
                
                /* Re-start advertising with a new RPA */
                err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
                APP_ERROR_CHECK(err_code);
    
                err_code = sd_ble_gap_adv_addr_get(0, &addr);
                APP_ERROR_CHECK(err_code);
                
                /* Current RPA */
                NRF_LOG_INFO("RPA %02x:%02x:%02x:%02x:%02x:%02x",
                              addr.addr[5],
                              addr.addr[4],
                              addr.addr[3],
                              addr.addr[2],
                              addr.addr[1],
                              addr.addr[0]
                              );
            }  break;

    Best regards,

    Vidar

Reply
  • Hi Marco,

    The Softdevice does not include an event to signal the application when the address has been updated, unfortunately. However, as you may know, the RPA is also rotated when you start advertising. This can be utilized to enable the application control when the address is rotated instead of having the Softdevice perform it in the background.

    I discussed this case with the Softdevice team, and they suggested that you configured the advertiser with a 30 second timeout and to extend the .private_addr_cycle_s interval (i.e. set adv. timeout > .private_addr_cycle_s )  to ensure the address is only cycled when advertising is re-started. Then when you get the BLE_GAP_EVT_ADV_SET_TERMINATED after 30 seconds, you call adv. start again to restart the advertiser with a new RPA.

            /* Event reported by the adv. module when the Softdevice has raised the 
             * BLE_GAP_EVT_ADV_SET_TERMINATED event with reason BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_TIMEOUT
             */
            case BLE_ADV_EVT_IDLE:
            {
                ble_gap_addr_t addr;
                
                /* Re-start advertising with a new RPA */
                err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
                APP_ERROR_CHECK(err_code);
    
                err_code = sd_ble_gap_adv_addr_get(0, &addr);
                APP_ERROR_CHECK(err_code);
                
                /* Current RPA */
                NRF_LOG_INFO("RPA %02x:%02x:%02x:%02x:%02x:%02x",
                              addr.addr[5],
                              addr.addr[4],
                              addr.addr[3],
                              addr.addr[2],
                              addr.addr[1],
                              addr.addr[0]
                              );
            }  break;

    Best regards,

    Vidar

Children
Related