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

Bonding Problem

Hello

I am trying to create secure connection between peripheral device and mobile app & central device.

I created my own custom service and want to make them secure.

But i am getting

app: ERROR 2 [NRF_ERROR_SOFTDEVICE_NOT_ENABLED] at ......\main.c:525

and this line is in this function:

/**@brief Function for handling Peer Manager events.
 *
 * @param[in] p_evt  Peer Manager event.
 */
static void pm_evt_handler(pm_evt_t const * p_evt)
{
    ret_code_t err_code;

    switch (p_evt->evt_id)
    {
        case PM_EVT_BONDED_PEER_CONNECTED:
        {
            NRF_LOG_INFO("Connected to a previously bonded device.");
            // Start Security Request timer.
            err_code = app_timer_start(m_sec_req_timer_id, SECURITY_REQUEST_DELAY, NULL);
            APP_ERROR_CHECK(err_code);
        } break;

        case PM_EVT_CONN_SEC_SUCCEEDED:
        {
            pm_conn_sec_status_t conn_sec_status;

            // Check if the link is authenticated (meaning at least MITM).
            err_code = pm_conn_sec_status_get(p_evt->conn_handle, &conn_sec_status);
            APP_ERROR_CHECK(err_code);

            if (conn_sec_status.mitm_protected)
            {
                NRF_LOG_INFO("Link secured. Role: %d. conn_handle: %d, Procedure: %d",
                             ble_conn_state_role(p_evt->conn_handle),
                             p_evt->conn_handle,
                             p_evt->params.conn_sec_succeeded.procedure);
            }
            else
            {
                // The peer did not use MITM, disconnect.
                NRF_LOG_INFO("Collector did not use MITM, disconnecting");
                err_code = pm_peer_id_get(m_conn_handle, &m_peer_to_be_deleted);
                APP_ERROR_CHECK(err_code);
                err_code = sd_ble_gap_disconnect(m_conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
            }
        } break;

        case PM_EVT_CONN_SEC_FAILED:
        {
            NRF_LOG_INFO("Failed to secure connection. Disconnecting.");
            err_code = sd_ble_gap_disconnect(m_conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
        } break;

        case PM_EVT_CONN_SEC_CONFIG_REQ:
        {
            // Reject pairing request from an already bonded peer.
            pm_conn_sec_config_t conn_sec_config = {.allow_repairing = false};
            pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
        } break;

        case PM_EVT_STORAGE_FULL:
        {
            // Run garbage collection on the flash.
            err_code = fds_gc();
            if (err_code == FDS_ERR_BUSY || err_code == FDS_ERR_NO_SPACE_IN_QUEUES)
            {
                // Retry.
            }
            else
            {
                APP_ERROR_CHECK(err_code);
            }
        } break;

        case PM_EVT_PEERS_DELETE_SUCCEEDED:
        {
            NRF_LOG_DEBUG("PM_EVT_PEERS_DELETE_SUCCEEDED [ advertising_start ]");
            advertising_start(/*false*/);
        } break;

        case PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED:
        {
            // The local database has likely changed, send service changed indications.
            pm_local_database_has_changed();
        } break;

        case PM_EVT_PEER_DATA_UPDATE_FAILED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.peer_data_update_failed.error);
        } break;

        case PM_EVT_PEER_DELETE_FAILED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.peer_delete_failed.error);
        } break;

        case PM_EVT_PEERS_DELETE_FAILED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.peers_delete_failed_evt.error);
        } break;

        case PM_EVT_ERROR_UNEXPECTED:
        {
            // Assert.
            APP_ERROR_CHECK(p_evt->params.error_unexpected.error);
        } break;

        case PM_EVT_CONN_SEC_START:
        case PM_EVT_PEER_DATA_UPDATE_SUCCEEDED:
        case PM_EVT_PEER_DELETE_SUCCEEDED:
        case PM_EVT_LOCAL_DB_CACHE_APPLIED:
        case PM_EVT_SERVICE_CHANGED_IND_SENT:
        case PM_EVT_SERVICE_CHANGED_IND_CONFIRMED:
        default:
            break;
    }
}
//

and event is: PM_EVT_PEER_DATA_UPDATE_FAILED

How can fix this issue and what am i missing?

I am using nRF52832 and SD132

