µracoli Manual Version foo

- µracoli
- User Guide
- Reference Guide

lw_mesh.h
1 /* Copyright (c) 2009 Axel Wachtler
2 All rights reserved.
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 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * 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 * Neither the name of the authors nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE. */
28
29 /* $Id: $ */
35 #ifndef LWMESH_H
36 #define LWMESH_H
37
42 /* === includes ============================================================ */
43 #include "const.h"
44 #include "board.h"
45 #include "transceiver.h"
46 #include "radio.h"
47 #include "timer.h"
48
49 /* === macros ============================================================== */
50
52 #define NWK_BUFFERS_AMOUNT (3)
53
54
56 #define NWK_MAX_ENDPOINTS_AMOUNT (0xF)
57
62 #define NWK_DUPLICATE_REJECTION_TABLE_SIZE (10)
63
68 #define NWK_DUPLICATE_REJECTION_TTL (50)
69
71 #define NWK_DUPLICATES_REJECTION_TIMER_INTERVAL (20)
72
75 #define NWK_ROUTE_TABLE_SIZE (10)
76
81 #define NWK_ACK_WAIT_TIME (50)
82
84 #ifndef NWK_SLEEPING_NODE
85 #define NWK_SLEEPING_NODE (0)
86 #endif
87
90 #ifndef NWK_ENABLE_ROUTING
91 #define NWK_ENABLE_ROUTING (1)
92 #endif
93
95 #define NWK_NFCTL_MASK (0x07)
96
99 #define NWK_ENDPOINT_ID_LW_COMMAND (0x0)
100
103 #define NWK_HEADER_SIZE (9 + 7 + 2)
104
107 #define NWK_MAX_PAYLOAD_SIZE (MAX_FRAME_SIZE - NWK_HEADER_SIZE)
108
109 #define NWK_NO_TASK_ID (255)
110
113 #define USE_RX_AACK (1)
114
115 /* === types =============================================================== */
116
118 typedef enum SHORTENUM
119 {
120 NWK_OPT_ACK_REQUEST = 0x01,
121 NWK_OPT_ENABLE_SECURITY = 0x02,
123 NWK_OPT_LINK_LOCAL = 0x04,
125 NWK_OPT_BROADCAST_PAN_ID = 0x08,
126 } NWK_Opt_t;
127
129 typedef enum SHORTENUM
130 {
133 NWK_IND_OPT_ACK_REQUEST = NWK_OPT_ACK_REQUEST,
134
136 NWK_IND_OPT_SECURED = NWK_OPT_ENABLE_SECURITY,
137
140 NWK_IND_OPT_LINK_LOCAL = NWK_OPT_LINK_LOCAL,
141
143 NWK_IND_OPT_BROADCAST_PAN_ID = NWK_OPT_BROADCAST_PAN_ID,
144
146 NWK_IND_OPT_BROADCAST = 0x10,
147
150 NWK_IND_OPT_LOCAL = 0x20,
151 } NWK_Ind_Opt_t;
152
154 typedef enum SHORTENUM
155 {
156 NWK_SUCCESS_STATUS,
159 NWK_ERROR_STATUS,
161 NWK_OUT_OF_MEMORY_STATUS,
164 NWK_NO_ACK_STATUS,
166 NWK_PHY_CHANNEL_ACCESS_FAILURE_STATUS,
168 NWK_PHY_NO_ACK_STATUS,
169 } NWK_Stat_t;
170
174 typedef struct NWK_DataReq_tag
175 {
176 uint16_t dstAddr;
177 uint8_t dstEndpoint;
178 uint8_t srcEndpoint;
179 NWK_Opt_t options;
180 uint8_t *data;
181 uint8_t size;
182 void (*confirm)(struct NWK_DataReq_tag *);
184 NWK_Stat_t status;
185 uint8_t control;
186 } NWK_DataReq_t;
187
188
192 typedef struct
193 {
194 uint16_t srcAddr;
195 uint8_t dstEndpoint;
196 uint8_t srcEndpoint;
197 NWK_Ind_Opt_t options;
199 uint8_t *data;
200 uint8_t size;
201 uint8_t lqi;
203 uint8_t rssi;
205 } NWK_DataInd_t;
206
207 /*TODO: how to make this "packed" on 16 bit architectures? */
211 typedef struct{
212 uint16_t m_fctl;
213 uint8_t m_seq;
214 uint16_t m_pid;
215 uint16_t m_dstAddr;
216 uint16_t m_srcAddr;
218 uint8_t lw_fctl;
219 uint8_t lw_seq;
220 uint16_t lw_srcAddr;
221 uint16_t lw_dstAddr;
222 uint8_t lw_endpts;
223 uint8_t lw_payload[NWK_MAX_PAYLOAD_SIZE];
225 uint16_t m_crc;
226 } NWK_FrameFormat_t;
227
228 typedef enum SHORTENUM
229 {
230 NWK_TASK_NO_TASK,
231 NWK_TASK_DATA_REQ,
232 NWK_TASK_DATA_IND,
233 NWK_TASK_TX_PENDING,
234 NWK_TASK_ACK_PENDING,
235 } NWK_Task_t;
236
241 typedef struct{
242 uint8_t task_id;
243 NWK_Task_t type;
244 timer_hdl_t timer_id;
245 NWK_FrameFormat_t *frame;
246 union{
247 NWK_DataReq_t req;
248 NWK_DataInd_t ind;
249 } info;
250 } NWK_Tasklist_t;
251
252 /* === prototypes ========================================================== */
253 #ifdef __cplusplus
254 extern "C" {
255 #endif
256
263 void lw_mesh_init(uint16_t pan_id, uint16_t short_addr, uint8_t channel);
264
268 void lw_mesh_task_handler();
269
277 void lw_mesh_data_req(NWK_DataReq_t *req);
278
279 void lw_mesh_open_endpoint(uint8_t endpoint_id,
280 bool (*data_ind_callback)(NWK_DataInd_t *));
281
282 void lw_mesh_set_ack_control(uint8_t control);
283
285 void lw_data_indication(NWK_FrameFormat_t *frame, uint8_t lw_payload_size,
286 uint8_t lqi, uint8_t rssi);
287
288 void lw_tx_done(uint8_t task_id, radio_tx_done_t tx_status);
289
290 /* called by lightweight command when a network acknowledgment is received*/
291 void lw_ack_received(uint8_t lw_seq, uint8_t lw_cmd_ctrl_message);
292
293 #ifdef __cplusplus
294 } /* extern "C" */
295 #endif
296
300 #endif /* #ifndef LWMESH_H */
NWK_DataReq_t::options
NWK_Opt_t options
Definition: lw_mesh.h:179
NWK_Tasklist_t::frame
NWK_FrameFormat_t * frame
Definition: lw_mesh.h:245
NWK_DataReq_t::size
uint8_t size
Definition: lw_mesh.h:181
NWK_FrameFormat_t::m_pid
uint16_t m_pid
Definition: lw_mesh.h:214
NWK_FrameFormat_t::lw_srcAddr
uint16_t lw_srcAddr
Definition: lw_mesh.h:220
NWK_DataInd_t::srcEndpoint
uint8_t srcEndpoint
Definition: lw_mesh.h:196
NWK_FrameFormat_t::m_seq
uint8_t m_seq
Definition: lw_mesh.h:213
NWK_FrameFormat_t::m_fctl
uint16_t m_fctl
Definition: lw_mesh.h:212
NWK_DataReq_t::dstEndpoint
uint8_t dstEndpoint
Definition: lw_mesh.h:177
NWK_DataInd_t::srcAddr
uint16_t srcAddr
Definition: lw_mesh.h:194
NWK_DataReq_t::dstAddr
uint16_t dstAddr
Definition: lw_mesh.h:176
NWK_FrameFormat_t
general lightweight mesh frame format
Definition: lw_mesh.h:211
NWK_DataInd_t::options
NWK_Ind_Opt_t options
Definition: lw_mesh.h:197
NWK_DataInd_t::size
uint8_t size
Definition: lw_mesh.h:200
NWK_DataInd_t::data
uint8_t * data
Definition: lw_mesh.h:199
radio_tx_done_t
radio_tx_done_t
Definition: radio.h:83
NWK_DataInd_t::dstEndpoint
uint8_t dstEndpoint
Definition: lw_mesh.h:195
NWK_FrameFormat_t::lw_seq
uint8_t lw_seq
Definition: lw_mesh.h:219
NWK_DataReq_t::control
uint8_t control
Definition: lw_mesh.h:185
NWK_Tasklist_t
structure for task list to propagate NWK_DataReq_t and NWK_DataInd_t to lw_mesh_task_handler ...
Definition: lw_mesh.h:241
NWK_FrameFormat_t::m_dstAddr
uint16_t m_dstAddr
Definition: lw_mesh.h:215
NWK_FrameFormat_t::lw_endpts
uint8_t lw_endpts
Definition: lw_mesh.h:222
NWK_FrameFormat_t::lw_dstAddr
uint16_t lw_dstAddr
Definition: lw_mesh.h:221
NWK_DataReq_t::srcEndpoint
uint8_t srcEndpoint
Definition: lw_mesh.h:178
timer_hdl_t
uint16_t timer_hdl_t
Definition: timer.h:86
NWK_FrameFormat_t::m_crc
uint16_t m_crc
Definition: lw_mesh.h:225
NWK_DataReq_t::data
uint8_t * data
Definition: lw_mesh.h:180
NWK_FrameFormat_t::lw_fctl
uint8_t lw_fctl
Definition: lw_mesh.h:218
NWK_DataInd_t::lqi
uint8_t lqi
Definition: lw_mesh.h:201
NWK_DataInd_t::rssi
uint8_t rssi
Definition: lw_mesh.h:203
NWK_DataReq_t::status
NWK_Stat_t status
Definition: lw_mesh.h:184
NWK_FrameFormat_t::m_srcAddr
uint16_t m_srcAddr
Definition: lw_mesh.h:216
NWK_DataReq_t
structure for sending frames
Definition: lw_mesh.h:174
NWK_DataInd_t
structure for receiving frames
Definition: lw_mesh.h:192