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

How do change the value of IRK

I use nrf51822 to do bluetooth keyboard, I hope the function is: I want to change the IRK value of the bluetooth keyboard each time it is paired and bound,Anybody know how to do that?My tests so far have found that the IRK value is fixed for each pair binding,I want to change IRK to a random number. How do I change it? thanks!

Parents Reply Children
  • Hi,

    OK, with older SoftDevices you have to use the options API to set the BLE_GAP_OPT_PRIVACY. There is no example of this in SDK 9, but you can refer to for instance the im_privacy_set() implementation for SDK 12.3 and copy what you need. It should only need small adaptations. Note that this just shows how you set the IRK, you still have to handle what I described earlier about generating and storing the IRK.

            ret_code_t     ret;
            ble_gap_addr_t privacy_addr;
            ble_gap_irk_t  current_irk;
            ble_opt_t      privacy_options;
            ble_opt_t      current_privacy_options;
    
            NRF_PM_DEBUG_CHECK(p_privacy_params != NULL);
    
            privacy_addr.addr_type                        = p_privacy_params->private_addr_type;
            privacy_options.gap_opt.privacy.p_irk         = p_privacy_params->p_device_irk;
            privacy_options.gap_opt.privacy.interval_s    = p_privacy_params->private_addr_cycle_s;
            current_privacy_options.gap_opt.privacy.p_irk = &current_irk;
    
            // Can not fail.
            (void) sd_ble_opt_get(BLE_GAP_OPT_PRIVACY, &current_privacy_options);
            (void) sd_ble_opt_set(BLE_GAP_OPT_PRIVACY, &privacy_options);

  • Hi,sir

    I use the method you provided to modify the value of IRK,but the modification was not successful,This bluetooth device is always reset. l modified before bluetooth enabled broadcast.The following image is the function I modified:

    I would like to ask, where can I modify irk? I am looking forward to your reply,thansk.

  • Hi,sir,

    I hope the function is:After the host and slave are successfully matched,in the pairing information exchange phase,l  want to change the slave's IRK. l  want to modify the IRK transmitted from the slave, as shown in the figure below.Is there any easy way?

  • Hi,

    Once you have set the IRK as discussed earlier, this is the IRK that will be used by the stack as your own IRK, and this is the one that will be transmitted to the peer during the key distribution when bonding. So you just need to set the IRK first, then all this is handled automatically (no need to change anything in how you do bonding etc.)

  • Hi,sir

    I use the method you provided to modify the value of IRK,but the modification was not successful,This bluetooth device is always reset. l modified before bluetooth enabled broadcast.I would like to ask, where can I modify irk? I am looking forward to your reply,thansk.

Related