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

how to make pairing mandatory

Module: ilumi H52 BLE module (nRF52832)
SDK: nRF5_SDK_15.2.0_9412b96
Softdevice: 132_nrf52_6.1.0_softdevice.hex
Compiler: gcc version 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] (15:7-2018-q2-4)

Hello,

I'm working with ble multiperipheral / app_UART (NUS) examples.

Since UART (NUS) example doesn't support pairing, I had to implement pairing manually.
Pairing works now. But central devices can still connect to the peripheral without pairing. Requirement is that only bonded devices are able to use the UART service. How can this be accomplished? How to force pairing / bonding for all connecting devices?

  • Thanks. That helped me. Now pairing works automatically.

    I enabled SEC_PARAM_LESC in main.c and changed the file components/ble/ble_services/ble_nus/ble_nus.c

        // Add the RX Characteristic.
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid                     = BLE_UUID_NUS_RX_CHARACTERISTIC;
        add_char_params.uuid_type                = p_nus->uuid_type;
        add_char_params.max_len                  = BLE_NUS_MAX_RX_CHAR_LEN;
        add_char_params.init_len                 = sizeof(uint8_t);
        add_char_params.is_var_len               = true;
        add_char_params.char_props.write         = 1;
        add_char_params.char_props.write_wo_resp = 1;
    
    //    add_char_params.read_access  = SEC_OPEN;
    //    add_char_params.write_access = SEC_OPEN;
        add_char_params.read_access  = SEC_JUST_WORKS;
        add_char_params.write_access = SEC_JUST_WORKS;
    
        err_code = characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->rx_handles);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    
        // Add the TX Characteristic.
        /**@snippet [Adding proprietary characteristic to the SoftDevice] */
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid              = BLE_UUID_NUS_TX_CHARACTERISTIC;
        add_char_params.uuid_type         = p_nus->uuid_type;
        add_char_params.max_len           = BLE_NUS_MAX_TX_CHAR_LEN;
        add_char_params.init_len          = sizeof(uint8_t);
        add_char_params.is_var_len        = true;
        add_char_params.char_props.notify = 1;
    
    //    add_char_params.read_access       = SEC_OPEN;
    //    add_char_params.write_access      = SEC_OPEN;
    //    add_char_params.cccd_write_access = SEC_OPEN;
        add_char_params.read_access       = SEC_JUST_WORKS;
        add_char_params.write_access      = SEC_JUST_WORKS;
        add_char_params.cccd_write_access = SEC_JUST_WORKS;
    
        return characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->tx_handles);

    Unfortunately I was not able to change permissions afterwards in main.c, so I had to change the ble_nus.c from nordic SDK.

Related