sixlowpan.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 
24 #include "byteorder.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
37 #define SIXLOWPAN_UNCOMP (0x41)
38 #define SIXLOWPAN_FRAG_DISP_MASK (0xf8)
40 #define SIXLOWPAN_FRAG_1_DISP (0xc0)
41 #define SIXLOWPAN_FRAG_N_DISP (0xe0)
43 #define SIXLOWPAN_FRAG_MAX_LEN (2047)
51 #define SIXLOWPAN_IPHC1_DISP_MASK (0xe0)
52 
59 #define SIXLOWPAN_IPHC1_DISP (0x60)
60 
65 #define SIXLOWPAN_SFR_DISP_MASK (0xfe)
66 
71 #define SIXLOWPAN_SFR_RFRAG_DISP (0xe8)
72 
77 #define SIXLOWPAN_SFR_ACK_DISP (0xea)
78 
87 static inline bool sixlowpan_nalp(uint8_t disp)
88 {
89  return ((disp & 0xc0) == 0);
90 }
97 #define SIXLOWPAN_FRAG_SIZE_MASK (0x07ff)
110 typedef struct __attribute__((packed)) {
120 
130 typedef struct __attribute__((packed)) {
139  uint8_t offset;
141 
150 static inline bool sixlowpan_frag_1_is(sixlowpan_frag_t *hdr)
151 {
153 }
154 
163 static inline bool sixlowpan_frag_n_is(sixlowpan_frag_t *hdr)
164 {
166 }
167 
176 static inline bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
177 {
178  return sixlowpan_frag_1_is(hdr) || sixlowpan_frag_n_is(hdr);
179 }
180 
188 static inline uint16_t sixlowpan_frag_datagram_size(sixlowpan_frag_t *hdr)
189 {
191 }
192 
200 static inline uint16_t sixlowpan_frag_datagram_tag(sixlowpan_frag_t *hdr)
201 {
202  return byteorder_ntohs(hdr->tag);
203 }
204 
212 static inline uint16_t sixlowpan_frag_offset(sixlowpan_frag_n_t *hdr)
213 {
214  /* https://tools.ietf.org/html/rfc4944#section-5.3:
215  * datagram_offset: This field is present only in the second and
216  * subsequent link fragments and SHALL specify the offset, in
217  * increments of 8 octets, of the fragment from the beginning of the
218  * payload datagram. [...] */
219  return (hdr->offset * 8U);
220 }
234 #define SIXLOWPAN_IPHC1_TF (0x18)
235 
243 #define SIXLOWPAN_IPHC1_NH (0x04)
244 
251 #define SIXLOWPAN_IPHC1_HL (0x03)
252 
260 #define SIXLOWPAN_IPHC2_CID_EXT (0x80)
261 
269 #define SIXLOWPAN_IPHC2_SAC (0x40)
270 
278 #define SIXLOWPAN_IPHC2_SAM (0x30)
279 
287 #define SIXLOWPAN_IPHC2_DAC (0x04)
288 
296 #define SIXLOWPAN_IPHC2_DAM (0x03)
297 
305 #define SIXLOWPAN_IPHC2_M (0x08)
306 
310 #define SIXLOWPAN_IPHC_HDR_LEN (2)
311 
315 #define SIXLOWPAN_IPHC_CID_EXT_LEN (1)
316 
325 static inline bool sixlowpan_iphc_is(uint8_t *data)
326 {
327  return ((*data & SIXLOWPAN_IPHC1_DISP_MASK) == SIXLOWPAN_IPHC1_DISP);
328 }
337 void sixlowpan_print(uint8_t *data, size_t size);
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 
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:502
static bool sixlowpan_frag_n_is(sixlowpan_frag_t *hdr)
Checks if a given header is a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:163
#define SIXLOWPAN_IPHC1_DISP_MASK
Dispatch mask for LOWPAN_IPHC.
Definition: sixlowpan.h:51
#define SIXLOWPAN_FRAG_DISP_MASK
mask for fragmentation dispatch
Definition: sixlowpan.h:38
#define SIXLOWPAN_IPHC1_DISP
Dispatch for LOWPAN_IPHC.
Definition: sixlowpan.h:59
static bool sixlowpan_frag_1_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 1st 6LoWPAN fragment header.
Definition: sixlowpan.h:150
static bool sixlowpan_iphc_is(uint8_t *data)
Checks if datagram is an IPHC datagram.
Definition: sixlowpan.h:325
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:97
static bool sixlowpan_frag_is(sixlowpan_frag_t *hdr)
Checks if a given header is a 6LoWPAN fragment header.
Definition: sixlowpan.h:176
static uint16_t sixlowpan_frag_offset(sixlowpan_frag_n_t *hdr)
Get fragment offset from a subsequent 6LoWPAN fragment header.
Definition: sixlowpan.h:212
#define SIXLOWPAN_FRAG_1_DISP
dispatch for 1st fragment
Definition: sixlowpan.h:40
static uint16_t sixlowpan_frag_datagram_tag(sixlowpan_frag_t *hdr)
Get datagram tag from general 6LoWPAN fragment header.
Definition: sixlowpan.h:200
static uint16_t sixlowpan_frag_datagram_size(sixlowpan_frag_t *hdr)
Get datagram size from general 6LoWPAN fragment header.
Definition: sixlowpan.h:188
#define SIXLOWPAN_FRAG_N_DISP
dispatch for subsequent fragments
Definition: sixlowpan.h:41
static bool sixlowpan_nalp(uint8_t disp)
Checks if dispatch indicates that frame is not a 6LoWPAN (NALP) frame.
Definition: sixlowpan.h:87
Subsequent 6LoWPAN fragmentation header.
Definition: sixlowpan.h:130
network_uint16_t disp_size
Dispatch and datagram size.
Definition: sixlowpan.h:137
network_uint16_t tag
datagram tag
Definition: sixlowpan.h:138
uint8_t offset
offset
Definition: sixlowpan.h:139
General and 1st 6LoWPAN fragmentation header.
Definition: sixlowpan.h:110
network_uint16_t disp_size
Dispatch and datagram size.
Definition: sixlowpan.h:117
network_uint16_t tag
datagram tag
Definition: sixlowpan.h:118
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:70
uint8_t u8[2]
8 bit representation
Definition: byteorder.h:72