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

Adding peer manager to ble_app_uart

Hi,

I'm developing with 52840 DK, trying to add peer manager to another project I've modified from ble_app_uart (basically I've added saadc, SPI, USB and I2C module based on original example. Also this project was migrated from 52832 DK to 52840 DK and has been proven working).

As for peer manager example, I referred ble_app_bms from SDK16.

Here are the attempts I've done:

- Copying peer_manager_init(); and its evt_handler() from ble_app_bms. Copying and modifying erase_bonds and advertising_start().

- Adding source files from         ...\components\ble\peer_manager   to nRF_BLE group

- Adding        fds.c     fstorage.c        fstorage_sd.c   to nRF_Libraries group

- Including     fds.h   peer_manager.h   peer_manager_handler.h to main.c

- Enable fds, fstorage, peer_manager module in sdk_config

Now here is my situation,

I could compile the project without error and burned it into 52840DK.

Seems like I could erase existing bonds from flash.

I could connect without bonding(which is not what we want) and it works as usual, but when I manually bond it, connection failed and it shows "invalid pin or passkey, bonding failed" on nrf_connect.

And it LOG shows as follows when bonding failed.

I've been stuck by this problem for weeks. But it just works differently from sample projects.

Which part of it goes wrong.

Your help is appreciated, I could upload my project if necessary.

  • Hi,

    Please provide the debug log in text (using Insert -> Code). It would be interesting to see the full log, particularly the whole line starting with "Could not perform security procedure".

    Without knowing more I cannot say much, but this could for instance be because you have not included the required crypto libraries as in this thread.

  • Hi Einar!

    Thanks for your reply!

    I tried to add bonding to ble_app_uart based project again. This time it still won't work but act differently...

    When I runned ble_app_bms example,bonding window popped up automatically when ble was connected, and RTT log shows as follows:

    [11:29:24.387]收←◆<info> app_timer: RTC: initialized.
    <info> app: Bond Management example started.
    <info> app: Erase bonds!
    <debug> peer_manager_handler: Event PM_EVT_PEER_DELETE_SUCCEEDED
    <error> peer_manager_handler: Peer deleted successfully: peer_id: 0
    <debug> peer_manager_handler: Event PM_EVT_PEERS_DELETE_SUCCEEDED
    <info> peer_manager_handler: All peers deleted.
    <info> app: Fast adverstising.
    
    [11:29:29.266]收←◆<debug> peer_manager_handler: Connected, securing connection. conn_handle: 0
    <info> app: Connected
    
    [11:29:29.390]收←◆<debug> nrf_ble_gatt: Peer on connection 0x0 requested a data length of 251 bytes.
    <debug> nrf_ble_gatt: Updating data length to 27 on connection 0x0.
    
    [11:29:29.439]收←◆<debug> nrf_ble_gatt: Data length updated to 27 on connection 0x0.
    <debug> nrf_ble_gatt: max_rx_octets: 27
    <debug> nrf_ble_gatt: max_tx_octets: 27
    <debug> nrf_ble_gatt: max_rx_time: 2120
    <debug> nrf
    [11:29:29.509]收←◆_ble_gatt: max_tx_time: 2120
    
    [11:29:33.229]收←◆<debug> peer_manager_handler: Event PM_EVT_CONN_SEC_PARAMS_REQ
    <debug> peer_manager_handler: Security parameter request
    
    [11:29:34.475]收←◆<debug> peer_manager_handler: Event PM_EVT_CONN_SEC_START
    <debug> peer_manager_handler: Connection security procedure started: role: Peripheral, conn_handle: 0, procedure: Bonding
    <debug> peer_manager_handler: Event PM_EVT_CONN_SEC_PARAMS_REQ
    <debug> peer_manager_handler: Security parameter request
    
    [11:29:36.173]收←◆<debug> peer_manager_handler: Event PM_EVT_CONN_SEC_SUCCEEDED
    <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
    <debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
    <debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update
    
    [11:29:36.418]收←◆<debug> peer_manager_handler: Event PM_EVT_PEER_DATA_UPDATE_SUCCEEDED
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Central address resolution, action: Update

    But my project was not showing bonding window after connection, so I have to hit "bond" manually on nrf_connect app.

    Then there will be an fatal error and assert. Also it seems like system reset when I tried to erase bonding data.

    00> <info> app_timer: RTC: initialized.
    00> 
    00> <debug> nrf_ble_gatt: Requesting to update ATT MTU to 247 bytes on connection 0x0.
    00> 
    00> <debug> nrf_ble_gatt: Updating data length to 251 on connection 0x0.
    00> 
    00> <info> app: Connected
    00> 
    00> <debug> nrf_ble_gatt: ATT MTU updated to 247 bytes on connection 0x0 (response).
    00> 
    00> <info> app: Data len is set to 0xF4(244)
    00> 
    00> <debug> app: ATT MTU exchange completed. central 0xF7 peripheral 0xF7
    00> 
    00> <debug> nrf_ble_gatt: Data length updated to 251 on connection 0x0.
    00> 
    00> <debug> nrf_ble_gatt: max_rx_octets: 251
    00> 
    00> <debug> nrf_ble_gatt: max_tx_octets: 251
    00> 
    00> <debug> nrf_ble_gatt: max_rx_time: 2120
    00> 
    00> <debug> nrf_ble_gatt: max_tx_time: 2120
    00> 
    00> <debug> app: ATT MTU exchange completed. central 0xF7 peripheral 0xF7
    00> 
    00> <error> app: Fatal error

    I can't 100% sure which part is different from my last post(which cause the different log output) but I think I set the peer manager parameters as:

    #define SEC_PARAM_BOND                  1                                       //!< Perform bonding.
    #define SEC_PARAM_MITM                  0                                       //!< Man In The Middle protection not required.
    #define SEC_PARAM_LESC                  0                                       //!< LE Secure Connections not enabled.
    #define SEC_PARAM_KEYPRESS              0                                       //!< Keypress notifications not enabled.
    #define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_NONE                    //!< No I/O capabilities.
    #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

    Since this is how ble_app_bms works and all I need is the basic bonding function.

    Previously I tried to set LESC to 1 as another bonding example shows, then tons of source files(including crypto) and libraries need to be added. So I turned to ble_app_bms since it bit more simple.

    Thanks!

  • Hi Einar,

    Here are some updates.

    I modified ble_evt_handler based on https://devzone.nordicsemi.com/f/nordic-q-a/35433/configuring-peer-manager-for-bonding and it works.

    However bonding window does not pop up automatically, I have to press bond manually.

    Thanks

  • Hello Avadacadabara,

    Einar is currently out of office, so I will be handling this case from now on.

    Avadacadabara said:

    I am happy to hear that bonding works now!

    Avadacadabara said:
    However bonding window does not pop up automatically, I have to press bond manually.

    I am not sure that I understand what you mean when you say this - do you mean the bonding option in the nRF Connect application for smartphones? Is this option not showing up when you enter into the connection, or is the issue that you have to manually press the bond option that appears?
    In case of the latter, this is likely due to the security requirements of the service provided. If you take a look at the services_init function of the ble_app_hrs you could see where this may be configured. If the central tries to interact with a service that it does not have the required security for, the peripheral will send a security request.

    Best regards,
    Karl

  • Hi Karl,

    Thanks for reply.

    I was saying that peering option didn't show up after ble connected and I have to hit "bond" option to call it out.

    After several attempts, this issue fixed somehow...But I didn't change any part of the code.

    I think I'll just let it be. But your advice is appreciated!

    Thanks Karl and Einer.

Related