Loading...
Searching...
No Matches
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
34extern "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)
62typedef struct __attribute__((packed)) {
87 uint8_t disp_ecn;
88 uint8_t tag;
90
134
140typedef struct __attribute__((packed)) {
147
159static inline bool sixlowpan_sfr_is(sixlowpan_sfr_t *hdr)
160{
162}
163
170{
172}
173
180{
181 hdr->disp_ecn &= ~SIXLOWPAN_SFR_ECN;
182}
183
193static inline bool sixlowpan_sfr_ecn(const sixlowpan_sfr_t *hdr)
194{
195 return (hdr->disp_ecn & SIXLOWPAN_SFR_ECN);
196}
197
206{
207 hdr->disp_ecn &= ~SIXLOWPAN_SFR_DISP_MASK;
209}
210
221static inline bool sixlowpan_sfr_rfrag_is(const sixlowpan_sfr_t *hdr)
222{
224}
225
236
244{
245 hdr->ar_seq_fs.u8[0] &= ~SIXLOWPAN_SFR_ACK_REQ;
246}
247
258{
259 return (hdr->ar_seq_fs.u8[0] & SIXLOWPAN_SFR_ACK_REQ);
260}
261
272 uint8_t seq)
273{
275 hdr->ar_seq_fs.u8[0] &= ~SIXLOWPAN_SFR_SEQ_MASK;
276 hdr->ar_seq_fs.u8[0] |= (seq << SIXLOWPAN_SFR_SEQ_POS);
277}
278
286static inline uint8_t sixlowpan_sfr_rfrag_get_seq(const sixlowpan_sfr_rfrag_t *hdr)
287{
288 return ((hdr->ar_seq_fs.u8[0] & SIXLOWPAN_SFR_SEQ_MASK) >>
290}
291
302 uint16_t frag_size)
303{
306 hdr->ar_seq_fs.u16 |= htons(frag_size);
307}
308
320
328 uint16_t offset)
329{
330 hdr->offset = byteorder_htons(offset);
331}
332
341{
342 return byteorder_ntohs(hdr->offset);
343}
344
353{
354 hdr->disp_ecn &= ~SIXLOWPAN_SFR_DISP_MASK;
356}
357
368static inline bool sixlowpan_sfr_ack_is(const sixlowpan_sfr_t *hdr)
369{
371}
372
373#ifdef __cplusplus
374}
375#endif
376
377#endif /* NET_SIXLOWPAN_SFR_H */
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:136
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:485
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 uint16_t htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
Definition byteorder.h:521
#define SIXLOWPAN_SFR_FRAG_SIZE_MAX
Maximum value for fragment size.
Definition sfr.h:54
#define SIXLOWPAN_SFR_SEQ_MASK
Sequence number mask (for 8 MSB)
Definition sfr.h:50
static bool sixlowpan_sfr_ack_is(const sixlowpan_sfr_t *hdr)
Check if given header is a 6LoWPAN RFRAG acknowledgment header.
Definition sfr.h:368
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:327
#define SIXLOWPAN_SFR_ACK_REQ
Acknowledgment request flag (for 8 MSB)
Definition sfr.h:49
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:340
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:257
static void sixlowpan_sfr_set_ecn(sixlowpan_sfr_t *hdr)
Set the ECN flag in a 6LoWPAN selective fragment recovery header.
Definition sfr.h:169
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:232
static void sixlowpan_sfr_ack_set_disp(sixlowpan_sfr_t *hdr)
Initialize 6LoWPAN RFRAG acknowledgment dispatch.
Definition sfr.h:352
#define SIXLOWPAN_SFR_ACK_BITMAP_SIZE
Acknowledgment bitmap size in bits.
Definition sfr.h:55
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:193
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:301
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:271
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:316
#define SIXLOWPAN_SFR_FRAG_SIZE_MASK
Fragment size mask.
Definition sfr.h:53
static void sixlowpan_sfr_rfrag_set_disp(sixlowpan_sfr_t *hdr)
Initialize 6LoWPAN recoverable fragment dispatch.
Definition sfr.h:205
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:286
#define SIXLOWPAN_SFR_GEN_DISP
generic dispatch for both SFR headers
Definition sfr.h:47
static bool sixlowpan_sfr_rfrag_is(const sixlowpan_sfr_t *hdr)
Check if given header is a 6LoWPAN recoverable fragment header.
Definition sfr.h:221
#define SIXLOWPAN_SFR_SEQ_POS
Sequence number position (for 8 MSB)
Definition sfr.h:51
#define SIXLOWPAN_SFR_GEN_DISP_MASK
Mask for generic dispatch of both selective fragment recovery headers.
Definition sfr.h:46
#define SIXLOWPAN_SFR_ECN
explicit congestion notification flag
Definition sfr.h:48
static void sixlowpan_sfr_clear_ecn(sixlowpan_sfr_t *hdr)
Clear the ECN flag in a 6LoWPAN recoverable fragment header.
Definition sfr.h:179
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:159
#define SIXLOWPAN_SFR_SEQ_MAX
Maximum value for sequence number.
Definition sfr.h:52
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:243
#define SIXLOWPAN_SFR_DISP_MASK
Dispatch mask for 6LoWPAN selective fragment recovery.
Definition sixlowpan.h:68
#define SIXLOWPAN_SFR_RFRAG_DISP
Dispatch for 6LoWPAN recoverable fragment.
Definition sixlowpan.h:74
#define SIXLOWPAN_SFR_ACK_DISP
Dispatch for 6LoWPAN recoverable fragment acknowledgment.
Definition sixlowpan.h:80
6LoWPAN dispatch type and helper function definitions.
Recoverable fragment (RFRAG) acknowledgment header.
Definition sfr.h:140
sixlowpan_sfr_t base
generic part
Definition sfr.h:141
BITFIELD(bitmap, SIXLOWPAN_SFR_ACK_BITMAP_SIZE)
RFRAG acknowledgment bitmap.
Recoverable fragment header.
Definition sfr.h:96
network_uint16_t offset
Fragment offset.
Definition sfr.h:132
sixlowpan_sfr_t base
generic part
Definition sfr.h:97
network_uint16_t ar_seq_fs
Acknowledgment request flag, sequence number, and fragment size.
Definition sfr.h:121
Generic type for selective fragment recovery headers.
Definition sfr.h:62
uint8_t disp_ecn
Dispatch and explicit congestion notification (ECN) flag.
Definition sfr.h:87
uint8_t tag
Datagram tag.
Definition sfr.h:88
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
uint16_t u16
16 bit representation
Definition byteorder.h:75