zephyr::raw

Function bt_id_create

source
pub unsafe extern "C" fn bt_id_create(
    addr: *mut bt_addr_le_t,
    irk: *mut u8,
) -> i32
Expand description

@brief Create a new identity.

Create a new identity using the given address and IRK. This function can be called before calling bt_enable(). However, the new identity will only be stored persistently in flash when this API is used after bt_enable(). The reason is that the persistent settings are loaded after bt_enable() and would therefore cause potential conflicts with the stack blindly overwriting what’s stored in flash. The identity will also not be written to flash in case a pre-defined address is provided, since in such a situation the app clearly has some place it got the address from and will be able to repeat the procedure on every power cycle, i.e. it would be redundant to also store the information in flash.

Generating random static address or random IRK is not supported when calling this function before bt_enable().

If the application wants to have the stack randomly generate identities and store them in flash for later recovery, the way to do it would be to first initialize the stack (using bt_enable), then call settings_load(), and after that check with bt_id_get() how many identities were recovered. If an insufficient amount of identities were recovered the app may then call bt_id_create() to create new ones.

If supported by the HCI driver (indicated by setting @kconfig{CONFIG_BT_HCI_SET_PUBLIC_ADDR}), the first call to this function can be used to set the controller’s public identity address. This call must happen before calling bt_enable(). Subsequent calls always add/generate random static addresses.

@param addr Address to use for the new identity. If NULL or initialized to BT_ADDR_LE_ANY the stack will generate a new random static address for the identity and copy it to the given parameter upon return from this function (in case the parameter was non-NULL). @param irk Identity Resolving Key (16 bytes) to be used with this identity. If set to all zeroes or NULL, the stack will generate a random IRK for the identity and copy it back to the parameter upon return from this function (in case the parameter was non-NULL). If privacy @kconfig{CONFIG_BT_PRIVACY} is not enabled this parameter must be NULL.

@return Identity identifier (>= 0) in case of success, or a negative error code on failure.