sixlowpan.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef NET_SIXLOWPAN_H
21 #define NET_SIXLOWPAN_H
22 
23 #include <stdbool.h>
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include "byteorder.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
40 #define SIXLOWPAN_UNCOMP (0x41)
41 #define SIXLOWPAN_FRAG_DISP_MASK (0xf8)
43 #define SIXLOWPAN_FRAG_1_DISP (0xc0)
44 #define SIXLOWPAN_FRAG_N_DISP (0xe0)
46 #define SIXLOWPAN_FRAG_MAX_LEN (2047)
54 #define SIXLOWPAN_IPHC1_DISP_MASK (0xe0)
55 
62 #define SIXLOWPAN_IPHC1_DISP (0x60)
63 
69 #define SIXLOWPAN_SFR_DISP_MASK (0xfe)
70 
76 #define SIXLOWPAN_SFR_RFRAG_DISP (0xe8)
77 
83 #define SIXLOWPAN_SFR_ACK_DISP (0xea)
84 
93 static inline bool sixlowpan_nalp(uint8_t disp)
94 {
95  return ((disp & 0xc0) == 0);
96 }
103 #define SIXLOWPAN_FRAG_SIZE_MASK (0x07ff)
116 typedef struct __attribute__((packed)) {
117 
123  network_uint16_t disp_size;
124  network_uint16_t tag;
136 typedef struct __attribute__((packed)) {
143  network_uint16_t disp_size;
144  network_uint16_t tag;
145  uint8_t offset;
156 static inline bool sixlowpan_frag_1_is(sixlowpan_frag_t *hdr)
157 {
159 }
160 
169 static inline bool sixlowpan_frag_n_is(sixlowpan_frag_t *hdr)
170 {
172 }
173 
182 static inline bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
183 {
185 }
186 
194 static inline uint16_t sixlowpan_frag_datagram_size(sixlowpan_frag_t *hdr)
195 {
197 }
198 
206 static inline uint16_t sixlowpan_frag_datagram_tag(sixlowpan_frag_t *hdr)
207 {
208  return byteorder_ntohs(hdr->tag);
209 }
210 
218 static inline uint16_t sixlowpan_frag_offset(sixlowpan_frag_n_t *hdr)
219 {
220  /* https://tools.ietf.org/html/rfc4944#section-5.3:
221  * datagram_offset: This field is present only in the second and
222  * subsequent link fragments and SHALL specify the offset, in
223  * increments of 8 octets, of the fragment from the beginning of the
224  * payload datagram. [...] */
225  return (hdr->offset * 8U);
226 }
240 #define SIXLOWPAN_IPHC1_TF (0x18)
241 
249 #define SIXLOWPAN_IPHC1_NH (0x04)
250 
257 #define SIXLOWPAN_IPHC1_HL (0x03)
258 
266 #define SIXLOWPAN_IPHC2_CID_EXT (0x80)
267 
275 #define SIXLOWPAN_IPHC2_SAC (0x40)
276 
284 #define SIXLOWPAN_IPHC2_SAM (0x30)
285 
293 #define SIXLOWPAN_IPHC2_DAC (0x04)
294 
302 #define SIXLOWPAN_IPHC2_DAM (0x03)
303 
311 #define SIXLOWPAN_IPHC2_M (0x08)
312 
316 #define SIXLOWPAN_IPHC_HDR_LEN (2)
317 
321 #define SIXLOWPAN_IPHC_CID_EXT_LEN (1)
322 
331 static inline bool sixlowpan_iphc_is(uint8_t *data)
332 {
334 }
343 void sixlowpan_print(uint8_t *data, size_t size);
344 
345 #ifdef __cplusplus
346 }
347 #endif
348 
349 #endif /* NET_SIXLOWPAN_H */
350 
static bool sixlowpan_frag_n_is(sixlowpan_frag_t *hdr)
Checks if a given header is a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:171
static bool sixlowpan_iphc_is(uint8_t *data)
Checks if datagram is an IPHC datagram.
Definition: sixlowpan.h:333
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:76
#define SIXLOWPAN_IPHC1_DISP_MASK
Dispatch mask for LOWPAN_IPHC.
Definition: sixlowpan.h:56
#define SIXLOWPAN_FRAG_N_DISP
dispatch for subsequent fragments
Definition: sixlowpan.h:45
uint8_t offset
offset
Definition: sixlowpan.h:147
static uint16_t sixlowpan_frag_datagram_size(sixlowpan_frag_t *hdr)
Get datagram size from general 6LoWPAN fragment header.
Definition: sixlowpan.h:196
#define SIXLOWPAN_IPHC1_DISP
Dispatch for LOWPAN_IPHC.
Definition: sixlowpan.h:64
void sixlowpan_print(uint8_t *data, size_t size)
Prints 6LoWPAN dispatch to stdout.
static bool sixlowpan_nalp(uint8_t disp)
Checks if dispatch indicates that frame is not a 6LoWPAN (NALP) frame.
Definition: sixlowpan.h:95
static bool sixlowpan_frag_1_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 1st 6LoWPAN fragment header.
Definition: sixlowpan.h:158
General and 1st 6LoWPAN fragmentation header.
Definition: sixlowpan.h:118
#define SIXLOWPAN_FRAG_SIZE_MASK
mask for datagram size
Definition: sixlowpan.h:105
Subsequent 6LoWPAN fragmentation header.
Definition: sixlowpan.h:138
Functions to work with different byte orders.
#define SIXLOWPAN_FRAG_DISP_MASK
mask for fragmentation dispatch
Definition: sixlowpan.h:41
static bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 6LoWPAN fragment header.
Definition: sixlowpan.h:184
uint8_t u8[2]
8 bit representation
Definition: byteorder.h:78
static uint16_t sixlowpan_frag_datagram_tag(sixlowpan_frag_t *hdr)
Get datagram tag from general 6LoWPAN fragment header.
Definition: sixlowpan.h:208
static uint16_t sixlowpan_frag_offset(sixlowpan_frag_n_t *hdr)
Get fragment offset from a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:220
static uint16_t byteorder_ntohs(network_uint16_t v)
Convert from network byte order to host byte order, 16 bit.
Definition: byteorder.h:398
network_uint16_t tag
datagram tag
Definition: sixlowpan.h:126
#define SIXLOWPAN_FRAG_1_DISP
dispatch for 1st fragment
Definition: sixlowpan.h:44
network_uint16_t disp_size
Dispatch and datagram size.
Definition: sixlowpan.h:125