Here is my project file. ble_app_blinky.7z

  • Here is an update:

    Now i get this error: app: ERROR 2 [NRF_ERROR_SOFTDEVICE_NOT_ENABLED] at ......\main.c:525

    Which is in the handler function case PM_EVT_ERROR_UNEXPECTED

    static void pm_evt_handler(pm_evt_t const * p_evt)
    {
        ret_code_t err_code;
    
        switch (p_evt->evt_id)
        {
            case PM_EVT_BONDED_PEER_CONNECTED:
            {
                NRF_LOG_INFO("Connected to a previously bonded device.");
                // Start Security Request timer.
                err_code = app_timer_start(m_sec_req_timer_id, SECURITY_REQUEST_DELAY, NULL);
                APP_ERROR_CHECK(err_code);
            } break;
    
            case PM_EVT_CONN_SEC_SUCCEEDED:
            {
                pm_conn_sec_status_t conn_sec_status;
    
                // Check if the link is authenticated (meaning at least MITM).
                err_code = pm_conn_sec_status_get(p_evt->conn_handle, &conn_sec_status);
                APP_ERROR_CHECK(err_code);
    
                if (conn_sec_status.mitm_protected)
                {
                    NRF_LOG_INFO("Link secured. Role: %d. conn_handle: %d, Procedure: %d",
                                 ble_conn_state_role(p_evt->conn_handle),
                                 p_evt->conn_handle,
                                 p_evt->params.conn_sec_succeeded.procedure);
                }
                else
                {
                    // The peer did not use MITM, disconnect.
                    NRF_LOG_INFO("Collector did not use MITM, disconnecting");
                    err_code = pm_peer_id_get(m_conn_handle, &m_peer_to_be_deleted);
                    APP_ERROR_CHECK(err_code);
                    err_code = sd_ble_gap_disconnect(m_conn_handle,
                                                     BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                    APP_ERROR_CHECK(err_code);
                }
            } break;
    
            case PM_EVT_CONN_SEC_FAILED:
            {
                NRF_LOG_INFO("Failed to secure connection. Disconnecting.");
                err_code = sd_ble_gap_disconnect(m_conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
                m_conn_handle = BLE_CONN_HANDLE_INVALID;
            } break;
    
            case PM_EVT_CONN_SEC_CONFIG_REQ:
            {
                // Reject pairing request from an already bonded peer.
                pm_conn_sec_config_t conn_sec_config = {.allow_repairing = false};
                pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
            } break;
    
            case PM_EVT_STORAGE_FULL:
            {
                // Run garbage collection on the flash.
                err_code = fds_gc();
                if (err_code == FDS_ERR_BUSY || err_code == FDS_ERR_NO_SPACE_IN_QUEUES)
                {
                    // Retry.
                }
                else
                {
                    APP_ERROR_CHECK(err_code);
                }
            } break;
    
            case PM_EVT_PEERS_DELETE_SUCCEEDED:
            {
                NRF_LOG_DEBUG("PM_EVT_PEERS_DELETE_SUCCEEDED [ advertising_start ]");
                advertising_start(/*false*/);
            } break;
    
            case PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED:
            {
                // The local database has likely changed, send service changed indications.
                pm_local_database_has_changed();
            } break;
    
            case PM_EVT_PEER_DATA_UPDATE_FAILED:
            {
                // Assert.
                **APP_ERROR_CHECK(p_evt->params.peer_data_update_failed.error);**
            } break;
    
            case PM_EVT_PEER_DELETE_FAILED:
            {
                // Assert.
                APP_ERROR_CHECK(p_evt->params.peer_delete_failed.error);
            } break;
    
            case PM_EVT_PEERS_DELETE_FAILED:
            {
                // Assert.
                APP_ERROR_CHECK(p_evt->params.peers_delete_failed_evt.error);
            } break;
    
            **case PM_EVT_ERROR_UNEXPECTED:**
            {
                // Assert.
                APP_ERROR_CHECK(p_evt->params.error_unexpected.error);
            } break;
    
            case PM_EVT_CONN_SEC_START:
            case PM_EVT_PEER_DATA_UPDATE_SUCCEEDED:
            case PM_EVT_PEER_DELETE_SUCCEEDED:
            case PM_EVT_LOCAL_DB_CACHE_APPLIED:
            case PM_EVT_SERVICE_CHANGED_IND_SENT:
            case PM_EVT_SERVICE_CHANGED_IND_CONFIRMED:
            default:
                break;
        }
    }
    
  • Which SDK and SoftDevice are you using? Did you start off with an example using Peer Manager? Do you have any logs showing what is going on?

    You are getting PM_EVT_ERROR_UNEXPECTED? Have you tried to debug further to see where it originates from?

    Also consider uploading your complete project so I can test it here. You can do it by editing your question and clicking the paper clip icon.

  • Hello Peter.

    Which SDK and SoftDevice are you using?

    I am using SD132, nRF5_SDK_14.2.0_17b948a, nRF52840.

    Did you start off with an example using Peer Manager?

    Yes i did. In fact i used ble_app_gls example.

    Do you have any logs showing what is going on?

    Here is my project definetions. DEBUG BOARD_PCA10040 CONFIG_GPIO_AS_PINRESET FLOAT_ABI_HARD NRF52 NRF52832_XXAA NRF52_PAN_74 NRF_SD_BLE_API_VERSION=5 S132 SOFTDEVICE_PRESENT SWI_DISABLE0

    Here is my console log (i opened colored log);

    [0m<info> app: First time boot[0m
    [0m<info> app: --> Event received: wrote 44 bytes at address 0x3E000.[0m
    [0m<info> app: Fast advertising[0m
    [0m<info> app: Blinky example started.[0m
    [0m<info> app: Connected[0m
    [1;31m<error> app: ERROR 2 [NRF_ERROR_SOFTDEVICE_NOT_ENABLED] at ..\..\..\main.c:548[0m
    

    You are getting PM_EVT_ERROR_UNEXPECTED?

    That is right. In the pm_evt_handler case

    case PM_EVT_ERROR_UNEXPECTED:
    {
        // Assert.
        APP_ERROR_CHECK(p_evt->params.error_unexpected.error);
    } break;
    

    Have you tried to debug further to see where it originates from?

    I made some debug to see what is going on. But did not get much more info. In fact, i did not find explanation for this error code. Usally when i get an error code, i am looking for some explanation for that. And that helps me alot.But i did not find for this error.

    Some how i got some feelings that i am getting this because my main loop is this;

    // any pending write request?
    		if( pending_write == true )
    		{
    			// clear write request
    			pending_write = false;
    			
    			// write to flash and check for errors
    			err_code = nrf_fstorage_write( &fstorage, APP_FLASH_START_ADDRESS, &config, sizeof( config_t ), NULL );
    			APP_ERROR_CHECK( err_code );
    		}
    		
            if (NRF_LOG_PROCESS() == false)
            {
                power_manage();
            }
    

    Am i feeling right?

    Also consider uploading your complete project so I can test it here. You can do it by editing your question clicking the paper clip icon.

    I guess this is best way. BTW i need docs to understand ble and nordic sdk. I may have a little confuse.

  • I still did not solve this problem. Can some one help a little?

Related