Manually setting hardcoded IRK whitelist

Hi,
I want to my central device to search for peripherals by specific, hardcoced IRKs. I have setup whitelist that cooperates with bonding and peer manager. The thing is that untill flag m_whitelist_disabled is true the central device accepts every peripheral, and after NRF_BLE_SCAN_EVT_WHITELIST_REQUEST event happen then flag change to false and every peripheral device that was on time bonded is now whitelisted. But it is not how We want our device to work. We decided to hardcode IRKs whitelist that the central device can accept. I searched on forum and found that I can use sd_ble_gap_device_identities_set() and sd_ble_gap_whitelist_set() functions, but I receive hard fault every time after sd_ble_gap_device_identities_set() function. Could someone maybe explain or show me an example about manually setting whitelist. Below is my code and what I tried so far. This event NRF_BLE_SCAN_EVT_WHITELIST_REQUEST is triggered in scan_evt_handler.

  case NRF_BLE_SCAN_EVT_WHITELIST_REQUEST: {
    NRF_LOG_DEBUG("SCAN EVENT: NRF_BLE_SCAN_EVT_WHITELIST_REQUEST");
    //on_whitelist_req();
    ble_gap_id_key_t id_key = {0};
    ble_gap_irk_t irk = {0xA2,0xCE,0x21,0xF3,0x12,0x0E,0x6D,0x69,0xFB,0xC4,0x1A,0x43,0x12,0xD9,0xEF,0xB7};
    ble_gap_id_key_t const * key_ptr;

    key_ptr = &id_key;
 
    memcpy(&id_key.id_info.irk[0], &irk.irk[0], sizeof(ble_gap_irk_t));
    id_key.id_addr_info.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
    sd_ble_gap_device_identities_set(key_ptr, NULL, 1);
  }    

I am working on NRF52840 with SDK 16 S140

Parents
  • Hi,
    Try something like this:

    #define DM_PUBLIC_ADDR                      ((ble_gap_addr_t) {0,BLE_GAP_ADDR_TYPE_PUBLIC,{0xAB,0x02,0x03,0x04,0x05,0x06}})
    #define DM_PUBLIC_IRK                       ((ble_gap_irk_t) {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}})
    
    
    static ble_gap_irk_t m_irk;                                                 /**< IRK to signal DM support. */
    static ble_gap_addr_t m_id_addr;                                            /**< internal address to signal DM support. */
    static ble_gap_id_key_t* m_key_ptrs[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT];   /**< IRK store */
    
    
    static void on_whitelist_req(void)
    {
            ret_code_t ret;
            if (((nrf_ble_whitelist_cnt() == 0)) ||
                (m_whitelist_disabled))
            {
                    m_scan_param.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
                    ret = nrf_ble_scan_params_set(&m_scan, &m_scan_param);
                    APP_ERROR_CHECK(ret);
                    NRF_LOG_INFO("on_whitelist_req BLE_GAP_SCAN_FP_ACCEPT_ALL");
            }
            else
            {
                    ret = nrf_ble_whitelist_enable();
                    APP_ERROR_CHECK(ret);
                    
                    m_irk = DM_PUBLIC_IRK;
                    m_id_addr = DM_PUBLIC_ADDR;
    
                    ble_gap_id_key_t id_irk = {
                            .id_info = m_irk,
                            .id_addr_info = m_id_addr
                    };
                    m_key_ptrs[0] = &id_irk;
    
                    if(NRF_SUCCESS != sd_ble_gap_device_identities_set((const ble_gap_id_key_t**) &m_key_ptrs[0], NULL, 1))
                    {
                            APP_ERROR_CHECK(false);
                    }
                    NRF_LOG_INFO("on_whitelist_req IRK");
            }
    }


    Code is from this example: https://github.com/jimmywong2003/nrf52-sdk5-privacy-address-with-whitelist/blob/972a3047c1fbb0c5d1be1ba8dcaaabbcc6b768bf/ble_app_uart_c/main.c

  • Hi,
    Thank You for Your answer, and sorry for replying so late but I had to focus on different tasks.
    So I added the nrf_ble_whitelist library to the project and I prepared on_whitelist_req() following the example. Whenever it is called sd_ble_gap_device_identities_set returns NRF_SUCCESS but my peripheral device with matching IRK still cannot connect.
    I also made NRF_BLE_SCAN_EVT_WHITELIST_REQUEST same as in example and use privacy_init() function.

    Maybe You have any clue what is missing?
    I've seen that nrf_ble_whitelist_irk_add() function in nrf_ble_whitelist library have commented sd_ble_gap_device_identities_set function.

    ret_code_t nrf_ble_whitelist_irk_add(ble_gap_id_key_t *p_irk_key, uint8_t * irk_count)
    {
            ret_code_t err_code = NRF_SUCCESS;
    
            if (m_irk_cnt >= BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT)
                    return NRF_ERROR_INVALID_PARAM;
    
            if ((p_irk_key == NULL) || (*irk_count == 0))
            {
                    // Clear the device identities list.
                    return sd_ble_gap_device_identities_set(NULL, NULL, 0);
            }
    
    
            //err_code = sd_ble_gap_device_identities_set(key_ptrs, NULL, peer_cnt);
            //APP_ERROR_CHECK(err_code);
    
            m_irk_cnt++;
            *irk_count = m_irk_cnt;
    
    
            return NRF_SUCCESS;
    }

    So using this function basically just increment counter.

  • DPemployee said:
    Whenever it is called sd_ble_gap_device_identities_set returns NRF_SUCCESS but my peripheral device with matching IRK still cannot connect.

    What happens when it tried to connect? Any errors? Do you have any logs? What events do you get? 

Reply Children
No Data
Related