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

How to add bond function to SDK12.3.0\app_ble_uart


Hi,
I am trying to add numeric comparison function to the project nRF5_SDK_12.3.0_d7731ad\examples\ble_peripheral\app_ble_uart\pca10028\s130.
in the project, there is no support for bonding.so i added the fds and peer_manager reference to the project app_ble_hrs. but there are something wrong with my code.
 
i was modified ble_evt_dispatch :
static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
    ble_conn_params_on_ble_evt(p_ble_evt);
    ble_nus_on_ble_evt(&m_nus, p_ble_evt);
    on_ble_evt(p_ble_evt);
    ble_advertising_on_ble_evt(p_ble_evt);
    //bsp_btn_ble_on_ble_evt(p_ble_evt);
    pm_on_ble_evt(p_ble_evt);
    
    dbgPrint("evt id = %d\n", p_ble_evt->header.evt_id);//testonly
}

i printed the ble_evt_id in ble_evt_dispatch() as follows:
 connected
 evt id = 16
 evt id = 18
 evt id = 18
 evt id = 18
 evt id = 19//BLE_GAP_EVT_SEC_PARAMS_REQUEST
 evt id = 18
 disconnected//out of 30 seconds so the link has been disconnected
 evt id = 17
 
by debug i found there is a error in pm_evt_handler() {case PM_EVT_ERROR_UNEXPECTED:},i don't know why this error occurs.
can i get an example of app_ble_uart with bond function?

any sugestions would be helpful.
Best Regards.

Parents Reply Children
  • Hi Einar,

    Thank you for your help.it is very useful!
    I used the project you modified,and modified some code to trigger the pairing (shown PIN and confirmed on the device side,shown PIN only on the cellphone, i.e. numeric comparison) when I turned on the notify.

    1,changed the function rx_char_add(),use BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&cccd_md.write_perm);instead of BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);

    2,changed some micro defines
    #define SEC_PARAM_BOND                   1                                           /**< Perform bonding. */
    #define SEC_PARAM_MITM                   1                                           /**< Man In The Middle protection required. */
    #define SEC_PARAM_LESC                   1                                           /**< LE Secure Connections enabled. */
    #define SEC_PARAM_KEYPRESS               0                                           /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES        BLE_GAP_IO_CAPS_DISPLAY_YESNO                        /**< have display and key to confirm. */
    #define SEC_PARAM_OOB                    0                                           /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE           7                                           /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE           16                                          /**< Maximum encryption key size. */

    3,add NRF_LOG_INFO("evt_id = %d\r\n", p_ble_evt->header.evt_id) in ble_evt_dispatch()

    and the LOG_INFO is:
    0> APP:INFO:NUS example started!
    0> APP:INFO:Connected to a previously bonded device.
    0> APP:INFO:Connected.
    0> APP:INFO:evt_id = 16
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    //now open the notify
    0> APP:INFO:evt_id = 19
    0> APP:INFO:evt_id = 25
    0> APP:INFO:evt_id = 18
    0> APP:INFO:Disconnected.
    0> APP:INFO:evt_id = 17
    0>

    Then i connect the device and open the notify again.the LOG_INFO is
    0> APP:INFO:Connected to a previously bonded device.
    0> APP:INFO:Connected.
    0> APP:INFO:evt_id = 16
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 18
    //now open the notify
    0> APP:INFO:evt_id = 19
    0> APP:INFO:evt_id = 21
    0> APP:INFO:evt_id = 18
    0> APP:INFO:evt_id = 25
    0> APP:INFO:Disconnected.
    0> APP:INFO:evt_id = 17
    0>
    and there a pairing window poped on the cellphone, not the numeric comparison but the passkey entry.
    how can i make the pairing as numeric comparison?

  • Hi Einar,
        To implement the numeric comparison function i made some minor changers to your project reference to the project nRF5_SDK_12.3.0_d7731ad\examples\ble_central_and_peripheral\experimental\ble_app_multirole_lesc\pca10028\s130\arm5_no_packs:
        
        1.in the peer_manager_init(),add
        sec_param.mitm           = SEC_PARAM_MITM;//SEC_PARAM_MITM = 1
        sec_param.lesc           = SEC_PARAM_LESC;//SEC_PARAM_LESC = 1
        
        2.in the rx_char_add(),modified the write_perm;
        //BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
        BLE_GAP_CONN_SEC_MODE_SET_LESC_ENC_WITH_MITM(&cccd_md.write_perm);
        
        and when i enable the notify it was a "0> APP_ERROR:ERROR:Fatal" occurs which is printed at app_error_fault_handler().

    could you give me some suggestions?

  • Hi,

    You can refer to the table in this PDF, where you see that if the initiator support display and yes/not button, and the responder supports display and keyboard there will be passkey entry if using legacy pairing and numeric comparison if using LESC.

    You need to do quite a bit more modifications to the example to support LESC. Particularly, the shared secret calculation need to be handled by the application, as shown in the experimental LESC multirole example. Note that the central device must also support LESC, if not legacy pairing will be used.

  • Hi Einar,

    thank you for your help.

    i have made some minor changes to the sample project you gived reference to experimental LESC multirole example. but there is an "0> APP_ERROR:ERROR:Fatal" occurs when i enabled the notify.

    could you give me some suggestions?

  • Hi,

    I am sorry for the late reply. (I have been away for some days).

    Have you got this working? If not, have you checked where the fatal error occurred? If you define DEBUG for the project and use the debugger you can inspect a struct in the error handler telling you the file name, line number and error code. This is normally very good when trying to fix such issues. If you are unable to resolve it, can you upload your current project so that I can test on my side?

Related