OpenWSN Firmware
openwsn.h
Go to the documentation of this file.
1 
8 #ifndef __OPENWSN_H
9 #define __OPENWSN_H
10 
11 //general
12 #include <stdint.h> // needed for uin8_t, uint16_t
13 #include "toolchain_defs.h"
14 #include "board_info.h"
15 
16 //=========================== define ==========================================
17 
18 static const uint8_t infoStackName[] = "OpenWSN ";
19 #define OPENWSN_VERSION_MAJOR 1
20 #define OPENWSN_VERSION_MINOR 4
21 #define OPENWSN_VERSION_PATCH 1
22 
23 //to delimit the implementation of draft-thubert-6man-flow-label-for-rpl-03
24 #define FLOW_LABEL_RPL_DOMAIN 1
25 
26 #ifndef TRUE
27 #define TRUE 1
28 #endif
29 
30 #ifndef FALSE
31 #define FALSE 0
32 #endif
33 
34 #define LENGTH_ADDR16b 2
35 #define LENGTH_ADDR64b 8
36 #define LENGTH_ADDR128b 16
37 
38 
39 enum {
40  E_SUCCESS = 0,
41  E_FAIL = 1,
42 };
43 
44 // types of addresses
45 enum {
46  ADDR_NONE = 0,
47  ADDR_16B = 1,
48  ADDR_64B = 2,
49  ADDR_128B = 3,
53 };
54 
55 enum {
58 };
59 
60 // protocol numbers, as defined by the IANA
61 enum {
63  IANA_TCP = 0x06,
64  IANA_UDP = 0x11,
65  IANA_IPv6ROUTE = 0x2b,//used for source routing
66  IANA_ICMPv6 = 0x3a,
75  IANA_RSVP = 46,
76  IANA_UNDEFINED = 250, //use an unassigned
77 };
78 
79 // well known ports (which we define)
80 // warning: first 4 MSB of 2° octect may coincide with previous protocol number
81 enum {
82  //TCP
87  //UDP
88  WKP_UDP_COAP = 5683,
89  WKP_UDP_HELI = 2192,
90  WKP_UDP_IMU = 2190,
94  WKP_UDP_RAND = 61000,
95  WKP_UDP_LATENCY = 61001,
96 };
97 
98 //status elements
99 enum {
112 };
113 
114 //component identifiers
115 //the order is important because
116 enum {
119  //cross-layers
125  //PHY
127  //MAClow
130 
131  //All components with higher component id than COMPONENT_IEEE802154E
132  //won't be able to get free packets from the queue
133  //when the mote is not synch
134 
135  //MAClow<->MAChigh ("virtual components")
138  //MAChigh
143  //IPHC
146  //IPv6
152  //TRAN
156  //App test
164  //App
171  COMPONENT_RT = 0x27,
185 };
186 
194 enum {
195  // l7
196  ERR_RCVD_ECHO_REQUEST = 0x01, // received an echo request
197  ERR_RCVD_ECHO_REPLY = 0x02, // received an echo reply
198  ERR_GETDATA_ASKS_TOO_FEW_BYTES = 0x03, // getData asks for too few bytes, maxNumBytes={0}, fill level={1}
199  ERR_INPUT_BUFFER_OVERFLOW = 0x04, // the input buffer has overflown
200  ERR_COMMAND_NOT_ALLOWED = 0x05, // the command is not allowerd, command = {0}
201  // l4
202  ERR_WRONG_TRAN_PROTOCOL = 0x06, // unknown transport protocol {0} (code location {1})
203  ERR_WRONG_TCP_STATE = 0x07, // wrong TCP state {0} (code location {1})
204  ERR_TCP_RESET = 0x08, // TCP reset while in state {0} (code location {1})
205  ERR_UNSUPPORTED_PORT_NUMBER = 0x09, // unsupported port number {0} (code location {1})
206  // l3
207  ERR_UNEXPECTED_DAO = 0x0a, // unexpected DAO (code location {0})
208  ERR_UNSUPPORTED_ICMPV6_TYPE = 0x0b, // unsupported ICMPv6 type {0} (code location {1})
209  ERR_6LOWPAN_UNSUPPORTED = 0x0c, // unsupported 6LoWPAN parameter {1} at location {0}
210  ERR_NO_NEXTHOP = 0x0d, // no next hop
211  ERR_INVALID_PARAM = 0x0e, // invalid parameter
212  ERR_INVALID_FWDMODE = 0x0f, // invalid forward mode
213  ERR_LARGE_DAGRANK = 0x10, // large DAGrank {0}, set to {1}
214  ERR_HOP_LIMIT_REACHED = 0x11, // packet discarded hop limit reached
215  ERR_LOOP_DETECTED = 0x12, // loop detected due to previous rank {0} lower than current node rank {1}
216  ERR_WRONG_DIRECTION = 0x13, // upstream packet set to be downstream, possible loop.
217  // l2b
218  ERR_NEIGHBORS_FULL = 0x14, // neighbors table is full (max number of neighbor is {0})
219  ERR_NO_SENT_PACKET = 0x15, // there is no sent packet in queue
220  ERR_NO_RECEIVED_PACKET = 0x16, // there is no received packet in queue
221  ERR_SCHEDULE_OVERFLOWN = 0x17, // schedule overflown
222  // l2a
223  ERR_WRONG_CELLTYPE = 0x18, // wrong celltype {0} at slotOffset {1}
224  ERR_IEEE154_UNSUPPORTED = 0x19, // unsupported IEEE802.15.4 parameter {1} at location {0}
225  ERR_DESYNCHRONIZED = 0x1a, // got desynchronized at slotOffset {0}
226  ERR_SYNCHRONIZED = 0x1b, // synchronized at slotOffset {0}
227  ERR_LARGE_TIMECORRECTION = 0x1c, // large timeCorr.: {0} ticks (code loc. {1})
228  ERR_WRONG_STATE_IN_ENDFRAME_SYNC = 0x1d, // wrong state {0} in end of frame+sync
229  ERR_WRONG_STATE_IN_STARTSLOT = 0x1e, // wrong state {0} in startSlot, at slotOffset {1}
230  ERR_WRONG_STATE_IN_TIMERFIRES = 0x1f, // wrong state {0} in timer fires, at slotOffset {1}
231  ERR_WRONG_STATE_IN_NEWSLOT = 0x20, // wrong state {0} in start of frame, at slotOffset {1}
232  ERR_WRONG_STATE_IN_ENDOFFRAME = 0x21, // wrong state {0} in end of frame, at slotOffset {1}
233  ERR_MAXTXDATAPREPARE_OVERFLOW = 0x22, // maxTxDataPrepare overflows while at state {0} in slotOffset {1}
234  ERR_MAXRXACKPREPARE_OVERFLOWS = 0x23, // maxRxAckPrepapare overflows while at state {0} in slotOffset {1}
235  ERR_MAXRXDATAPREPARE_OVERFLOWS = 0x24, // maxRxDataPrepapre overflows while at state {0} in slotOffset {1}
236  ERR_MAXTXACKPREPARE_OVERFLOWS = 0x25, // maxTxAckPrepapre overflows while at state {0} in slotOffset {1}
237  ERR_WDDATADURATION_OVERFLOWS = 0x26, // wdDataDuration overflows while at state {0} in slotOffset {1}
238  ERR_WDRADIO_OVERFLOWS = 0x27, // wdRadio overflows while at state {0} in slotOffset {1}
239  ERR_WDRADIOTX_OVERFLOWS = 0x28, // wdRadioTx overflows while at state {0} in slotOffset {1}
240  ERR_WDACKDURATION_OVERFLOWS = 0x29, // wdAckDuration overflows while at state {0} in slotOffset {1}
241  // general
242  ERR_BUSY_SENDING = 0x2a, // busy sending
243  ERR_UNEXPECTED_SENDDONE = 0x2b, // sendDone for packet I didn't send
244  ERR_NO_FREE_PACKET_BUFFER = 0x2c, // no free packet buffer (code location {0})
245  ERR_FREEING_UNUSED = 0x2d, // freeing unused memory
246  ERR_FREEING_ERROR = 0x2e, // freeing memory unsupported memory
247  ERR_UNSUPPORTED_COMMAND = 0x2f, // unsupported command {0}
248  ERR_MSG_UNKNOWN_TYPE = 0x30, // unknown message type {0}
249  ERR_WRONG_ADDR_TYPE = 0x31, // wrong address type {0} (code location {1})
250  ERR_BRIDGE_MISMATCH = 0x32, // isBridge mismatch (code location {0})
251  ERR_HEADER_TOO_LONG = 0x33, // header too long, length {1} (code location {0})
252  ERR_INPUTBUFFER_LENGTH = 0x34, // input length problem, length={0}
253  ERR_BOOTED = 0x35, // booted
254  ERR_INVALIDSERIALFRAME = 0x36, // invalid serial frame
255  ERR_INVALIDPACKETFROMRADIO = 0x37, // invalid packet frome radio, length {1} (code location {0})
256  ERR_BUSY_RECEIVING = 0x38, // busy receiving when stop of serial activity, buffer input length {1} (code location {0})
257  ERR_WRONG_CRC_INPUT = 0x39, // wrong CRC in input Buffer (input length {0})
258 };
259 
260 //=========================== typedef =========================================
261 
262 
263 typedef uint16_t errorparameter_t;
264 typedef uint16_t dagrank_t;
265 typedef uint8_t owerror_t;
266 
267 BEGIN_PACK
268 typedef struct {
269  uint8_t byte4;
270  uint16_t bytes2and3;
271  uint16_t bytes0and1;
272 } asn_t;
273 END_PACK
274 
275 BEGIN_PACK
276 typedef struct { // always written big endian, i.e. MSB in addr[0]
277  uint8_t type;
278  union {
279  uint8_t addr_16b[2];
280  uint8_t addr_64b[8];
281  uint8_t addr_128b[16];
282  uint8_t panid[2];
283  uint8_t prefix[8];
284  };
285 } open_addr_t;
286 END_PACK
287 
288 typedef struct {
289  //admin
290  uint8_t creator; // the component which called getFreePacketBuffer()
291  uint8_t owner; // the component which currently owns the entry
292  uint8_t* payload; // pointer to the start of the payload within 'packet'
293  uint8_t length; // length in bytes of the payload
294  //l4
295  uint8_t l4_protocol; // l4 protocol to be used
296  bool l4_protocol_compressed; // is the l4 protocol header compressed?
297  uint16_t l4_sourcePortORicmpv6Type; // l4 source port
298  uint16_t l4_destination_port; // l4 destination port
299  uint8_t* l4_payload; // pointer to the start of the payload of l4 (used for retransmits)
300  uint8_t l4_length; // length of the payload of l4 (used for retransmits)
301  //l3
302  open_addr_t l3_destinationAdd; // 128b IPv6 destination (down stack)
303  open_addr_t l3_sourceAdd; // 128b IPv6 source address
304  //l2
305  owerror_t l2_sendDoneError; // outcome of trying to send this packet
306  open_addr_t l2_nextORpreviousHop; // 64b IEEE802.15.4 next (down stack) or previous (up) hop address
307  uint8_t l2_frameType; // beacon, data, ack, cmd
308  uint8_t l2_dsn; // sequence number of the received frame
309  uint8_t l2_retriesLeft; // number Tx retries left before packet dropped (dropped when hits 0)
310  uint8_t l2_numTxAttempts; // number Tx attempts
311  asn_t l2_asn; // at what ASN the packet was Tx'ed or Rx'ed
312  uint8_t* l2_payload; // pointer to the start of the payload of l2 (used for MAC to fill in ASN in ADV)
313  uint8_t* l2_scheduleIE_cellObjects; // pointer to the start of cell Objects in scheduleIE
314  uint8_t l2_scheduleIE_numOfCells; // number of cells were going to be scheduled or removed.
315  uint8_t l2_scheduleIE_frameID; // frameID in scheduleIE
316  uint8_t* l2_ASNpayload; // pointer to the ASN in EB
317  uint8_t l2_joinPriority; // the join priority received in EB
318  bool l2_IEListPresent; //did have IE field?
320  //l1 (drivers)
321  uint8_t l1_txPower; // power for packet to Tx at
322  int8_t l1_rssi; // RSSI of received packet
323  uint8_t l1_lqi; // LQI of received packet
324  bool l1_crc; // did received packet pass CRC check?
325  //the packet
326  uint8_t packet[1+1+125+2+1]; // 1B spi address, 1B length, 125B data, 2B CRC, 1B LQI
328 
329 //=========================== variables =======================================
330 
331 //=========================== prototypes ======================================
332 
333 void openwsn_init(void);
334 
335 #endif
Definition: openwsn.h:236
open_addr_t l3_destinationAdd
Definition: openwsn.h:302
Definition: openwsn.h:248
Definition: openwsn.h:63
Definition: openwsn.h:199
Definition: openwsn.h:94
Definition: openwsn.h:227
Definition: openwsn.h:251
uint8_t l2_scheduleIE_frameID
Definition: openwsn.h:315
Definition: openwsn.h:65
Definition: openwsn.h:75
Definition: openwsn.h:178
Definition: openwsn.h:47
Definition: openwsn.h:220
Definition: openwsn.h:154
uint8_t * l4_payload
Definition: openwsn.h:299
open_addr_t l3_sourceAdd
Definition: openwsn.h:303
Definition: openwsn.h:126
Definition: openwsn.h:167
Definition: openwsn.h:242
Definition: openwsn.h:216
Definition: openwsn.h:170
Definition: openwsn.h:252
Definition: openwsn.h:174
Definition: openwsn.h:85
uint8_t l1_txPower
Definition: openwsn.h:321
owerror_t l2_sendDoneError
Definition: openwsn.h:305
Definition: openwsn.h:225
Definition: openwsn.h:74
Definition: openwsn.h:223
Definition: openwsn.h:120
Definition: openwsn.h:207
Definition: openwsn.h:117
Definition: openwsn.h:243
Definition: openwsn.h:230
Definition: openwsn.h:177
Definition: openwsn.h:148
Definition: openwsn.h:90
uint8_t * l2_ASNpayload
Definition: openwsn.h:316
bool l2_IEListPresent
Definition: openwsn.h:318
Definition: openwsn.h:95
uint16_t l4_sourcePortORicmpv6Type
Definition: openwsn.h:297
Definition: openwsn.h:184
Definition: openwsn.h:64
Definition: openwsn.h:245
uint8_t l2_numTxAttempts
Definition: openwsn.h:310
Definition: openwsn.h:211
Definition: openwsn.h:142
Definition: openwsn.h:72
Definition: openwsn.h:40
bool l2_joinPriorityPresent
Definition: openwsn.h:319
Definition: openwsn.h:237
Definition: openwsn.h:196
uint8_t byte4
Definition: openwsn.h:269
Definition: openwsn.h:229
Definition: openwsn.h:165
uint8_t * l2_scheduleIE_cellObjects
Definition: openwsn.h:313
Definition: openwsn.h:172
Definition: openwsn.h:224
Definition: openwsn.h:159
uint8_t creator
Definition: openwsn.h:290
Definition: openwsn.h:180
uint16_t bytes0and1
Definition: openwsn.h:271
Definition: openwsn.h:140
bool l4_protocol_compressed
Definition: openwsn.h:296
Definition: openwsn.h:231
open_addr_t l2_nextORpreviousHop
Definition: openwsn.h:306
Definition: openwsn.h:256
Definition: openwsn.h:46
Definition: openwsn.h:144
uint8_t owerror_t
Definition: openwsn.h:265
Definition: openwsn.h:84
Definition: openwsn.h:238
uint8_t l2_frameType
Definition: openwsn.h:307
Definition: openwsn.h:171
uint8_t * payload
Definition: openwsn.h:292
int8_t l1_rssi
Definition: openwsn.h:322
Definition: openwsn.h:107
Definition: openwsn.h:254
uint16_t l4_destination_port
Definition: openwsn.h:298
Definition: openwsn.h:83
Definition: openwsn.h:160
Definition: openwsn.h:175
Definition: openwsn.h:106
Definition: openwsn.h:228
uint16_t errorparameter_t
Definition: openwsn.h:263
Definition: openwsn.h:163
Definition: openwsn.h:253
uint8_t length
Definition: openwsn.h:293
Definition: openwsn.h:70
Definition: openwsn.h:62
Definition: openwsn.h:239
Definition: openwsn.h:67
Definition: openwsn.h:121
Definition: openwsn.h:147
Definition: openwsn.h:249
Definition: openwsn.h:268
Definition: openwsn.h:66
Definition: openwsn.h:213
uint8_t l2_retriesLeft
Definition: openwsn.h:309
Definition: openwsn.h:181
Definition: openwsn.h:109
Definition: openwsn.h:91
Definition: openwsn.h:137
Definition: openwsn.h:203
Definition: openwsn.h:111
Definition: openwsn.h:221
Definition: openwsn.h:179
Definition: openwsn.h:92
Definition: openwsn.h:257
Definition: openwsn.h:166
Definition: openwsn.h:182
Definition: openwsn.h:212
Definition: openwsn.h:214
Definition: openwsn.h:104
Definition: openwsn.h:69
Definition: openwsn.h:105
Definition: openwsn.h:204
Definition: openwsn.h:202
void openwsn_init()
General OpenWSN definitions.
Definition: openwsn.c:80
Definition: openwsn.h:210
uint8_t l4_protocol
Definition: openwsn.h:295
Definition: openwsn.h:93
Definition: openwsn.h:108
Definition: openwsn.h:110
asn_t l2_asn
Definition: openwsn.h:311
Definition: openwsn.h:50
Definition: openwsn.h:57
Definition: openwsn.h:103
uint8_t * l2_payload
Definition: openwsn.h:312
Definition: openwsn.h:161
Definition: openwsn.h:244
Definition: openwsn.h:208
Definition: openwsn.h:128
Definition: openwsn.h:155
Definition: openwsn.h:276
Definition: openwsn.h:150
Definition: openwsn.h:118
Definition: openwsn.h:56
bool l1_crc
Definition: openwsn.h:324
Definition: openwsn.h:41
Definition: openwsn.h:151
Definition: openwsn.h:49
Definition: openwsn.h:247
Definition: openwsn.h:129
Definition: openwsn.h:157
Definition: openwsn.h:76
Definition: openwsn.h:218
Definition: openwsn.h:48
Definition: openwsn.h:169
uint8_t l2_scheduleIE_numOfCells
Definition: openwsn.h:314
Definition: openwsn.h:153
Definition: openwsn.h:162
Definition: openwsn.h:139
Definition: openwsn.h:219
Definition: openwsn.h:255
Definition: openwsn.h:101
Definition: openwsn.h:235
Definition: openwsn.h:246
#define FALSE
Definition: openwsn.h:31
Definition: openwsn.h:250
uint16_t dagrank_t
Definition: openwsn.h:264
Definition: openwsn.h:183
Definition: openwsn.h:73
Definition: openwsn.h:158
Definition: openwsn.h:200
uint8_t l2_dsn
Definition: openwsn.h:308
Definition: openwsn.h:141
uint8_t l2_joinPriority
Definition: openwsn.h:317
Definition: openwsn.h:173
uint8_t owner
Definition: openwsn.h:291
Definition: openwsn.h:198
Definition: openwsn.h:71
Definition: openwsn.h:136
Definition: openwsn.h:288
Definition: openwsn.h:205
uint8_t l1_lqi
Definition: openwsn.h:323
Definition: openwsn.h:145
uint16_t bytes2and3
Definition: openwsn.h:270
Definition: openwsn.h:88
Definition: openwsn.h:86
Definition: openwsn.h:52
Definition: openwsn.h:89
Definition: openwsn.h:197
uint8_t l4_length
Definition: openwsn.h:300
uint8_t type
Definition: openwsn.h:277
Definition: openwsn.h:102
Definition: openwsn.h:68
Definition: openwsn.h:233
Definition: openwsn.h:234
Definition: openwsn.h:215
Definition: openwsn.h:123
Definition: openwsn.h:124
Definition: openwsn.h:209
Definition: openwsn.h:149
Definition: openwsn.h:176
Definition: openwsn.h:240
Definition: openwsn.h:168
Definition: openwsn.h:100
Definition: openwsn.h:232
Definition: openwsn.h:226
Definition: openwsn.h:51
#define TRUE
Definition: openwsn.h:27
Definition: openwsn.h:122