How to pair and bond with a static passkey?

I developed a project that using static passkey to pair and bond with nRF SDK17.

It be fulfilled by the follow way:

//write static passkey	
	m_static_pin_option.gap_opt.passkey.p_passkey = passkey;
	err_code =  sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option);
	APP_ERROR_CHECK(err_code);
//pair with MITM and check the passkey from phone
    #define  SEC_PARAM_BOND  1
    #define  SEC_PARAM_MITM  1
    #define  SEC_PARAM_LESC  0
    #define  SEC_PARAM_KEYPRESS  0
    #define  SEC_PARAM_IO_CAPABILITIES   BLE_GAP_IO_CAPS_DISPLAY_ONLY 
    #define  SEC_PARAM_OOB  0
    #define  SEC_PARAM_MIN_KEY_SIZE  7
    #define  SEC_PARAM_MAX_KEY_SIZE  16
    
    m_sec_param.bond           = SEC_PARAM_BOND;
    m_sec_param.mitm           = SEC_PARAM_MITM;
    m_sec_param.lesc           = SEC_PARAM_LESC;
    m_sec_param.keypress       = SEC_PARAM_KEYPRESS;
		m_sec_param.io_caps        = BLE_GAP_IO_CAPS_DISPLAY_ONLY;
    m_sec_param.oob            = SEC_PARAM_OOB;
    m_sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
    m_sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
    m_sec_param.kdist_own.enc  = 1;
    m_sec_param.kdist_own.id   = 1;
    m_sec_param.kdist_peer.enc = 1;
    m_sec_param.kdist_peer.id  = 1;
		
    err_code = pm_sec_params_set(&m_sec_param);
    APP_ERROR_CHECK(err_code);

However,when I turn to NCS,I don't know how to fulfill it.

I used the hid_mouse sample but it just push the button to confirm the bond.

How can I use the passkey to do the MITM protect?

  • When I using my phone to connect with my board , The pop-up is quick appeared.

    The waiting happen at the time that I entry passkey and confirm.

    The display of phone is pairing and the process will keep about five seconds.

    But it finished immediately when I use the application in nRF SDK.

    The board using to test is designed by myself that refer to official design.

  • Do you mean that it is slow:

    1: after you have entered the code and press "confirm"

    or

    2: It takes a long time before the popup with the passkey appears?

    In my test, using the ncs\nrf\samples\bluetooth\peripheral_cgms on an nRF52832 DK the time after pressing confirm was almost instantly. Can you please try this sample on both a DK and your custom hardware? You don't need to worry about setting the static passkey, as this shouldn't affect the time it takes roughly one second before I can see it in the log, but the logging has some delay. 

    Can you see if you see the same 5 second delay in that application on a) a DK and b) your HW?

    Best regards,

    Edvin

  • It is slow as case 1 that you say,just like that as follow:

    There no the same 5 second delay when I test cgms in my HW.

  • Ok, thank you for showing me. This could actually be unrelated to the security part. Do you know what connection interval that is being used? A sniffer trace using nRF Connect for Bluetooth LE would reveal this, and probably also reveal what takes so long. I suspect it is a long connection interval being used. I didn't see that you specify it anywhere, so it could be the phone that is selecting a long connection interval. It is possible for your peripheral to request a shorter connection interval, so that is something we could try. For a guide, you can follow the Nordic Developer Academy, and the Bluetooth Low Energy Fundamentals course. Particularly Lesson 3, exercise 2, steps 1-6 is relevant for this. It will also tell you the connection interval without using a sniffer, based on the connection callbacks from your application.

    Best regards,

    Edvin

Related