This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Use of whitelist

How to implement unpaired binding whitelist? I have tried, but the device that only sets the MAC address whitelist cannot be connected, so I must set the peer IRK. Is there a way to obtain the peer IRK, or to set the whitelist to only use the MAC address authentication? Thank you very much!

  • Hi,Thank you for your reply.

    Whitelist is implemented on peripherals, The following is the implementation code for the peripheral.

    I manually added the device address to the whitelist,I tried byte order inversion,The result is always the same.

    The manually added  MAC address is obtained when the whitelist is not added.

    static ble_gap_addr_t whitelist[BLE_GAP_WHITELIST_ADDR_MAX_COUNT] = {0, BLE_GAP_ADDR_TYPE_PUBLIC,0xFC, 0xF4, 0x53, 0x87, 0x0B, 0xC1};
    //static ble_gap_addr_t whitelist[BLE_GAP_WHITELIST_ADDR_MAX_COUNT] = {0, BLE_GAP_ADDR_TYPE_PUBLIC,0xC1, 0x0B, 0x87, 0x53, 0xF4, 0xFC};
    
    /**@brief Function for initializing the Advertising functionality.
     */
    void advertising_init(uint16_t  uudis,uint8_t *CtrolType,ble_adv_Evt_handler_t  bleAdvEvtCallback)
    {
        uint32_t               err_code;
        ble_advertising_init_t init;
        iBleAdvEvtCallbackHandler = bleAdvEvtCallback;
        ble_uuid_t adv_uuids[] =
        {
            {uudis, BLE_UUID_TYPE_BLE}
        };
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.include_appearance = false;
        init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
        init.advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
        init.advdata.uuids_complete.p_uuids  = adv_uuids;
    
        init.srdata.name_type = BLE_ADVDATA_FULL_NAME;
        init.srdata.include_appearance = true;
        
        
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
        init.evt_handler = on_adv_evt;
        
        init.config.ble_adv_whitelist_enabled = true;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }
    /**@brief Function for starting advertising. */
    void advertising_start(void )
    {
        ret_code_t err_code;
    		ble_gap_addr_t const * addr_ptrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT] = {0};
    		
    		for (uint32_t i = 0; i < BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; i++)
    		{
    				addr_ptrs[i] = &whitelist[i];
    		}
    		
        err_code = sd_ble_gap_whitelist_set(addr_ptrs, 1);
        APP_ERROR_CHECK(err_code);
        
    
        err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for handling advertising events.
     *
     * @details This function will be called for advertising events which are passed to the application.
     *
     * @param[in] ble_adv_evt  Advertising event.
     */
    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    {
        ret_code_t     err_code;
    	uint32_t       addr_cnt = 1;
    	uint32_t       irk_cnt  = 0;
    	ble_gap_id_key_t         keys[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT] = {0};
    	ble_gap_id_key_t const * key_ptrs[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT] = {0};	
        switch (ble_adv_evt)
        {
            case BLE_ADV_EVT_WHITELIST_REQUEST:
    			for (uint32_t i = 0; i < BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; i++)
    			{
    				key_ptrs[i] = &keys[i];
    				memcpy(&keys[i].id_addr_info, &whitelist[i], sizeof(ble_gap_addr_t));
    			}
    			
    			err_code = sd_ble_gap_device_identities_set(key_ptrs, NULL, addr_cnt);
    			APP_ERROR_CHECK(err_code);
    			// Apply the whitelist.
    			err_code = ble_advertising_whitelist_reply(&m_advertising,
        													 whitelist,
        													 addr_cnt,
        													 NULL,
        													 irk_cnt);
    			APP_ERROR_CHECK(err_code);
                break;
            case BLE_ADV_EVT_FAST:
                NRF_LOG_INFO("Fast advertising.");
                break;
            case BLE_ADV_EVT_IDLE:
                
                break;
            default:
                break;
        }
    }

Related