Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why are there no SoftDevice APIs that expose dynamic state?

I am using s132 v5.1.0 and am in the process of implementing an error-handling architecture.

I'm noticing that much of my error handling could be avoided if there were APIs to query the dynamic internals of the SoftDevice, especially one to get the connection state for a given connection handle.

Does the API I've been looking for actually exist? If not, why not? Any info on the motivation for this architecture would be helpful.

  • "To keep the predefined states updated, the module uses BLE events."

    This appears to be subject to the same limitation as any Application code. There's always a short period of time where the connection state is changed, but observers for the relevant BLE event have not been called.

    For example, in that period of time, sd_ble_gatts_hvx() will return INVALID_STATE. Can the code immediately check that this is due to pending disconnection, or does it have to wait for BLE_GAP_EVT_DISCONNECTED to confirm this?

  • Elias said:
    This appears to be subject to the same limitation as any Application code.

     Yes, that's true.  

    Elias said:
    Can the code immediately check that this is due to pending disconnection, or does it have to wait for BLE_GAP_EVT_DISCONNECTED to confirm this?

    It has to wait for a BLE_GAP_EVT_DISCONNECTED. Though that event is sent from the SoftDevice immediately after it has itself become aware of the disconnected state of the link. Though I guess you can get a race condition where the connection state library believes a connection is valid when it, in fact, is not. Ultimately you need to handle the invalid connection handle return code from the SoftDevice calls in a non-destructive way as any connection can drop at any moment. 

Related