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 
126 
136 typedef struct __attribute__((packed)) {
145  uint8_t offset;
147 
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 {
184  return sixlowpan_frag_1_is(hdr) || sixlowpan_frag_n_is(hdr);
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 {
333  return ((*data & SIXLOWPAN_IPHC1_DISP_MASK) == SIXLOWPAN_IPHC1_DISP);
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 
sixlowpan_frag_n_is
static bool sixlowpan_frag_n_is(sixlowpan_frag_t *hdr)
Checks if a given header is a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:169
sixlowpan_iphc_is
static bool sixlowpan_iphc_is(uint8_t *data)
Checks if datagram is an IPHC datagram.
Definition: sixlowpan.h:331
byteorder.h
Functions to work with different byte orders.
be_uint16_t
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:77
SIXLOWPAN_FRAG_N_DISP
#define SIXLOWPAN_FRAG_N_DISP
dispatch for subsequent fragments
Definition: sixlowpan.h:44
be_uint16_t::u8
uint8_t u8[2]
8 bit representation
Definition: byteorder.h:79
SIXLOWPAN_IPHC1_DISP_MASK
#define SIXLOWPAN_IPHC1_DISP_MASK
Dispatch mask for LOWPAN_IPHC.
Definition: sixlowpan.h:54
sixlowpan_nalp
static bool sixlowpan_nalp(uint8_t disp)
Checks if dispatch indicates that frame is not a 6LoWPAN (NALP) frame.
Definition: sixlowpan.h:93
sixlowpan_frag_datagram_size
static uint16_t sixlowpan_frag_datagram_size(sixlowpan_frag_t *hdr)
Get datagram size from general 6LoWPAN fragment header.
Definition: sixlowpan.h:194
SIXLOWPAN_IPHC1_DISP
#define SIXLOWPAN_IPHC1_DISP
Dispatch for LOWPAN_IPHC.
Definition: sixlowpan.h:62
sixlowpan_print
void sixlowpan_print(uint8_t *data, size_t size)
Prints 6LoWPAN dispatch to stdout.
sixlowpan_frag_n_t::tag
network_uint16_t tag
datagram tag
Definition: sixlowpan.h:144
sixlowpan_frag_1_is
static bool sixlowpan_frag_1_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 1st 6LoWPAN fragment header.
Definition: sixlowpan.h:156
sixlowpan_frag_t
General and 1st 6LoWPAN fragmentation header.
Definition: sixlowpan.h:116
SIXLOWPAN_FRAG_SIZE_MASK
#define SIXLOWPAN_FRAG_SIZE_MASK
mask for datagram size
Definition: sixlowpan.h:103
sixlowpan_frag_n_t::offset
uint8_t offset
offset
Definition: sixlowpan.h:145
sixlowpan_frag_n_t
Subsequent 6LoWPAN fragmentation header.
Definition: sixlowpan.h:136
sixlowpan_frag_n_t::disp_size
network_uint16_t disp_size
Dispatch and datagram size.
Definition: sixlowpan.h:143
sixlowpan_frag_t::disp_size
network_uint16_t disp_size
Dispatch and datagram size.
Definition: sixlowpan.h:123
sixlowpan_frag_is
static bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 6LoWPAN fragment header.
Definition: sixlowpan.h:182
sixlowpan_frag_t::tag
network_uint16_t tag
datagram tag
Definition: sixlowpan.h:124
byteorder_ntohs
static uint16_t byteorder_ntohs(network_uint16_t v)
Convert from network byte order to host byte order, 16 bit.
Definition: byteorder.h:458
SIXLOWPAN_FRAG_DISP_MASK
#define SIXLOWPAN_FRAG_DISP_MASK
mask for fragmentation dispatch
Definition: sixlowpan.h:41
sixlowpan_frag_datagram_tag
static uint16_t sixlowpan_frag_datagram_tag(sixlowpan_frag_t *hdr)
Get datagram tag from general 6LoWPAN fragment header.
Definition: sixlowpan.h:206
sixlowpan_frag_offset
static uint16_t sixlowpan_frag_offset(sixlowpan_frag_n_t *hdr)
Get fragment offset from a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:218
SIXLOWPAN_FRAG_1_DISP
#define SIXLOWPAN_FRAG_1_DISP
dispatch for 1st fragment
Definition: sixlowpan.h:43