sfr.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
22 #include <assert.h>
23 #include <stdbool.h>
24 #include <stdint.h>
25 
26 #include "bitfield.h"
27 #include "byteorder.h"
28 #include "net/sixlowpan.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
43 #define SIXLOWPAN_SFR_GEN_DISP_MASK (0xfc)
44 #define SIXLOWPAN_SFR_GEN_DISP (0xe8)
45 #define SIXLOWPAN_SFR_ECN (0x01U)
46 #define SIXLOWPAN_SFR_ACK_REQ (0x80U)
47 #define SIXLOWPAN_SFR_SEQ_MASK (0x7cU)
48 #define SIXLOWPAN_SFR_SEQ_POS (2U)
49 #define SIXLOWPAN_SFR_SEQ_MAX (0x1fU)
50 #define SIXLOWPAN_SFR_FRAG_SIZE_MASK (0x03ffU)
51 #define SIXLOWPAN_SFR_FRAG_SIZE_MAX (0x03ffU)
52 #define SIXLOWPAN_SFR_ACK_BITMAP_SIZE (32U)
59 typedef struct __attribute__((packed)) {
84  uint8_t disp_ecn;
85  uint8_t tag;
87 
93 typedef struct __attribute__((packed)) {
119 
131 
137 typedef struct __attribute__((packed)) {
144 
156 static inline bool sixlowpan_sfr_is(sixlowpan_sfr_t *hdr)
157 {
159 }
160 
166 static inline void sixlowpan_sfr_set_ecn(sixlowpan_sfr_t *hdr)
167 {
168  hdr->disp_ecn |= SIXLOWPAN_SFR_ECN;
169 }
170 
176 static inline void sixlowpan_sfr_clear_ecn(sixlowpan_sfr_t *hdr)
177 {
178  hdr->disp_ecn &= ~SIXLOWPAN_SFR_ECN;
179 }
180 
190 static inline bool sixlowpan_sfr_ecn(const sixlowpan_sfr_t *hdr)
191 {
192  return (hdr->disp_ecn & SIXLOWPAN_SFR_ECN);
193 }
194 
203 {
206 }
207 
218 static inline bool sixlowpan_sfr_rfrag_is(const sixlowpan_sfr_t *hdr)
219 {
221 }
222 
230 {
232 }
233 
241 {
242  hdr->ar_seq_fs.u8[0] &= ~SIXLOWPAN_SFR_ACK_REQ;
243 }
244 
255 {
256  return (hdr->ar_seq_fs.u8[0] & SIXLOWPAN_SFR_ACK_REQ);
257 }
258 
269  uint8_t seq)
270 {
272  hdr->ar_seq_fs.u8[0] &= ~SIXLOWPAN_SFR_SEQ_MASK;
273  hdr->ar_seq_fs.u8[0] |= (seq << SIXLOWPAN_SFR_SEQ_POS);
274 }
275 
283 static inline uint8_t sixlowpan_sfr_rfrag_get_seq(const sixlowpan_sfr_rfrag_t *hdr)
284 {
285  return ((hdr->ar_seq_fs.u8[0] & SIXLOWPAN_SFR_SEQ_MASK) >>
287 }
288 
299  uint16_t frag_size)
300 {
301  assert(frag_size <= SIXLOWPAN_SFR_FRAG_SIZE_MAX);
303  hdr->ar_seq_fs.u16 |= htons(frag_size);
304 }
305 
314 {
316 }
317 
325  uint16_t offset)
326 {
327  hdr->offset = byteorder_htons(offset);
328 }
329 
337 static inline uint16_t sixlowpan_sfr_rfrag_get_offset(const sixlowpan_sfr_rfrag_t *hdr)
338 {
339  return byteorder_ntohs(hdr->offset);
340 }
341 
350 {
353 }
354 
365 static inline bool sixlowpan_sfr_ack_is(const sixlowpan_sfr_t *hdr)
366 {
368 }
369 
370 #ifdef __cplusplus
371 }
372 #endif
373 
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:143
bitfields operations on bitfields of arbitrary length
Functions to work with different byte orders.
static network_uint16_t byteorder_htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
Definition: byteorder.h:481
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 uint16_t htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
Definition: byteorder.h:517
#define SIXLOWPAN_SFR_FRAG_SIZE_MAX
Maximum value for fragment size.
Definition: sfr.h:51
#define SIXLOWPAN_SFR_SEQ_MASK
Sequence number mask (for 8 MSB)
Definition: sfr.h:47
static bool sixlowpan_sfr_ack_is(const sixlowpan_sfr_t *hdr)
Check if given header is a 6LoWPAN RFRAG acknowledgment header.
Definition: sfr.h:365
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:324
#define SIXLOWPAN_SFR_ACK_REQ
Acknowledgment request flag (for 8 MSB)
Definition: sfr.h:46
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:337
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:254
static void sixlowpan_sfr_set_ecn(sixlowpan_sfr_t *hdr)
Set the ECN flag in a 6LoWPAN selective fragment recovery header.
Definition: sfr.h:166
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:229
static void sixlowpan_sfr_ack_set_disp(sixlowpan_sfr_t *hdr)
Initialize 6LoWPAN RFRAG acknowledgment dispatch.
Definition: sfr.h:349
#define SIXLOWPAN_SFR_ACK_BITMAP_SIZE
Acknowledgment bitmap size in bits.
Definition: sfr.h:52
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:190
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:298
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:268
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:313
#define SIXLOWPAN_SFR_FRAG_SIZE_MASK
Fragment size mask.
Definition: sfr.h:50
static void sixlowpan_sfr_rfrag_set_disp(sixlowpan_sfr_t *hdr)
Initialize 6LoWPAN recoverable fragment dispatch.
Definition: sfr.h:202
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:283
#define SIXLOWPAN_SFR_GEN_DISP
generic dispatch for both SFR headers
Definition: sfr.h:44
static bool sixlowpan_sfr_rfrag_is(const sixlowpan_sfr_t *hdr)
Check if given header is a 6LoWPAN recoverable fragment header.
Definition: sfr.h:218
#define SIXLOWPAN_SFR_SEQ_POS
Sequence number position (for 8 MSB)
Definition: sfr.h:48
#define SIXLOWPAN_SFR_GEN_DISP_MASK
Mask for generic dispatch of both selective fragment recovery headers.
Definition: sfr.h:43
#define SIXLOWPAN_SFR_ECN
explicit congestion notification flag
Definition: sfr.h:45
static void sixlowpan_sfr_clear_ecn(sixlowpan_sfr_t *hdr)
Clear the ECN flag in a 6LoWPAN recoverable fragment header.
Definition: sfr.h:176
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:156
#define SIXLOWPAN_SFR_SEQ_MAX
Maximum value for sequence number.
Definition: sfr.h:49
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:240
#define SIXLOWPAN_SFR_DISP_MASK
Dispatch mask for 6LoWPAN selective fragment recovery.
Definition: sixlowpan.h:65
#define SIXLOWPAN_SFR_RFRAG_DISP
Dispatch for 6LoWPAN recoverable fragment.
Definition: sixlowpan.h:71
#define SIXLOWPAN_SFR_ACK_DISP
Dispatch for 6LoWPAN recoverable fragment acknowledgment.
Definition: sixlowpan.h:77
6LoWPAN dispatch type and helper function definitions.
Recoverable fragment (RFRAG) acknowledgment header.
Definition: sfr.h:137
sixlowpan_sfr_t base
generic part
Definition: sfr.h:138
BITFIELD(bitmap, SIXLOWPAN_SFR_ACK_BITMAP_SIZE)
RFRAG acknowledgment bitmap.
Recoverable fragment header.
Definition: sfr.h:93
network_uint16_t offset
Fragment offset.
Definition: sfr.h:129
sixlowpan_sfr_t base
generic part
Definition: sfr.h:94
network_uint16_t ar_seq_fs
Acknowledgment request flag, sequence number, and fragment size.
Definition: sfr.h:118
Generic type for selective fragment recovery headers.
Definition: sfr.h:59
uint8_t disp_ecn
Dispatch and explicit congestion notification (ECN) flag.
Definition: sfr.h:84
uint8_t tag
Datagram tag.
Definition: sfr.h:85
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
uint16_t u16
16 bit representation
Definition: byteorder.h:71