xref: /btstack/src/mesh/mesh_node.h (revision 94dc8eb321a7f7f0a210fd842516b5c13a7033ec)
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 #include <stdint.h>
42 
43 #include "btstack_linked_list.h"
44 
45 #if defined __cplusplus
46 extern "C" {
47 #endif
48 
49 typedef struct mesh_element {
50     // linked list item
51     btstack_linked_item_t item;
52 
53     // element index
54     uint16_t element_index;
55 
56     // LOC
57     uint16_t loc;
58 
59     // models
60     btstack_linked_list_t models;
61     uint16_t models_count_sig;
62     uint16_t models_count_vendor;
63 
64 } mesh_element_t;
65 
66 typedef struct {
67     btstack_linked_list_iterator_t it;
68 } mesh_element_iterator_t;
69 
70 
71 void mesh_node_init(void);
72 
73 /**
74  * @brief Set unicast address of primary element
75  * @param unicast_address
76  */
77 void mesh_node_primary_element_address_set(uint16_t unicast_address);
78 
79 /**
80  * @brief Set location of primary element
81  * @note Returned by Configuration Server Composite Data
82  * @param location
83  */
84 void mesh_node_set_primary_element_location(uint16_t location);
85 
86 /**
87  * @brief Set location of element
88  * @param element
89  * @param location
90  */
91 void mesh_node_set_element_location(mesh_element_t * element, uint16_t location);
92 
93 /**
94  * @brief Get unicast address of primary element
95  */
96 uint16_t mesh_node_get_primary_element_address(void);
97 
98 /**
99  * @brief Get Primary Element of this node
100  */
101 mesh_element_t * mesh_node_get_primary_element(void);
102 
103 /**
104  * @brief Add secondary element
105  * @param element
106  */
107 void mesh_node_add_element(mesh_element_t * element);
108 
109 /**
110  * @brief Get number elements
111  * @returns number of elements on this node
112  */
113 uint16_t mesh_node_element_count(void);
114 
115 /**
116  * @brief Get element for given unicast address
117  * @param unicast_address
118  */
119 mesh_element_t * mesh_node_element_for_unicast_address(uint16_t unicast_address);
120 
121 /**
122  * @brief Get element by index
123  * @param element_index
124  */
125 mesh_element_t * mesh_node_element_for_index(uint16_t element_index);
126 
127 
128 // Mesh Element Iterator
129 
130 void mesh_element_iterator_init(mesh_element_iterator_t * iterator);
131 
132 int mesh_element_iterator_has_next(mesh_element_iterator_t * iterator);
133 
134 mesh_element_t * mesh_element_iterator_next(mesh_element_iterator_t * iterator);
135 
136 /**
137  * @brief Set Device UUID
138  * @param device_uuid
139  */
140 void mesh_node_set_device_uuid(const uint8_t * device_uuid);
141 
142 /**
143  * @brief Get Device UUID
144  * @returns device_uuid if set, NULL otherwise
145  */
146 const uint8_t * mesh_node_get_device_uuid(void);
147 
148 #if defined __cplusplus
149 }
150 #endif
151 
152 #endif //__MESH_NODE_H
153