xref: /btstack/src/mesh/mesh_node.h (revision e8625ff1d444cb256f69fa3459ecedf340d2bb16)
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_access_set_primary_element_location(uint16_t location);
84 
85 /**
86  * @brief Get unicast address of primary element
87  */
88 uint16_t mesh_node_primary_element_address_get(void);
89 
90 /**
91  * @brief Get Primary Element of this node
92  */
93 mesh_element_t * mesh_primary_element(void);
94 
95 /**
96  * @brief Add secondary element
97  * @param element
98  */
99 void mesh_element_add(mesh_element_t * element);
100 
101 /**
102  * @brief Get element for given unicast address
103  * @param unicast_address
104  */
105 mesh_element_t * mesh_element_for_unicast_address(uint16_t unicast_address);
106 
107 /**
108  * @brief Get element by index
109  * @param element_index
110  */
111 mesh_element_t * mesh_element_for_index(uint16_t element_index);
112 
113 // Mesh Element Iterator
114 
115 void mesh_element_iterator_init(mesh_element_iterator_t * iterator);
116 
117 int mesh_element_iterator_has_next(mesh_element_iterator_t * iterator);
118 
119 mesh_element_t * mesh_element_iterator_next(mesh_element_iterator_t * iterator);
120 
121 
122 #if defined __cplusplus
123 }
124 #endif
125 
126 #endif //__MESH_NODE_H
127