1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** Virtual address entry. */ 8 struct bt_mesh_va { 9 uint16_t ref:15, 10 changed:1; 11 uint16_t addr; 12 uint8_t uuid[16]; 13 }; 14 15 /** @brief Store Label UUID. 16 * 17 * @param uuid Label UUID to be stored. 18 * @param entry Pointer to a memory where a new or updated entry will be stored, or NULL. 19 * 20 * @return STATUS_SUCCESS if entry is stored or updated, error code otherwise. 21 */ 22 uint8_t bt_mesh_va_add(const uint8_t uuid[16], const struct bt_mesh_va **entry); 23 24 /** @brief Delete Label UUID. 25 * 26 * @c uuid must be a pointer to @ref bt_mesh_va.uuid. Use @ref bt_mesh_va_uuid_get to get valid 27 * pointer. 28 * 29 * @param uuid Label UUID to delete. 30 * 31 * @return STATUS_SUCCESS if entry is deleted, error code otherwise. 32 */ 33 uint8_t bt_mesh_va_del(const uint8_t *uuid); 34 35 /** @brief Find virtual address entry by Label UUID. 36 * 37 * @c uuid can be a user data. 38 * 39 * @param uuid pointer to memory with Label UUID to be found. 40 * 41 * @return Pointer to a valid entry, NULL otherwise. 42 */ 43 const struct bt_mesh_va *bt_mesh_va_find(const uint8_t *uuid); 44 45 /** @brief Check if there are more than one Label UUID which hash has the specificed virtual 46 * address. 47 * 48 * @param addr Virtual address to check 49 * 50 * @return True if there is collision, false otherwise. 51 */ 52 bool bt_mesh_va_collision_check(uint16_t addr); 53 54 /* Needed for storing va as indexes in persistent storage. */ 55 /** @brief Get Label UUID by index. 56 * 57 * @param idx Index of virtual address entry. 58 * 59 * @return Pointer to a valid Label UUID, or NULL if entry is not found. 60 */ 61 const uint8_t *bt_mesh_va_get_uuid_by_idx(uint16_t idx); 62 63 /** @brief Get virtual address entry index by Label UUID. 64 * 65 * @c uuid must be a pointer to @ref bt_mesh_va.uuid. Use @ref bt_mesh_va_uuid_get to get valid 66 * pointer. 67 * 68 * @param uuid Label UUID which index to find 69 * @param uuidx Pointer to a memory where to store index. 70 * 71 * @return 0 if entry is found, error code otherwise. 72 */ 73 int bt_mesh_va_get_idx_by_uuid(const uint8_t *uuid, uint16_t *uuidx); 74 75 /** @brief Store pending virtual address entries in the persistent storage.*/ 76 void bt_mesh_va_pending_store(void); 77 78 /** @brief Remove all stored virtual addresses and remove them from the persistent storage. */ 79 void bt_mesh_va_clear(void); 80