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

How to add bonding information manually?

Hi,

I want to add bonding information manually. 

1.can I assume IRK key will be constant for multiple peripherals?

2.if IRK only key is available, can i add it to peer list using pm_peer_new? 

 

Parents
  • I'm afraid we're still misunderstanding each other. You're saying that you are referring to the peripheral but not advertising, which is what a BLE peripheral does. If not, what do you intend that the peripheral is going to do, just have a whitelist with the central's IRK, and bond without advertising at all? If so, that is not possible, as there needs to be an advertising process before bonding at all.

    To add the IRK address of a device in any whitelist, you need to add the IRK to the identity list using sd_ble_gap_device_identities_set(), then call sd_ble_gap_whitelist_set() to set that whitelist. After you've done so, you can do something like this to use said IRK.

            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;

    If you would describe the use case, it would be easier to tell you whether what you're trying to do is possible or not. If you plan to advertise to only one device, I'm afraid you will need the peer_ID as well, as that would be directed advertising, which I've already mentioned, and the sd_ble_gap_device_identities_set() function needs both peer address and IRK to be used.

    Best regards,

    Simon

Reply
  • I'm afraid we're still misunderstanding each other. You're saying that you are referring to the peripheral but not advertising, which is what a BLE peripheral does. If not, what do you intend that the peripheral is going to do, just have a whitelist with the central's IRK, and bond without advertising at all? If so, that is not possible, as there needs to be an advertising process before bonding at all.

    To add the IRK address of a device in any whitelist, you need to add the IRK to the identity list using sd_ble_gap_device_identities_set(), then call sd_ble_gap_whitelist_set() to set that whitelist. After you've done so, you can do something like this to use said IRK.

            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;

    If you would describe the use case, it would be easier to tell you whether what you're trying to do is possible or not. If you plan to advertise to only one device, I'm afraid you will need the peer_ID as well, as that would be directed advertising, which I've already mentioned, and the sd_ble_gap_device_identities_set() function needs both peer address and IRK to be used.

    Best regards,

    Simon

Children
No Data
Related