sfr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Freie Universität Berlin
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 
22 #ifndef NET_SIXLOWPAN_SFR_H
23 #define NET_SIXLOWPAN_SFR_H
24 
25 #include <assert.h>
26 #include <stdbool.h>
27 #include <stdint.h>
28 
29 #include "bitfield.h"
30 #include "byteorder.h"
31 #include "net/sixlowpan.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
46 #define SIXLOWPAN_SFR_GEN_DISP_MASK (0xfc)
47 #define SIXLOWPAN_SFR_GEN_DISP (0xe8)
48 #define SIXLOWPAN_SFR_ECN (0x01U)
49 #define SIXLOWPAN_SFR_ACK_REQ (0x80U)
50 #define SIXLOWPAN_SFR_SEQ_MASK (0x7cU)
51 #define SIXLOWPAN_SFR_SEQ_POS (2U)
52 #define SIXLOWPAN_SFR_SEQ_MAX (0x1fU)
53 #define SIXLOWPAN_SFR_FRAG_SIZE_MASK (0x03ffU)
54 #define SIXLOWPAN_SFR_FRAG_SIZE_MAX (0x03ffU)
55 #define SIXLOWPAN_SFR_ACK_BITMAP_SIZE (32U)
63 typedef struct __attribute__((packed)) {
64 
88  uint8_t disp_ecn;
89  uint8_t tag;
91 
98 typedef struct __attribute__((packed)) {
124 
136 
143 typedef struct __attribute__((packed)) {
150 
162 static inline bool sixlowpan_sfr_is(sixlowpan_sfr_t *hdr)
163 {
165 }
166 
172 static inline void sixlowpan_sfr_set_ecn(sixlowpan_sfr_t *hdr)
173 {
174  hdr->disp_ecn |= SIXLOWPAN_SFR_ECN;
175 }
176 
182 static inline void sixlowpan_sfr_clear_ecn(sixlowpan_sfr_t *hdr)
183 {
184  hdr->disp_ecn &= ~SIXLOWPAN_SFR_ECN;
185 }
186 
196 static inline bool sixlowpan_sfr_ecn(const sixlowpan_sfr_t *hdr)
197 {
198  return (hdr->disp_ecn & SIXLOWPAN_SFR_ECN);
199 }
200 
209 {
212 }
213 
224 static inline bool sixlowpan_sfr_rfrag_is(const sixlowpan_sfr_t *hdr)
225 {
227 }
228 
236 {
238 }
239 
247 {
248  hdr->ar_seq_fs.u8[0] &= ~SIXLOWPAN_SFR_ACK_REQ;
249 }
250 
261 {
262  return (hdr->ar_seq_fs.u8[0] & SIXLOWPAN_SFR_ACK_REQ);
263 }
264 
275  uint8_t seq)
276 {
278  hdr->ar_seq_fs.u8[0] &= ~SIXLOWPAN_SFR_SEQ_MASK;
279  hdr->ar_seq_fs.u8[0] |= (seq << SIXLOWPAN_SFR_SEQ_POS);
280 }
281 
289 static inline uint8_t sixlowpan_sfr_rfrag_get_seq(const sixlowpan_sfr_rfrag_t *hdr)
290 {
291  return ((hdr->ar_seq_fs.u8[0] & SIXLOWPAN_SFR_SEQ_MASK) >>
293 }
294 
305  uint16_t frag_size)
306 {
307  assert(frag_size <= SIXLOWPAN_SFR_FRAG_SIZE_MAX);
309  hdr->ar_seq_fs.u16 |= htons(frag_size);
310 }
311 
320 {
322 }
323 
331  uint16_t offset)
332 {
333  hdr->offset = byteorder_htons(offset);
334 }
335 
343 static inline uint16_t sixlowpan_sfr_rfrag_get_offset(const sixlowpan_sfr_rfrag_t *hdr)
344 {
345  return byteorder_ntohs(hdr->offset);
346 }
347 
356 {
359 }
360 
371 static inline bool sixlowpan_sfr_ack_is(const sixlowpan_sfr_t *hdr)
372 {
374 }
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 
380 #endif /* NET_SIXLOWPAN_SFR_H */
381 
sixlowpan_sfr_ack_set_disp
static void sixlowpan_sfr_ack_set_disp(sixlowpan_sfr_t *hdr)
Initialize 6LoWPAN RFRAG acknowledgment dispatch.
Definition: sfr.h:355
sixlowpan_sfr_rfrag_get_offset
static uint16_t sixlowpan_sfr_rfrag_get_offset(const sixlowpan_sfr_rfrag_t *hdr)
Get fragment offset from a 6LoWPAN recoverable fragment header.
Definition: sfr.h:343
sixlowpan_sfr_ecn
static bool sixlowpan_sfr_ecn(const sixlowpan_sfr_t *hdr)
Check if the ECN flag in a 6LoWPAN recoverable fragment header is set.
Definition: sfr.h:196
sixlowpan_sfr_rfrag_get_frag_size
static uint16_t sixlowpan_sfr_rfrag_get_frag_size(const sixlowpan_sfr_rfrag_t *hdr)
Get fragment size from a 6LoWPAN recoverable fragment header.
Definition: sfr.h:319
sixlowpan_sfr_t::tag
uint8_t tag
Datagram tag.
Definition: sfr.h:89
sixlowpan_sfr_rfrag_is
static bool sixlowpan_sfr_rfrag_is(const sixlowpan_sfr_t *hdr)
Check if given header is a 6LoWPAN recoverable fragment header.
Definition: sfr.h:224
sixlowpan_sfr_is
static bool sixlowpan_sfr_is(sixlowpan_sfr_t *hdr)
Check if given header is a 6LoWPAN selective fragment recovery header (either RFRAG or RFRAG ACK)
Definition: sfr.h:162
sixlowpan_sfr_rfrag_t::base
sixlowpan_sfr_t base
generic part
Definition: sfr.h:99
bitfield.h
bitfields operations on bitfields of arbitrary length
sixlowpan.h
6LoWPAN dispatch type and helper function definitions.
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
assert
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
sixlowpan_sfr_clear_ecn
static void sixlowpan_sfr_clear_ecn(sixlowpan_sfr_t *hdr)
Clear the ECN flag in a 6LoWPAN recoverable fragment header.
Definition: sfr.h:182
be_uint16_t::u8
uint8_t u8[2]
8 bit representation
Definition: byteorder.h:79
assert.h
POSIX.1-2008 compliant version of the assert macro.
sixlowpan_sfr_rfrag_set_seq
static void sixlowpan_sfr_rfrag_set_seq(sixlowpan_sfr_rfrag_t *hdr, uint8_t seq)
Set sequence number in a 6LoWPAN recoverable fragment header.
Definition: sfr.h:274
sixlowpan_sfr_rfrag_set_disp
static void sixlowpan_sfr_rfrag_set_disp(sixlowpan_sfr_t *hdr)
Initialize 6LoWPAN recoverable fragment dispatch.
Definition: sfr.h:208
sixlowpan_sfr_t
Generic type for selective fragment recovery headers.
Definition: sfr.h:63
SIXLOWPAN_SFR_ACK_DISP
#define SIXLOWPAN_SFR_ACK_DISP
Dispatch for 6LoWPAN recoverable fragment acknowledgment.
Definition: sixlowpan.h:83
sixlowpan_sfr_rfrag_set_offset
static void sixlowpan_sfr_rfrag_set_offset(sixlowpan_sfr_rfrag_t *hdr, uint16_t offset)
Set fragment offset in a 6LoWPAN recoverable fragment header.
Definition: sfr.h:330
sixlowpan_sfr_ack_is
static bool sixlowpan_sfr_ack_is(const sixlowpan_sfr_t *hdr)
Check if given header is a 6LoWPAN RFRAG acknowledgment header.
Definition: sfr.h:371
sixlowpan_sfr_ack_t
Recoverable fragment (RFRAG) acknowledgment header.
Definition: sfr.h:143
sixlowpan_sfr_rfrag_set_frag_size
static void sixlowpan_sfr_rfrag_set_frag_size(sixlowpan_sfr_rfrag_t *hdr, uint16_t frag_size)
Set fragment size in a 6LoWPAN recoverable fragment header.
Definition: sfr.h:304
sixlowpan_sfr_rfrag_set_ack_req
static void sixlowpan_sfr_rfrag_set_ack_req(sixlowpan_sfr_rfrag_t *hdr)
Set the Acknowledgment request flag in a 6LoWPAN recoverable fragment header.
Definition: sfr.h:235
SIXLOWPAN_SFR_ACK_REQ
#define SIXLOWPAN_SFR_ACK_REQ
Acknowledgment request flag (for 8 MSB)
Definition: sfr.h:49
sixlowpan_sfr_rfrag_t::ar_seq_fs
network_uint16_t ar_seq_fs
Acknowledgment request flag, sequence number, and fragment size.
Definition: sfr.h:123
SIXLOWPAN_SFR_DISP_MASK
#define SIXLOWPAN_SFR_DISP_MASK
Dispatch mask for 6LoWPAN selective fragment recovery.
Definition: sixlowpan.h:69
SIXLOWPAN_SFR_ECN
#define SIXLOWPAN_SFR_ECN
explicit congestion notification flag
Definition: sfr.h:48
SIXLOWPAN_SFR_ACK_BITMAP_SIZE
#define SIXLOWPAN_SFR_ACK_BITMAP_SIZE
Acknowledgment bitmap size in bits.
Definition: sfr.h:55
SIXLOWPAN_SFR_FRAG_SIZE_MASK
#define SIXLOWPAN_SFR_FRAG_SIZE_MASK
Fragment size mask.
Definition: sfr.h:53
sixlowpan_sfr_t::disp_ecn
uint8_t disp_ecn
Dispatch and explicit congestion notification (ECN) flag.
Definition: sfr.h:88
byteorder_htons
static network_uint16_t byteorder_htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
Definition: byteorder.h:437
sixlowpan_sfr_rfrag_t
Recoverable fragment header.
Definition: sfr.h:98
SIXLOWPAN_SFR_SEQ_POS
#define SIXLOWPAN_SFR_SEQ_POS
Sequence number position (for 8 MSB)
Definition: sfr.h:51
sixlowpan_sfr_rfrag_t::offset
network_uint16_t offset
Fragment offset.
Definition: sfr.h:134
SIXLOWPAN_SFR_FRAG_SIZE_MAX
#define SIXLOWPAN_SFR_FRAG_SIZE_MAX
Maximum value for fragment size.
Definition: sfr.h:54
sixlowpan_sfr_set_ecn
static void sixlowpan_sfr_set_ecn(sixlowpan_sfr_t *hdr)
Set the ECN flag in a 6LoWPAN selective fragment recovery header.
Definition: sfr.h:172
htons
static uint16_t htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
Definition: byteorder.h:473
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
be_uint16_t::u16
uint16_t u16
16 bit representation
Definition: byteorder.h:78
sixlowpan_sfr_rfrag_get_seq
static uint8_t sixlowpan_sfr_rfrag_get_seq(const sixlowpan_sfr_rfrag_t *hdr)
Get sequence number from a 6LoWPAN recoverable fragment header.
Definition: sfr.h:289
SIXLOWPAN_SFR_SEQ_MAX
#define SIXLOWPAN_SFR_SEQ_MAX
Maximum value for sequence number.
Definition: sfr.h:52
SIXLOWPAN_SFR_SEQ_MASK
#define SIXLOWPAN_SFR_SEQ_MASK
Sequence number mask (for 8 MSB)
Definition: sfr.h:50
sixlowpan_sfr_ack_t::base
sixlowpan_sfr_t base
generic part
Definition: sfr.h:144
sixlowpan_sfr_rfrag_clear_ack_req
static void sixlowpan_sfr_rfrag_clear_ack_req(sixlowpan_sfr_rfrag_t *hdr)
Clear the Acknowledgment request flag in a 6LoWPAN recoverable fragment header.
Definition: sfr.h:246
BITFIELD
#define BITFIELD(NAME, SIZE)
Declare a bitfield of a given size.
Definition: bitfield.h:46
sixlowpan_sfr_rfrag_ack_req
static bool sixlowpan_sfr_rfrag_ack_req(sixlowpan_sfr_rfrag_t *hdr)
Check if the Acknowledgment request flag in a 6LoWPAN recoverable fragment header is set.
Definition: sfr.h:260
SIXLOWPAN_SFR_GEN_DISP
#define SIXLOWPAN_SFR_GEN_DISP
generic dispatch for both SFR headers
Definition: sfr.h:47
SIXLOWPAN_SFR_GEN_DISP_MASK
#define SIXLOWPAN_SFR_GEN_DISP_MASK
Mask for generic dispatch of both selective fragment recovery headers.
Definition: sfr.h:46
SIXLOWPAN_SFR_RFRAG_DISP
#define SIXLOWPAN_SFR_RFRAG_DISP
Dispatch for 6LoWPAN recoverable fragment.
Definition: sixlowpan.h:76