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

Private Bluetooth Address

Hello All,

i have a problem when I try to change the Bluetooth Address.

This is the code that works correctly:
err = bt_addr_le_from_str("DE:8B:49:00:00:01", "random", &addr);

This is the code that NOT works correctly:
err = bt_addr_le_from_str("43:8B:49:00:00:01", "random", &addr);

If I change "DE" of the Bluetooth Address with some other string like "43" I get the following error:
Only static random identity address supported
Creating new ID failed (err -22)

What could be? How can i fix this?

Second questions:
We buyed a range of Bluetooth Address but for Classic Bluetooth, can we use this range or we have to buy a specific address for BLE?

thanks to everything for the reply
Best regards

  • Hi,

    What could be? How can i fix this?

    The two most significant bits of a Bluetooth address specifies the type of address (unless it is public, that is). This follows the Bluetooth specification. You specify a "random" address, and by specification the two most significant bits then must be "11". So either the address is wrong, or you have specified the wrong type. If the address is public(?), then you should use "public" in the call to bt_addr_le_from_str().

    We buyed a range of Bluetooth Address but for Classic Bluetooth, can we use this range or we have to buy a specific address for BLE?

    Bluetooth device addresses are the same for LE and classic, so it should be fine to use your existing range. (As a side note, few end products benefit from a public address. Random static addresses are effectively 46 bit, and the likelihood of collisions between devices in Bluetooth range is negligible.)

  • Hello Einar,

    before of all thanks for your reply.

    I have already tried to put "public" and also "public-id" in the call bt_addr_le_from_str() but the result is the same.
    I still having the following error:
    Only static random identity address supported
    Creating new ID failed (err -22)

    Do you have other suggestions?

    For point number 2 i'ts ok.

    Thank you again for your time.
    Best regards

  • Hi,

    To set a public address you need to use bt_ctlr_set_public_addr(). Then you also need "#include <bluetooth/controller.h>".

    A generic set address wrapper function could look like this:

    static void set_bt_addr(const char *addr_str, const char *type_str)
    {
    	int err;
    	bt_addr_le_t addr;
    
    	err = bt_addr_le_from_str(addr_str, type_str, &addr);
    	if (err) {
    		printk("Invalid BT address (err %d)\n", err);
    	}
    
    	if (addr.type == BT_ADDR_LE_PUBLIC) {
    		bt_ctlr_set_public_addr(addr.a.val);
    		return;
    	} else {
    		err = bt_id_create(&addr, NULL);
    		if (err < 0) {
    			printk("Creating new ID failed (err %d)\n", err);
    		}
    	}
    }

    And be called like this: set_bt_addr("DE:AD:BE:AF:BA:11", "public");

Related