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

Merging LE Secure Connections Multirole Example and Ble App UART Example

Hi,

I am working on a project where I need to send and receive ASCII strings from my Central Device to the Peripheral Device. Before the communication starts there should be a bonding (paring) between the devices. The nRF52840 DK is used as a peripheral device and nRF Toolbox is used as a central device.  After the bond is established the text should be encrypted using the AES algorithm. Finally, the text sent should be displayed using UART.

the bonding and paring are done in example LE Secure Connections Multirole and the UART is done in the example Ble App UART so I wanted to merge both the files. Can anyone help me with this?

The tools and software used are listed here:

NRF52840 DK

SDK 15.2.0

Segger embedded studio for coding

nRF Toolbox version 2.0

Parents
  • You don't need to merge the two examples completely, I would instead recommend you to add the security related functionality to the BLE App UART example. In addition I don't think the nRF Toolbox supports bonding with the BLE UART example. You should use nRF Connect (for phone) instead.

    I would recommend you to take a look at the Peer Manager, which is a library that can be used to manage BLE Security. If you take a look at the different Message Sequence Charts for LESC Pairing, you can see that pairing consist of a set of events and replies. The Peer Manager will handle most of this for you.  

    In order to initialize the Peer Manager you have to execute the three steps explained in this link. Then, depending on the pairing method, you have to set the Security Parameters accordingly. 

    Choose pairing method and set security parameters

    The LE Secure Connections Multirole examples uses the pairing method Numeric Comparison, but you have other choices, such as Numeric comparison, Out of Band, Passkey Entry and Just works. Check out this link on how to set the security parameters for the different pairing methods.

    Initialize the Peer manager

    In order to initialize the Peer Manager you have to run the three steps, as explained here:

    Include functionality depending on pairing method

    Depending on the pairing method, different functionality must be implemented. E.g. if you want to use Numeric Comparison, you need a way of displaying the comparison numbers when receiving BLE_GAP_EVT_PASSKEY_DISPLAY, and also functionality to press a button and respond with sd_ble_gap_auth_key_reply(). This will make more sense of you look at the Message sequence chart for Numeric Comparison. The function nrf_ble_lesc_request_handler() should run regularly in the main loop (Take a look at the The LESC Multirole example on where to put it).

    If you want me to go through any of the other pairing methods, please ask. 

    Remove BLE event replies from the BLE App UART examples

    The ble app uart example includes a ble_evt_handler(), which will receive and reply to BLE events, including some that will interfere with the Peer Manager and the pairing process. You should comment out the replies to these events: BLE_GAP_EVT_SEC_PARAMS_REQUEST and BLE_GATTS_EVT_SYS_ATTR_MISSING.

    I may have forgotten something, but this should be a good start. Please ask if anything is unclear.

    Best regards,

    Simon

  • Thank You for explaining the initial steps.

    I have included the peer manager function in my UART example with numeric comparison security features.
    When I try to connect my nRF board with the new UART example( including security features) it shows connected initially but while bonding and pairing it throws an error stating:

    ERROR: (0x16): GATT CONN TERMINATED LOCAL HOST.

    The screenshort of the nRF Toolbox app UART logs is attached below:



    As you told me previously that nRF toolbox doesn't support BONDING and PAIRING so I tried to connect using the nRF Connect App but still I am getting the same Error.

    Am I missing anything If so please help me!

  • Thank You. I will try to run the file and let you know.

  • So, nRF Toolbox also supports bonding and pairing?

  • Yes it seems like it, I was wrong.

    Did my project work?

  • Yes, nRF Toolbox supports bonding. I verified now.
    Actually, there was a problem with the central device which was getting disconnected.
    So I changed the central device and now the communication is established with bonding.
    I tried your code also and it's working.

    Thank you for your help.  

  • I am glad it works and always happy to help

    Best regards,

    Simon

Reply Children
Related