This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Peer manager - pm_conn_secure returning invalid state

In the case where connecting to a phone that is paired with my device after my device has cleared pairing information and doesn't remember the pair, I'm observing the following behavior:

When pm_conn_secure is called the first time it returns NRF_SUCCESS and subsequently receive a PM_EVT_CONN_SEC_START and PM_EVT_CONN_SEC_FAILED event.  The (android) phone seems to automatically delete the stored pair. 

Subsequent calls to pm_conn_secure do not return NRF_SUCCESS and instead return NRF_ERROR_INVALID_STATE.  The call produces a PM_EVT_CONN_SEC_PARAMS_REQ event to which I reply with the same ble_gap_sec_params_t I was using before.  This return value isn't really explained anywhere and I'm not sure what I'm doing wrong here.  Thanks for any input

  • Hi

    Are you able to see what error code  the PM_EVT_CONN_SEC_FAILED event generates in the first place?

    NRF_ERROR_INVALID STATE  returns from pm_conn_secure is explained in peer_manager.h as "If the Peer Manager is not initialized." So you will have to reinitialize the peer manager if you are getting this return value. 

    Best regards,

    Simon

  • procedure 0x0 (PM_LINK_SECURED_PROCEDURE_ENCRYPTION)

    error 0x1006

    error_src 0x0 (BLE_GAP_SEC_STATUS_SOURCE_LOCAL)

    The device readily re-pairs with the next connection, but not in the first connection after deleting bond information.

  • Hi

    The error 0x1006 (PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING) indicates that the phone hasn't deleted the stored pair, so if you do this before the first connection I think this should work fine.

    This post deals with a similar issue, so maybe you can find some hints there if this still doesn't work.

    Best regards,

    Simon

  • Thanks for your help so far.  This is indeed the case (phone has not deleted the stored pair, but nrf device has).  I'm wondering how to get peer manager to secure the connection (where the phone user approves pairing request again) in the same connection, because the current flow is to disconnect and let the next connection send pairing request.  I'd like to use peer manager properly in the same connection to enhance user experience but the way to use peer manager in this case isn't clear.

  • Hi

    To make a secure connection via bonding, I suggest you take a look at one of our examples doing just that, for example ble_app_proximity. (You can also test with an unmodified build of this example to ensure that you are able to bond properly).

    You can check out this case which describes how to check if there is existing bond info on the device you are pairing with already, which might cause errors. 

    Best regards,

    Simon

Related