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

How to hard-coded irk address of a device in whitelist

I'm working nrf52832 , SDK V15.3.0 and S132. I have implemented whitelist in application and its working fine.  I need to add one phone as master device so  i need to hard coded the device irk key(16byte). But its not working . Previously i was using nrf51822,SDKV10,S110 and i was implemented same thing that was working fine. But SDKV15.3 is not working. 

im also adding the working code snippet of SDKV10,nrf51822 below .

           ble_gap_whitelist_t      whitelist;
            ble_gap_irk_t*              p_whitelist_irk[6];
            ble_gap_addr_t*          p_whitelist_addr[1];
            static ble_gap_irk_t     whitelist_asusZenfone = {{0xAB,0x7F,0x6B,0xED,0xF5,0xD8,0x30,0x1F,0x87,0x7D,0x2F,0xA9,0xFC,0xF1,0xA8,0xDB}};

            whitelist.addr_count = 1;
            whitelist.irk_count  = 2;
            whitelist.pp_addrs   = p_whitelist_addr;
            whitelist.pp_irks    = p_whitelist_irk;

            err_code = dm_whitelist_create(&m_app_handle, &whitelist);
            APP_ERROR_CHECK(err_code);

            if (whitelist.addr_count ==1)
            {
                SEGGER_RTT_printf(0,"Entering to addr mode\n");
                p_whitelist_irk[0]      = &whitelist_asusZenfone;
                whitelist.addr_count = 1;
                whitelist.irk_count =1;
                whitelist.pp_addrs = p_whitelist_addr;
                whitelist.pp_irks = p_whitelist_irk;
            }
            else if (whitelist.irk_count >=1)
            {
                SEGGER_RTT_printf(0,"Entering to irk mode\n");
                p_whitelist_irk[1]      = &whitelist_asusZenfone;
                whitelist.addr_count = 0;
                whitelist.irk_count = 2;
                whitelist.pp_addrs = p_whitelist_addr;
                whitelist.pp_irks = p_whitelist_irk;

            }

            err_code = ble_advertising_whitelist_reply(&whitelist);
            APP_ERROR_CHECK(err_code);

-----------------------------------------------------------------------------------------------------------------------

