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