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

ble_uart_app with static passkey on SDK 11

I have been trying for a long time to implement ble_uart_app with static passkey on SDK 11 s130 on nRF51-dk.

There are a couple of threads on this feature.

devzone.nordicsemi.com/.../

devzone.nordicsemi.com/.../

devzone.nordicsemi.com/.../

devzone.nordicsemi.com/.../

I am confused what should be the right thing to do for SDK 11. Some answers recommend enabling MITM protection while some sample code devzone.nordicsemi.com/.../d893c21d4e9f1913474ede3920df0055 does not. Some use device manager, some use peer manager. Which is the best example app or thread I should visit to implement ble_uart_app with static passkey on SDK 11?

I am still not able to get static passkey working on ble_uart_app on SDK11. The Android app nRF UART 2.0 can connect to ble_uart_app without needing to key in any passkey.

Here are some relevant parts of my code;

static void device_manager_init(bool erase_bonds)
{
    uint32_t               err_code;
    dm_init_param_t        init_param = {.clear_persistent_data = erase_bonds};
    dm_application_param_t register_param;

    // Initialize persistent storage module.
    err_code = pstorage_init();
    APP_ERROR_CHECK(err_code);

    err_code = dm_init(&init_param);
    APP_ERROR_CHECK(err_code);

    memset(&register_param.sec_param, 0, sizeof(ble_gap_sec_params_t));

    register_param.sec_param.bond         = SEC_PARAM_BOND;
    register_param.sec_param.mitm         = SEC_PARAM_MITM;
    register_param.sec_param.io_caps      = SEC_PARAM_IO_CAPABILITIES;
    register_param.sec_param.oob          = SEC_PARAM_OOB;
    register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE;
    register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE;
    register_param.evt_handler            = device_manager_evt_handler;
    register_param.service_type           = DM_PROTOCOL_CNTXT_GATT_SRVR_ID;

    err_code = dm_register(&m_app_handle, &register_param);
    APP_ERROR_CHECK(err_code);
}

static void gap_params_init(void)
{
    uint32_t                err_code;
    ble_gap_conn_params_t   gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;

    //BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&sec_mode); 
    
    err_code = sd_ble_gap_device_name_set(&sec_mode,
                                          (const uint8_t *) DEVICE_NAME,
                                          strlen(DEVICE_NAME));
    APP_ERROR_CHECK(err_code);

    memset(&gap_conn_params, 0, sizeof(gap_conn_params));

    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency     = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;

    err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
    APP_ERROR_CHECK(err_code);

    ble_gap_opt_t gap_opt;
                                          
    gap_opt.passkey.p_passkey = (uint8_t *)"123456";  
 
    err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY,(const ble_opt_t *)&gap_opt); 
    APP_ERROR_CHECK(err_code);     
}

What else did I miss out? Thank you very much

  • Hi helpme,

    If you are using SDK v11, I would suggest to have a look at the ble_app_gls example. With that example you have an example of how to enable pairing with passkey (not static passkey). Both device manager and peer manager support passkey (and static passkey).

    You need to enable MITM both when you setup the security parameter and the properties of the characteristic.

    After you have pairing with passkey worked, you can start to use the sd_ble_opt_set() to set the passkey, it will be pretty straight forward.

    Note that the ble_app_uart doesn't device manager or peer manager and doesn't support pairing. I would suggest to start with the ble_app_gls and after you get it working, you port it to ble_app_uart.

Related