code snippet of SDKV15.3.0/S132/ nrf52832 but it not working

        case BLE_ADV_EVT_WHITELIST_REQUEST:
        	SEGGER_RTT_printf(0,"[Adv] BLE_ADV_EVT_WHITELIST_REQUEST\n");

            ble_gap_addr_t whitelist_addrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
            ble_gap_irk_t  whitelist_irks[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
            uint32_t       addr_cnt = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
            uint32_t       irk_cnt  = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;

	        static ble_gap_irk_t    whitelist_moto_irk = {{0x33,0x01,0xC2,0xDE,0x35,0x2C,0xED,0xD2,0x21,0x22,0x92,0x9A,0xD4,0x84,0xB9,0xCD}};
	        static ble_gap_addr_t	whitelist_moto_addr = {0,0,{0x89,0x38,0x60,0xC6,0x63,0xD4}};

            err_code = pm_whitelist_get(whitelist_addrs, &addr_cnt,
                                        whitelist_irks,  &irk_cnt);
            APP_ERROR_CHECK(err_code);

            SEGGER_RTT_printf(0,"pm_whitelist_get returns %d addr in whitelist and %d irk whitelist\n",
                          addr_cnt, irk_cnt);

            // Set the correct identities list (no excluding peers with no Central Address Resolution).
            identities_set(PM_PEER_ID_LIST_SKIP_NO_IRK);

            if(irk_cnt >= 1)
            {

				whitelist_irks[1]      = whitelist_moto_irk;
				whitelist_addrs[1]	= whitelist_moto_addr;
				addr_cnt =2;
				irk_cnt =2;
				
				
				SEGGER_RTT_printf(0,"ble_advertising with whitelist reply \n");
				// Apply the whitelist.
				err_code = ble_advertising_whitelist_reply(&m_advertising,
														   whitelist_addrs,
														   addr_cnt,
														   whitelist_irks,
														   irk_cnt);
				APP_ERROR_CHECK(err_code);
            }
            break;

Please help me to add device irk in whitelist for SDKV15.3 ?

Parents
  • Hi,

    You need to first add the IRK to the identity list using sd_ble_gap_device_identities_set(), then call sd_ble_gap_whitelist_set() to set the whitelist.

    However, if you use the peer manager (which it seem like you do) this also manipulates this list, so you may want to add this IRK via the peer manager API. Most SDK example that use whitelisting use this code to do that when handling BLE_ADV_EVT_WHITELIST_REQUEST:

    static void whitelist_load()
    {
        ret_code_t   ret;
        pm_peer_id_t peers[8];
        uint32_t     peer_cnt;
    
        memset(peers, PM_PEER_ID_INVALID, sizeof(peers));
        peer_cnt = (sizeof(peers) / sizeof(pm_peer_id_t));
    
        // Load all peers from the flash and whitelist them.
        peer_list_get(peers, &peer_cnt);
    
        ret = pm_whitelist_set(peers, peer_cnt);
        APP_ERROR_CHECK(ret);
    
        // Set up the list of device identities.
        // Some SoftDevices do not support this feature.
        ret = pm_device_identities_list_set(peers, peer_cnt);
        if (ret != NRF_ERROR_NOT_SUPPORTED)
        {
            APP_ERROR_CHECK(ret);
        }
    }
    
    
    static void on_whitelist_req(void)
    {
        ret_code_t     err_code;
    
        // Whitelist buffers.
        ble_gap_addr_t whitelist_addrs[8];
        ble_gap_irk_t  whitelist_irks[8];
    
        memset(whitelist_addrs, 0x00, sizeof(whitelist_addrs));
        memset(whitelist_irks,  0x00, sizeof(whitelist_irks));
    
        uint32_t addr_cnt = (sizeof(whitelist_addrs) / sizeof(ble_gap_addr_t));
        uint32_t irk_cnt  = (sizeof(whitelist_irks)  / sizeof(ble_gap_irk_t));
    
        // Reload the whitelist and whitelist all peers.
        whitelist_load();
    
        // Get the whitelist previously set using pm_whitelist_set().
        err_code = pm_whitelist_get(whitelist_addrs, &addr_cnt,
                                    whitelist_irks,  &irk_cnt);
        APP_ERROR_CHECK(err_code);
    
        if (((addr_cnt == 0) && (irk_cnt == 0)) ||
            (m_whitelist_disabled))
        {
            // Don't use whitelist
            err_code = nrf_ble_scan_params_set(&m_scan, NULL);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO("Starting scan.");
        }
        else
        {
            // Use whitelist.
            NRF_LOG_INFO("Starting scan with whitelist.");
        }
    
        bsp_board_led_on(CENTRAL_SCANNING_LED);
    }
    

    But the above code is based on having the bonding information. One option is to hardcode that you can refer to this example, ble_app_hrs_sidechannel_bonding.zip (it uses a slightly modified peer manager example for getting an existing bond and rewriting it again as a demo of how this can be done.

  • Hi,

    I have checked this example , this not using whitelist method. I have checked modified peer manager file also but i didn't get enough details.

    1. Can you please explains bit more detailed ? Or share other example with whitelist enabled ?

    This example code they using pm_peer_data_bonding_load for getting bonding info, then these bond info insert to peer manager. So if i'm hard-coded the master phone info ,  only the IRK details is enough to load in app_peer_bond_data struct function. Or i need to hard-code the whole details like Encryption Information,Master Identification, ble_gap_addr_t .

    In my case whitelist and bonding is working fine.

Reply
  • Hi,

    I have checked this example , this not using whitelist method. I have checked modified peer manager file also but i didn't get enough details.

    1. Can you please explains bit more detailed ? Or share other example with whitelist enabled ?

    This example code they using pm_peer_data_bonding_load for getting bonding info, then these bond info insert to peer manager. So if i'm hard-coded the master phone info ,  only the IRK details is enough to load in app_peer_bond_data struct function. Or i need to hard-code the whole details like Encryption Information,Master Identification, ble_gap_addr_t .

    In my case whitelist and bonding is working fine.

Children
  • Hi,

    NIDHIN K said:

    I have checked this example , this not using whitelist method. I have checked modified peer manager file also but i didn't get enough details.

    1. Can you please explains bit more detailed ? Or share other example with whitelist enabled ?

    Yes, that is correct. I had the example from earlier and intended it to show how you can preprogram bonding information. This can then be used for whitelisting in the exact same way as is done in other examples that use it. If you want the devices to be bonded in production, then this could be a sensible approach.

    NIDHIN K said:
    This example code they using pm_peer_data_bonding_load for getting bonding info, then these bond info insert to peer manager. So if i'm hard-coded the master phone info ,  only the IRK details is enough to load in app_peer_bond_data struct function. Or i need to hard-code the whole details like Encryption Information,Master Identification, ble_gap_addr_t .

    The idea here was to hard-code every bit of the bonding information. Alternatively, you can build the whitelist yourself instead of using the peer manger, as discussed earlier. But then you also need to make sure to handle this correctly if you intend to subsequently whitelist more bonded devices (I don't know if that is relevant for your use case).

    If you don't want to bond, and just want to whitelist a single IRK, then using the approach you have been using makes the most sense, but it seems like you are missing something based on the (incomplete) code snippet from your initial reply. As mentioned, you need to first add the IRK to the identity list using sd_ble_gap_device_identities_set(), then call sd_ble_gap_whitelist_set() to set the whitelist.

Related