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
  • Hi,

    There are quite a few things you need to remember when adding the peer manager to a project. It is difficult to know exactly what you have done without seeing more of your code, but you can use this modified ble_app_uart example (sdk_12.3_ble_app_uart_with_bonding.zip), which adds bonding support using the peer manager as well as logging (using RTT backend).

  • 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,

    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?

Reply
  • 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?

Children
  • Hi Einar,    
        The numeric comparison function is near completion with your help.but still have a little trubble with peer device management.
        
    my log and questions is as follow:

    /*step 1*/
    Ble power-on
    reset value = 0x00000000, reson is : POR or BOR.
    //use the cellphone to connect the device
    evt id = 16 //connected
    evt id = 18
    evt id = 18
    evt id = 18

    /*step 2*/
    //open the notify at cellphone to trigger pairing
    evt id = 19 //BLE_GAP_EVT_SEC_PARAMS_REQUEST
    evt id = 24 //BLE_GAP_EVT_LESC_DHKEY_REQUEST
    evt id = 21 //BLE_GAP_EVT_PASSKEY_DISPLAY
    key : 342569
    //i set a auto confirm at device side by by call sd_ble_gap_auth_key_reply(p_ble_evt->evt.gap_evt.conn_handle, BLE_GAP_AUTH_KEY_TYPE_PASSKEY, NULL) when deal the evt BLE_GAP_EVT_PASSKEY_DISPLAY.
    evt id = 18

    //here need to confirm at the cellphone to continue the pairing.
    //Q1: how can i make the confirm only on device side?because there are troubles on cellphone side when message the user to confirm(In android there is no message sen).does there have any solutions to skip the confirm by cellphone when using numeric comparison?
    evt id = 26 //BLE_GAP_EVT_CONN_SEC_UPDATE

    evt id = 25 //BLE_GAP_EVT_AUTH_STATUS
    auth status = 0
    evt id = 80 //BLE_GATTS_EVT_WRITE
    //now the pairng has done and cellphone side open the notify success.
    evt id = 18

    /*step 3*/
    //cellphone disconnect and reconnect the device,open notify success.
    evt id = 17 //disconnected
    evt id = 16
    connected
    evt id = 20 // BLE_GAP_EVT_SEC_INFO_REQUEST
    evt id = 26 // BLE_GAP_EVT_CONN_SEC_UPDATE
    evt id = 18

    /*step 4*/
    //cellphone disconnect the link and delete the bond information,and then reconnect the device
    evt id = 17 //disconnected
    evt id = 16 //connected
    evt id = 18
    //open the notify
    evt id = 19    //BLE_GAP_EVT_SEC_PARAMS_REQUEST
    //here should be an operation to trigger the pairing again,but it has not.
    //Q2: how to trigger a pairing? it looks like i should store the pair info in the device and read it after device reset.and manager the pair info when link to the cellphone, but i don't know how to do that.

    evt id = 25    //BLE_GAP_EVT_AUTH_STATUS
    auth status = 133 // the error code is
    evt id = 18
    evt id = 17 //disconnected

  • Hi,

    A1. There is no way to confirm the value on only one side. If only one side can confirm, then the only option is just works unauthenticated pairing. However, this issue seems a bit odd. The Android Bluetooth stack should not have any problems with numeric comparison - it should be handled out of the box.

    A2. If I understand correct, at this point the Android side has deleted the bonding information, but the nRF still has the bonding information. To fix this you should either delete the bond information on the nRF as well (for instance by power cycling while holding a button like in the SDK examples), or you can modify it so that it allows repairing. If you want to do that, you should search for this line (in the handling of the PM_EVT_CONN_SEC_CONFIG_REQ event):

                pm_conn_sec_config_t conn_sec_config = {.allow_repairing = false};

    and modify it to:

                pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};

  • Hi Einar,

    It works!Thank you for your help and patience.

Related