Custom MAC address for each advertising sets

I'm playing a bit with the multiple_adv_sets sample code and I want to be able to control the MAC address for my  non connectable adv and for the connectable adv. I tried to set the flag BT_LE_ADV_OPT_USE_IDENTITY but it only made the nrf switch bettwen the same MAC address. Is there a way to set one custom MAC address for each?

  • Found how! 

    You need to set in your advertising parms an id and set the option BT_LE_ADV_OPT_USE_IDENTITY
    then you need to create two ids.

    You also need to add in your prj.conf this line

    CONFIG_BT_ID_MAX=2

    static bt_addr_le_t addr_broadcaster;
    static bt_addr_le_t addr_connectable;
    
    static const struct bt_le_adv_param non_connectable_adv_param = {
    	.id = 0,
    	.options = BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_USE_IDENTITY,
    	.interval_min = 0x140,
    	.interval_max = 0x190,
    	.peer = NULL,
    };
    static const struct bt_le_adv_param connectable_adv_param = {
    	.id = 1,
    	.options = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_USE_IDENTITY,
    	.interval_min = BT_GAP_ADV_FAST_INT_MIN_2,
    	.interval_max = BT_GAP_ADV_FAST_INT_MAX_2,
    	.peer = NULL,
    };
    
    void main(void)
    {
        // ...
        
        err = bt_addr_le_from_str("FF:FF:FF:FF:FF:FF", "random", &addr_broadcaster);
    	if (err) {
    		printk("Invalid BT address: %d\n", err);
    		return;
    	}
    	
    	err = bt_addr_le_from_str("FF:AA:AA:AA:AA:FF", "random", &addr_connectable);
    	if (err) {
    		printk("Invalid BT address: %d\n", err);
    		return;
    	}
    	
    	bt_id_create(&addr_broadcaster, NULL); // ID 0
    	bt_id_create(&addr_connectable, NULL); // ID 1
    	
    	// ...
    }

Related