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

How to set static passkey for nrf51822 BLE central(s120 ) ?

As we known we can set static passkey in peripheral side (s110) with the API sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &ble_opt) as below:

inline void setPassKey(void) { uint8_t passkey[] = "123456"; ble_opt_t ble_opt; ble_opt.gap.passkey.p_passkey = &passkey[0]; (void) sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &ble_opt); }

But the same API can't be used to set passkey in nrf51822 BLE central(s120 ) side. So how to set static passkey in nrf51822 BLE central(s120 )?

Parents
  • FormerMember
    0 FormerMember

    Peripheral display:

    Static passkey for S120 can be impmlemented by following the message sequence chart for "GAP Central Bonding: Passkey Entry (Peripheral display) or OOB MSC" . The passkey could then be hard coded in the application.

    The passkey should be passed as a parameter when the function sd_ble_gap_auth_key_reply(..) is being called. It can for example be done the following way in main.c:

    #define STATIC_PASSKEY				"123456" 				            		/**< Static pin. */
    uint8_t                             passkey[] = STATIC_PASSKEY;
    
    static void on_ble_evt(ble_evt_t * p_ble_evt)
    {
        uint32_t                err_code;
        switch (p_ble_evt->header.evt_id)
        {
            ...
            ...
            case BLE_GAP_EVT_AUTH_KEY_REQUEST:
                err_code = sd_ble_gap_auth_key_reply(m_connection_handle,BLE_GAP_AUTH_KEY_TYPE_PASSKEY, passkey);
                APP_ERROR_CHECK(err_code);
                break;
            ...
            ...
            default:
                break;
        }
    }
    

    Central display:

    If you want to implement static passkey for S120 when the S120 device has the display,you should follow the message sequence chart "GAP Central Bonding: Passkey Entry, Central displays". In addition to what is in the message sequence chart, the static passkey has to be added. It can for example be done the following way: Set the option for static passkey in the softdevice, it can for example be done right after the initialization of the softdevice in main.c:

        #define STATIC_PASSKEY				"123456" 				         /**< Static pin. */
        uint8_t                             passkey[] = STATIC_PASSKEY;
        int main(void)
        {       
            uint32_t err_code;
            ble_opt_t static_pin_option;
            ...
            ble_stack_init();
            static_pin_option.gap_opt.passkey.p_passkey = passkey;
            err_code =  sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &static_pin_option);
            ...
        }
    

    On the peripheral side (S110), the message sequence chart "GAP Bonding: Passkey Entry (Central display) or OOB MSC" should be followed. The passkey can then be added the same way as for the central in the "peripheral display" case.

  • I want to set static passkey on Central side and then display it. So the message sequence chart should be "GAP Central Bonding: Passkey Entry, Central displays". But according to the sequence, I still don't know how to set a static passkey on Central side. Looks like we should set static passkey to softdevice. Could you please tell more details about how to implement it? Thanks!

Reply Children
No Data
Related