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 
68 #define SIXLOWPAN_SFR_DISP_MASK (0xfe)
69 
74 #define SIXLOWPAN_SFR_RFRAG_DISP (0xe8)
75 
80 #define SIXLOWPAN_SFR_ACK_DISP (0xea)
81 
90 static inline bool sixlowpan_nalp(uint8_t disp)
91 {
92  return ((disp & 0xc0) == 0);
93 }
100 #define SIXLOWPAN_FRAG_SIZE_MASK (0x07ff)
113 typedef struct __attribute__((packed)) {
123 
133 typedef struct __attribute__((packed)) {
142  uint8_t offset;
144 
153 static inline bool sixlowpan_frag_1_is(sixlowpan_frag_t *hdr)
154 {
156 }
157 
166 static inline bool sixlowpan_frag_n_is(sixlowpan_frag_t *hdr)
167 {
169 }
170 
179 static inline bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
180 {
181  return sixlowpan_frag_1_is(hdr) || sixlowpan_frag_n_is(hdr);
182 }
183 
191 static inline uint16_t sixlowpan_frag_datagram_size(sixlowpan_frag_t *hdr)
192 {
194 }
195 
203 static inline uint16_t sixlowpan_frag_datagram_tag(sixlowpan_frag_t *hdr)
204 {
205  return byteorder_ntohs(hdr->tag);
206 }
207 
215 static inline uint16_t sixlowpan_frag_offset(sixlowpan_frag_n_t *hdr)
216 {
217  /* https://tools.ietf.org/html/rfc4944#section-5.3:
218  * datagram_offset: This field is present only in the second and
219  * subsequent link fragments and SHALL specify the offset, in
220  * increments of 8 octets, of the fragment from the beginning of the
221  * payload datagram. [...] */
222  return (hdr->offset * 8U);
223 }
237 #define SIXLOWPAN_IPHC1_TF (0x18)
238 
246 #define SIXLOWPAN_IPHC1_NH (0x04)
247 
254 #define SIXLOWPAN_IPHC1_HL (0x03)
255 
263 #define SIXLOWPAN_IPHC2_CID_EXT (0x80)
264 
272 #define SIXLOWPAN_IPHC2_SAC (0x40)
273 
281 #define SIXLOWPAN_IPHC2_SAM (0x30)
282 
290 #define SIXLOWPAN_IPHC2_DAC (0x04)
291 
299 #define SIXLOWPAN_IPHC2_DAM (0x03)
300 
308 #define SIXLOWPAN_IPHC2_M (0x08)
309 
313 #define SIXLOWPAN_IPHC_HDR_LEN (2)
314 
318 #define SIXLOWPAN_IPHC_CID_EXT_LEN (1)
319 
328 static inline bool sixlowpan_iphc_is(uint8_t *data)
329 {
330  return ((*data & SIXLOWPAN_IPHC1_DISP_MASK) == SIXLOWPAN_IPHC1_DISP);
331 }
340 void sixlowpan_print(uint8_t *data, size_t size);
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 
346 #endif /* NET_SIXLOWPAN_H */
Functions to work with different byte orders.
static uint16_t byteorder_ntohs(network_uint16_t v)
Convert from network byte order to host byte order, 16 bit.
Definition: byteorder.h:506
static bool sixlowpan_frag_n_is(sixlowpan_frag_t *hdr)
Checks if a given header is a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:166
#define SIXLOWPAN_IPHC1_DISP_MASK
Dispatch mask for LOWPAN_IPHC.
Definition: sixlowpan.h:54
#define SIXLOWPAN_FRAG_DISP_MASK
mask for fragmentation dispatch
Definition: sixlowpan.h:41
#define SIXLOWPAN_IPHC1_DISP
Dispatch for LOWPAN_IPHC.
Definition: sixlowpan.h:62
static bool sixlowpan_frag_1_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 1st 6LoWPAN fragment header.
Definition: sixlowpan.h:153
static bool sixlowpan_iphc_is(uint8_t *data)
Checks if datagram is an IPHC datagram.
Definition: sixlowpan.h:328
void sixlowpan_print(uint8_t *data, size_t size)
Prints 6LoWPAN dispatch to stdout.
#define SIXLOWPAN_FRAG_SIZE_MASK
mask for datagram size
Definition: sixlowpan.h:100
static bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 6LoWPAN fragment header.
Definition: sixlowpan.h:179
static uint16_t sixlowpan_frag_offset(sixlowpan_frag_n_t *hdr)
Get fragment offset from a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:215
#define SIXLOWPAN_FRAG_1_DISP
dispatch for 1st fragment
Definition: sixlowpan.h:43
static uint16_t sixlowpan_frag_datagram_tag(sixlowpan_frag_t *hdr)
Get datagram tag from general 6LoWPAN fragment header.
Definition: sixlowpan.h:203
static uint16_t sixlowpan_frag_datagram_size(sixlowpan_frag_t *hdr)
Get datagram size from general 6LoWPAN fragment header.
Definition: sixlowpan.h:191
#define SIXLOWPAN_FRAG_N_DISP
dispatch for subsequent fragments
Definition: sixlowpan.h:44
static bool sixlowpan_nalp(uint8_t disp)
Checks if dispatch indicates that frame is not a 6LoWPAN (NALP) frame.
Definition: sixlowpan.h:90
Subsequent 6LoWPAN fragmentation header.
Definition: sixlowpan.h:133
network_uint16_t disp_size
Dispatch and datagram size.
Definition: sixlowpan.h:140
network_uint16_t tag
datagram tag
Definition: sixlowpan.h:141
uint8_t offset
offset
Definition: sixlowpan.h:142
General and 1st 6LoWPAN fragmentation header.
Definition: sixlowpan.h:113
network_uint16_t disp_size
Dispatch and datagram size.
Definition: sixlowpan.h:120
network_uint16_t tag
datagram tag
Definition: sixlowpan.h:121
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:74
uint8_t u8[2]
8 bit representation
Definition: byteorder.h:76