1 /* 2 * Copyright (C) 2019 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #ifndef __MESH_NODE_H 39 #define __MESH_NODE_H 40 41 #if defined __cplusplus 42 extern "C" { 43 #endif 44 45 #include <stdint.h> 46 #include "btstack_linked_list.h" 47 48 typedef struct mesh_element { 49 // linked list item 50 btstack_linked_item_t item; 51 52 // element index 53 uint16_t element_index; 54 55 // LOC 56 uint16_t loc; 57 58 // models 59 btstack_linked_list_t models; 60 uint16_t models_count_sig; 61 uint16_t models_count_vendor; 62 63 } mesh_element_t; 64 65 typedef struct { 66 btstack_linked_list_iterator_t it; 67 } mesh_element_iterator_t; 68 69 70 void mesh_node_init(void); 71 72 /** 73 * @brief Set unicast address of primary element 74 * @param unicast_address 75 */ 76 void mesh_node_primary_element_address_set(uint16_t unicast_address); 77 78 /** 79 * @brief Set location of primary element 80 * @note Returned by Configuration Server Composite Data 81 * @param location 82 */ 83 void mesh_node_set_primary_element_location(uint16_t location); 84 85 /** 86 * @brief Set location of element 87 * @param element 88 * @param location 89 */ 90 void mesh_node_set_element_location(mesh_element_t * element, uint16_t location); 91 92 /** 93 * @brief Get unicast address of primary element 94 */ 95 uint16_t mesh_node_get_primary_element_address(void); 96 97 /** 98 * @brief Get Primary Element of this node 99 */ 100 mesh_element_t * mesh_node_get_primary_element(void); 101 102 /** 103 * @brief Add secondary element 104 * @param element 105 */ 106 void mesh_node_add_element(mesh_element_t * element); 107 108 /** 109 * @brief Get number elements 110 * @returns number of elements on this node 111 */ 112 uint16_t mesh_node_element_count(void); 113 114 /** 115 * @brief Get element for given unicast address 116 * @param unicast_address 117 */ 118 mesh_element_t * mesh_node_element_for_unicast_address(uint16_t unicast_address); 119 120 /** 121 * @brief Get element by index 122 * @param element_index 123 */ 124 mesh_element_t * mesh_node_element_for_index(uint16_t element_index); 125 126 127 // Mesh Element Iterator 128 129 void mesh_element_iterator_init(mesh_element_iterator_t * iterator); 130 131 int mesh_element_iterator_has_next(mesh_element_iterator_t * iterator); 132 133 mesh_element_t * mesh_element_iterator_next(mesh_element_iterator_t * iterator); 134 135 /** 136 * @brief Set Device UUID 137 * @param device_uuid 138 */ 139 void mesh_node_set_device_uuid(const uint8_t * device_uuid); 140 141 /** 142 * @brief Get Device UUID 143 * @returns device_uuid if set, NULL otherwise 144 */ 145 const uint8_t * mesh_node_get_device_uuid(void); 146 147 #if defined __cplusplus 148 } 149 #endif 150 151 #endif //__MESH_NODE_H 152