mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
libschc: initial import
Co-Authored-By: boortmans <bart.moons@gmail.com>
This commit is contained in:
parent
ea300c3d15
commit
566066a083
@ -99,6 +99,7 @@
|
||||
/drivers/include/periph/ptp.h @maribu
|
||||
|
||||
/pkg/cryptoauthlib/ @Einhornhool @PeterKietzmann
|
||||
/pkg/libschc/ @bartmoons @miri64
|
||||
/pkg/lua/ @jcarrano
|
||||
/pkg/lwip/ @miri64
|
||||
/pkg/gecko_sdk/ @basilfx
|
||||
|
@ -39,6 +39,7 @@ rsource "libb2/Kconfig"
|
||||
rsource "libcose/Kconfig"
|
||||
rsource "libfixmath/Kconfig"
|
||||
rsource "libhydrogen/Kconfig"
|
||||
rsource "libschc/Kconfig"
|
||||
rsource "littlefs2/Kconfig"
|
||||
rsource "lorabasics/Kconfig"
|
||||
rsource "lora-serialization/Kconfig"
|
||||
|
39
pkg/libschc/Kconfig
Normal file
39
pkg/libschc/Kconfig
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright (c) 2022 Freie Universität Berlin
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
#
|
||||
menuconfig KCONFIG_USEPKG_LIBSCHC
|
||||
bool "Configure libSCHC"
|
||||
depends on USEPKG_LIBSCHC
|
||||
help
|
||||
Configure libSCHC package via Kconfig.
|
||||
|
||||
if KCONFIG_USEPKG_LIBSCHC
|
||||
|
||||
config LIBSCHC_STATIC_MEMBUF_LEN
|
||||
int "Static memory allocation buffer length"
|
||||
default 1024
|
||||
help
|
||||
Length of the static memory buffer for fragment data allocation in reassembly buffer in
|
||||
bytes.
|
||||
|
||||
config LIBSCHC_MBUF_POOL_SIZE
|
||||
int "Maximum number of mbuf pool entries"
|
||||
default 64
|
||||
help
|
||||
Maximum number of entries in the mbuf used for fragment reassembly.
|
||||
|
||||
config LIBSCHC_MAX_RX_CONNS
|
||||
int "Maximum number of incoming connections"
|
||||
default 1
|
||||
|
||||
config LIBSCHC_MAX_MTU_LEN
|
||||
int "Maximum transfer unit of the underlying technology"
|
||||
default 242
|
||||
|
||||
config LIBSCHC_DEBUG
|
||||
bool "Enable debug output"
|
||||
|
||||
endif # KCONFIG_USEPKG_LIBSCHC
|
9
pkg/libschc/Makefile
Normal file
9
pkg/libschc/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
PKG_NAME=libschc
|
||||
PKG_URL=https://github.com/imec-idlab/libschc
|
||||
PKG_VERSION=303e9f15bf69da5a68cda76796c76de353f44a88
|
||||
PKG_LICENSE=GPL-v3.0
|
||||
|
||||
include $(RIOTBASE)/pkg/pkg.mk
|
||||
|
||||
all:
|
||||
+$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR) -f $(RIOTBASE)/Makefile.base
|
9
pkg/libschc/Makefile.dep
Normal file
9
pkg/libschc/Makefile.dep
Normal file
@ -0,0 +1,9 @@
|
||||
ifneq (,$(filter libschc_%,$(USEMODULE)))
|
||||
USEPKG += libschc
|
||||
endif
|
||||
|
||||
ifneq (,$(filter libschc,$(USEPKG)))
|
||||
USEMODULE += libschc_udpv6
|
||||
endif
|
||||
|
||||
FEATURES_BLACKLIST += arch_8bit arch_16bit arch_esp8266
|
12
pkg/libschc/Makefile.include
Normal file
12
pkg/libschc/Makefile.include
Normal file
@ -0,0 +1,12 @@
|
||||
CFLAGS += -Wno-enum-conversion
|
||||
CFLAGS += -Wno-old-style-definition
|
||||
CFLAGS += -Wno-sign-compare
|
||||
CFLAGS += -Wno-strict-prototypes
|
||||
CFLAGS += -Wno-unused-parameter
|
||||
CFLAGS += -Wno-unused-variable
|
||||
|
||||
INCLUDES += -I$(RIOTBASE)/pkg/libschc/include
|
||||
INCLUDES += -I$(PKGDIRBASE)/libschc
|
||||
|
||||
PSEUDOMODULES += libschc_coap
|
||||
PSEUDOMODULES += libschc_udpv6
|
11
pkg/libschc/doc.txt
Normal file
11
pkg/libschc/doc.txt
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @defgroup pkg_libschc libSCHC
|
||||
* @ingroup pkg
|
||||
* @brief Provides support for Static Context Header Compression and Fragmentation (SCHC)
|
||||
* @see https://github.com/imec-idlab/libschc
|
||||
* @see [RFC 8724](https://datatracker.ietf.org/doc/html/rfc8724)
|
||||
* @experimental
|
||||
*
|
||||
* libSCHC is a C implementation of Static Context Header Compression and
|
||||
Fragmentation
|
||||
*/
|
72
pkg/libschc/include/libschc/config.h
Normal file
72
pkg/libschc/include/libschc/config.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup pkg_libschc_config libSCHC compile-time configuration
|
||||
* @ingroup pkg_libschc
|
||||
* @ingroup config
|
||||
* @brief Compile-time configuration for libSCHC
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief RIOT-side compile-time configuration for libSCHC
|
||||
*
|
||||
* @author Martine S. Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef LIBSCHC_CONFIG_H
|
||||
#define LIBSCHC_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Static memory buffer length
|
||||
*
|
||||
* Length of the static memory buffer for fragmentation in bytes.
|
||||
*/
|
||||
#ifndef CONFIG_LIBSCHC_STATIC_MEMBUF_LEN
|
||||
#define CONFIG_LIBSCHC_STATIC_MEMBUF_LEN 1024
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Maximum number of mbuf pool entries
|
||||
*
|
||||
* Maximum number of entries in the mbuf used for fragment reassembly.
|
||||
*/
|
||||
#ifndef CONFIG_LIBSCHC_MBUF_POOL_SIZE
|
||||
#define CONFIG_LIBSCHC_MBUF_POOL_SIZE 64
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Maximum number of incoming connections
|
||||
*/
|
||||
#ifndef CONFIG_LIBSCHC_MAX_RX_CONNS
|
||||
#define CONFIG_LIBSCHC_MAX_RX_CONNS 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Maximum transfer unit of the underlying technology
|
||||
*/
|
||||
#ifndef CONFIG_LIBSCHC_MAX_MTU_LEN
|
||||
#define CONFIG_LIBSCHC_MAX_MTU_LEN 242
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable debug output
|
||||
*/
|
||||
#ifndef CONFIG_LIBSCHC_DEBUG
|
||||
#define CONFIG_LIBSCHC_DEBUG
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LIBSCHC_CONFIG_H */
|
||||
/** @} */
|
37
pkg/libschc/include/rules/rule_config.h
Normal file
37
pkg/libschc/include/rules/rule_config.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2018 imec IDLab
|
||||
* Copyright (C) 2022 Freie Universität Berlin
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @author boortmans <bart.moons@gmail.com>
|
||||
* @author Martine S. Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef RULES_RULE_CONFIG_H
|
||||
#define RULES_RULE_CONFIG_H
|
||||
|
||||
#include "rules.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RULES_RULE_CONFIG_H */
|
344
pkg/libschc/include/rules/rules.h
Normal file
344
pkg/libschc/include/rules/rules.h
Normal file
@ -0,0 +1,344 @@
|
||||
/*
|
||||
* Copyright (C) 2018 imec IDLab
|
||||
* Copyright (C) 2022 Freie Universität Berlin
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @author boortmans <bart.moons@gmail.com>
|
||||
* @author Martine S. Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef RULES_RULES_H
|
||||
#define RULES_RULES_H
|
||||
|
||||
#include "kernel_defines.h"
|
||||
|
||||
#include "schc.h"
|
||||
#ifdef USE_COAP
|
||||
#include "net/coap.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if USE_IP6
|
||||
static const struct schc_ipv6_rule_t ipv6_rule1 = {
|
||||
.up = 10, .down = 10, .length = 11,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ IP6_V, 0, 4, 1, BI, {6}, &mo_equal, NOTSENT },
|
||||
{ IP6_TC, 0, 8, 1, BI, {0}, &mo_ignore, NOTSENT },
|
||||
{ IP6_FL, 0, 20, 1, BI, {0, 0, 0}, &mo_ignore, NOTSENT },
|
||||
{ IP6_LEN, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH },
|
||||
{ IP6_NH, 0, 8, 1, BI, {17}, &mo_equal, NOTSENT },
|
||||
{ IP6_HL, 0, 8, 1, UP, {64}, &mo_equal, NOTSENT },
|
||||
{ IP6_HL, 0, 8, 1, DOWN, {0}, &mo_ignore, VALUESENT },
|
||||
{ IP6_DEVPRE, 0, 64, 1, BI, {
|
||||
0x20, 0x01, 0x0d, 0xb8, 0x00, 0x01, 0x00, 0x00
|
||||
}, &mo_equal, NOTSENT },
|
||||
{ IP6_DEVIID, 0, 64, 1, BI, {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
|
||||
}, &mo_equal, NOTSENT },
|
||||
{ IP6_APPPRE, 4, 64, 1, BI, {
|
||||
/* you can store as many IPs as (MAX_FIELD_LENGTH / 8) */
|
||||
0x20, 0x01, 0x0d, 0xb8, 0x00, 0x01, 0x00, 0x00,
|
||||
0x20, 0x01, 0x0d, 0xb8, 0x00, 0x02, 0x00, 0x00,
|
||||
0x20, 0x01, 0x0d, 0xb8, 0x00, 0x03, 0x00, 0x00,
|
||||
0x20, 0x01, 0x0d, 0xb8, 0x00, 0x04, 0x00, 0x00
|
||||
}, &mo_matchmap, MAPPINGSENT },
|
||||
{ IP6_APPIID, 0, 64, 1, BI, {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
|
||||
}, &mo_equal, NOTSENT },
|
||||
}
|
||||
};
|
||||
|
||||
/* link local test rule */
|
||||
static const struct schc_ipv6_rule_t ipv6_rule2 = {
|
||||
.up = 10, .down = 10, .length = 10,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ IP6_V, 0, 4, 1, BI, {6}, &mo_equal, NOTSENT },
|
||||
{ IP6_TC, 0, 8, 1, BI, {0}, &mo_ignore, NOTSENT },
|
||||
{ IP6_FL, 0, 20, 1, BI, {0, 0, 0}, &mo_ignore, NOTSENT },
|
||||
{ IP6_LEN, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH },
|
||||
{ IP6_NH, 2, 8, 1, BI, {17, 58}, &mo_matchmap, MAPPINGSENT },
|
||||
{ IP6_HL, 2, 8, 1, BI, {64, 255}, &mo_matchmap, NOTSENT },
|
||||
{ IP6_DEVPRE, 0, 64, 1, BI, {
|
||||
0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
}, &mo_equal, NOTSENT },
|
||||
{ IP6_DEVIID, 62, 64, 1, BI, {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
|
||||
}, &mo_MSB, LSB },
|
||||
{ IP6_APPPRE, 0, 64, 1, BI, {
|
||||
0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
}, &mo_equal, NOTSENT },
|
||||
{ IP6_APPIID, 62, 64, 1, BI, {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
|
||||
}, &mo_MSB, LSB },
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#if USE_UDP
|
||||
static const struct schc_udp_rule_t udp_rule1 = {
|
||||
.up = 4, .down = 4, .length = 4,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
/* set field length to 16 to indicate 16 bit values
|
||||
* MO param length to 2 to indicate 2 indices */
|
||||
{ UDP_DEV, 2, 16, 1, BI, {
|
||||
0x33, 0x16, /* 5683 or */
|
||||
0x33, 0x17 /* 5684 */
|
||||
}, &mo_matchmap, MAPPINGSENT },
|
||||
{ UDP_APP, 2, 16, 1, BI, {
|
||||
0x33, 0x16, /* 5683 or */
|
||||
0x33, 0x17 /* 5684 */
|
||||
}, &mo_matchmap, MAPPINGSENT },
|
||||
{ UDP_LEN, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH },
|
||||
{ UDP_CHK, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPCHK },
|
||||
}
|
||||
};
|
||||
|
||||
static const struct schc_udp_rule_t udp_rule2 = {
|
||||
.up = 4, .down = 4, .length = 4,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ UDP_DEV, 12, 16, 1, BI, {0x1F, 0x40}, &mo_MSB, LSB },
|
||||
{ UDP_APP, 12, 16, 1, BI, {0x1F, 0x40}, &mo_MSB, LSB },
|
||||
{ UDP_LEN, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH },
|
||||
{ UDP_CHK, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPCHK },
|
||||
}
|
||||
};
|
||||
|
||||
static const struct schc_udp_rule_t udp_rule3 = {
|
||||
.up = 4, .down = 4, .length = 4,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ UDP_DEV, 0, 16, 1, BI, {0x13, 0x89}, &mo_equal, NOTSENT },
|
||||
{ UDP_APP, 0, 16, 1, BI, {0x13, 0x88}, &mo_equal, NOTSENT },
|
||||
{ UDP_LEN, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH },
|
||||
{ UDP_CHK, 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPCHK },
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#if USE_COAP
|
||||
/* It is important to use strings, identical to the ones defined in coap.h for the options. */
|
||||
|
||||
/* GET /usage */
|
||||
static const struct schc_coap_rule_t coap_rule1 = {
|
||||
.up = 9, .down = 7, .length = 9,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ COAP_V, 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT },
|
||||
/* the MO_param_length (ML) is used to indicate the true length of the list */
|
||||
{ COAP_T, 4, 2, 1, BI, {
|
||||
COAP_TYPE_CON, COAP_TYPE_NON, COAP_TYPE_ACK, COAP_TYPE_RST
|
||||
}, &mo_matchmap, MAPPINGSENT },
|
||||
{ COAP_TKL, 0, 4, 1, BI, {4}, &mo_equal, NOTSENT },
|
||||
{ COAP_C, 0, 8, 1, BI, {COAP_METHOD_PUT}, &mo_equal, NOTSENT },
|
||||
{ COAP_MID, 0, 16, 1, BI, {0x23, 0xBB}, &mo_equal, NOTSENT },
|
||||
{ COAP_TKN, 24, 32, 1, BI, {
|
||||
0x21, 0xFA, 0x01, 0x00
|
||||
}, &mo_MSB, LSB },
|
||||
{ COAP_URIPATH, 0, 40, 1, BI, "usage", &mo_equal, NOTSENT },
|
||||
{ COAP_NORESP, 0, 8, 1, BI, {0x1A}, &mo_equal, NOTSENT },
|
||||
{ COAP_PAYLOAD, 0, 8, 1, BI, {0xFF}, &mo_equal, NOTSENT }
|
||||
}
|
||||
};
|
||||
|
||||
/* POST temperature value */
|
||||
static const struct schc_coap_rule_t coap_rule2 = {
|
||||
.up = 7, .down = 7, .length = 10,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ COAP_V, 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT },
|
||||
{ COAP_T, 0, 2, 1, BI, {0}, &mo_ignore, VALUESENT },
|
||||
{ COAP_TKL, 0, 4, 1, BI, {4}, &mo_equal, NOTSENT },
|
||||
{ COAP_C, 0, 8, 1, UP, {COAP_CODE_CONTENT}, &mo_equal, NOTSENT },
|
||||
{ COAP_C, 0, 8, 1, DOWN, {COAP_METHOD_GET}, &mo_equal, NOTSENT },
|
||||
/* match the first 12 bits */
|
||||
{ COAP_MID, 12, 16, 1, UP, {0x23, 0xBB}, &mo_MSB, LSB },
|
||||
{ COAP_MID, 0, 16, 1, DOWN, {0, 0}, &mo_ignore, VALUESENT },
|
||||
{ COAP_TKN, 0, 32, 1, BI, {0, 0, 0, 0}, &mo_ignore, VALUESENT },
|
||||
{ COAP_URIPATH, 0, 32, 1, DOWN, "temp", &mo_equal, NOTSENT },
|
||||
/* respond with CONTENT */
|
||||
{ COAP_PAYLOAD, 0, 8, 1, UP, {0xFF}, &mo_equal, NOTSENT }
|
||||
}
|
||||
};
|
||||
|
||||
static const struct schc_coap_rule_t coap_rule3 = {
|
||||
.up = 1, .down = 1, .length = 1,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ COAP_V, 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT },
|
||||
}
|
||||
};
|
||||
|
||||
static const struct schc_coap_rule_t coap_rule4 = {
|
||||
.up = 12, .down = 12, .length = 12,
|
||||
{
|
||||
/* field, ML, len, pos, dir, val, MO, CDA */
|
||||
{ COAP_V, 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT },
|
||||
{ COAP_T, 0, 2, 1, BI, {COAP_TYPE_CON}, &mo_equal, NOTSENT },
|
||||
{ COAP_TKL, 0, 4, 1, BI, {8}, &mo_equal, NOTSENT },
|
||||
{ COAP_C, 0, 8, 1, BI, {COAP_METHOD_POST}, &mo_equal, NOTSENT },
|
||||
{ COAP_MID, 0, 16, 1, BI, {0x23, 0xBB}, &mo_ignore, VALUESENT },
|
||||
/* match the 24 first bits, send the last 8 */
|
||||
{ COAP_TKN, 24, 32, 1, BI, {
|
||||
0x21, 0xFA, 0x01, 0x00
|
||||
}, &mo_MSB, LSB },
|
||||
{ COAP_URIPATH, 0, 16, 1, BI, "rd", &mo_equal, NOTSENT },
|
||||
{ COAP_CONTENTF, 0, 8, 1, BI, {0x28}, &mo_equal, NOTSENT },
|
||||
{ COAP_URIQUERY, 0, 72, 1, BI, "lwm2m=1.0", &mo_equal, NOTSENT },
|
||||
{ COAP_URIQUERY, 0, 88, 1, BI, "ep=magician", &mo_equal, NOTSENT },
|
||||
{ COAP_URIQUERY, 0, 48, 1, BI, "lt=121", &mo_equal, NOTSENT },
|
||||
/* respond with CONTENT */
|
||||
{ COAP_PAYLOAD, 0, 8, 1, BI, {0xff}, &mo_equal, NOTSENT }
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
static const struct schc_compression_rule_t comp_rule_1 = {
|
||||
.rule_id = 0x01,
|
||||
.rule_id_size_bits = 8U,
|
||||
#if USE_IP6
|
||||
&ipv6_rule1,
|
||||
#endif
|
||||
#if USE_UDP
|
||||
&udp_rule1,
|
||||
#endif
|
||||
#if USE_COAP
|
||||
&coap_rule1,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct schc_compression_rule_t comp_rule_2 = {
|
||||
.rule_id = 0x02,
|
||||
.rule_id_size_bits = 8U,
|
||||
#if USE_IP6
|
||||
&ipv6_rule1,
|
||||
#endif
|
||||
#if USE_UDP
|
||||
&udp_rule3,
|
||||
#endif
|
||||
#if USE_COAP
|
||||
&coap_rule2,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct schc_compression_rule_t comp_rule_3 = {
|
||||
.rule_id = 0x03,
|
||||
.rule_id_size_bits = 8U,
|
||||
#if USE_IP6
|
||||
&ipv6_rule2,
|
||||
#endif
|
||||
#if USE_UDP
|
||||
&udp_rule2,
|
||||
#endif
|
||||
#if USE_COAP
|
||||
&coap_rule3,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct schc_compression_rule_t comp_rule_4 = {
|
||||
.rule_id = 0x04,
|
||||
.rule_id_size_bits = 8U,
|
||||
#if USE_IP6
|
||||
&ipv6_rule2,
|
||||
#endif
|
||||
#if USE_UDP
|
||||
&udp_rule2,
|
||||
#endif
|
||||
#if USE_COAP
|
||||
&coap_rule4,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct schc_fragmentation_rule_t frag_rule_21 = {
|
||||
.rule_id = 21,
|
||||
.rule_id_size_bits = 8,
|
||||
.mode = NO_ACK,
|
||||
.dir = BI,
|
||||
.FCN_SIZE = 1, /* FCN size */
|
||||
.MAX_WND_FCN = 0, /* Maximum fragments per window */
|
||||
.WINDOW_SIZE = 0, /* Window size */
|
||||
.DTAG_SIZE = 0, /* DTAG size */
|
||||
};
|
||||
|
||||
static const struct schc_fragmentation_rule_t frag_rule_22 = {
|
||||
.rule_id = 22,
|
||||
.rule_id_size_bits = 8,
|
||||
.mode = ACK_ON_ERROR,
|
||||
.dir = BI,
|
||||
.FCN_SIZE = 3, /* FCN size */
|
||||
.MAX_WND_FCN = 6, /* Maximum fragments per window */
|
||||
.WINDOW_SIZE = 1, /* Window size */
|
||||
.DTAG_SIZE = 0, /* DTAG size */
|
||||
};
|
||||
|
||||
static const struct schc_fragmentation_rule_t frag_rule_23 = {
|
||||
.rule_id = 23,
|
||||
.rule_id_size_bits = 8,
|
||||
.mode = ACK_ALWAYS,
|
||||
.dir = BI,
|
||||
.FCN_SIZE = 3, /* FCN size */
|
||||
.MAX_WND_FCN = 6, /* Maximum fragments per window */
|
||||
.WINDOW_SIZE = 1, /* Window size */
|
||||
.DTAG_SIZE = 0, /* DTAG size */
|
||||
};
|
||||
|
||||
/* save compression rules in flash */
|
||||
static const struct schc_compression_rule_t* node1_compression_rules[] = {
|
||||
&comp_rule_1, &comp_rule_2, &comp_rule_3, &comp_rule_4
|
||||
};
|
||||
|
||||
/* save fragmentation rules in flash */
|
||||
static const struct schc_fragmentation_rule_t* node1_fragmentation_rules[] = {
|
||||
&frag_rule_21, &frag_rule_22, &frag_rule_23,
|
||||
};
|
||||
|
||||
/* rules for a particular device */
|
||||
static const struct schc_device node1 = {
|
||||
.device_id = 1,
|
||||
.uncomp_rule_id = 0,
|
||||
.uncomp_rule_id_size_bits = 8,
|
||||
.compression_rule_count = ARRAY_SIZE(node1_compression_rules),
|
||||
.compression_context = &node1_compression_rules,
|
||||
.fragmentation_rule_count = ARRAY_SIZE(node1_fragmentation_rules),
|
||||
.fragmentation_context = &node1_fragmentation_rules
|
||||
};
|
||||
static const struct schc_device node2 = {
|
||||
.device_id = 2,
|
||||
.uncomp_rule_id = 0,
|
||||
.uncomp_rule_id_size_bits = 8,
|
||||
.compression_rule_count = ARRAY_SIZE(node1_compression_rules),
|
||||
.compression_context = &node1_compression_rules,
|
||||
.fragmentation_rule_count = ARRAY_SIZE(node1_fragmentation_rules),
|
||||
.fragmentation_context = &node1_fragmentation_rules
|
||||
};
|
||||
|
||||
/* server keeps track of multiple devices: add devices to device list */
|
||||
static const struct schc_device* devices[] = { &node1, &node2 };
|
||||
|
||||
#define DEVICE_COUNT ((int)ARRAY_SIZE(devices))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RULES_RULES_H */
|
128
pkg/libschc/include/schc_config.h
Normal file
128
pkg/libschc/include/schc_config.h
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2018 imec IDLab
|
||||
* Copyright (C) 2022 Freie Universität Berlin
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup pkg_libschc_config
|
||||
*
|
||||
* @internal
|
||||
* @name libSCHC-side compile-time config for libSCHC
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* Usually this file and its macros need not to be touched. Use the compile-time
|
||||
* configuration macros in @ref libschc_config.h to configure @ref pkg_libschc.
|
||||
*
|
||||
* @author boortmans <bart.moons@gmail.com>
|
||||
* @author Martine S. Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef SCHC_CONFIG_H
|
||||
#define SCHC_CONFIG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "kernel_defines.h"
|
||||
#include "libschc/config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CLICK 0
|
||||
|
||||
#define DYNAMIC_MEMORY 0
|
||||
#define STATIC_MEMORY_BUFFER_LENGTH CONFIG_LIBSCHC_STATIC_MEMBUF_LEN
|
||||
|
||||
#define SCHC_CONF_RX_CONNS CONFIG_LIBSCHC_MAX_RX_CONNS
|
||||
#define SCHC_CONF_MBUF_POOL_LEN CONFIG_LIBSCHC_MBUF_POOL_SIZE
|
||||
|
||||
#if IS_USED(MODULE_LIBSCHC_COAP)
|
||||
#define USE_COAP 1
|
||||
#else
|
||||
#define USE_COAP 0
|
||||
#endif
|
||||
|
||||
#if IS_USED(MODULE_LIBSCHC_UDPV6)
|
||||
#define USE_IP6_UDP 1
|
||||
#else
|
||||
#define USE_IP6_UDP 0
|
||||
#endif
|
||||
|
||||
/* the maximum length of a single header field
|
||||
* e.g. you can use 4 ipv6 source iid addresses with match-mapping */
|
||||
#define MAX_FIELD_LENGTH 32
|
||||
|
||||
/* maximum number of header fields present in a rule (vertical, top to bottom) */
|
||||
#define IP6_FIELDS 14
|
||||
#define UDP_FIELDS 4
|
||||
#define COAP_FIELDS 16
|
||||
|
||||
#define MAX_HEADER_LENGTH 256
|
||||
|
||||
#define MAX_COAP_HEADER_LENGTH 64
|
||||
#define MAX_PAYLOAD_LENGTH 256
|
||||
#define MAX_COAP_MSG_SIZE MAX_COAP_HEADER_LENGTH + MAX_PAYLOAD_LENGTH
|
||||
|
||||
/* the maximum transfer unit of the underlying technology */
|
||||
#define MAX_MTU_LENGTH CONFIG_LIBSCHC_MAX_MTU_LEN
|
||||
|
||||
/* the maximum number of tokens inside a JSON structure */
|
||||
#define JSON_TOKENS 16
|
||||
|
||||
#define RULE_SIZE_BITS 8
|
||||
|
||||
#if IS_ACTIVE(CONFIG_LIBSCHC_DEBUG)
|
||||
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_PRINTF(...)
|
||||
#endif
|
||||
|
||||
/* the number of ack attempts */
|
||||
#define MAX_ACK_REQUESTS 3
|
||||
|
||||
/* the number of FCN bits */
|
||||
#if IS_USED(MODULE_LORA)
|
||||
#define FCN_SIZE_BITS 6
|
||||
#else
|
||||
#define FCN_SIZE_BITS 3
|
||||
#endif
|
||||
|
||||
/* the number of DTAG bits */
|
||||
#define DTAG_SIZE_BITS 0
|
||||
|
||||
/* the number of bytes the MIC consists of */
|
||||
#define MIC_SIZE_BYTES 4
|
||||
|
||||
/* the length of the bitmap */
|
||||
#if IS_USED(MODULE_LORA)
|
||||
#define BITMAP_SIZE_BYTES 8 /* pow(2, FCN_SIZE_BITS) / 8 */
|
||||
#else
|
||||
#define BITMAP_SIZE_BYTES 2 /* pow(2, FCN_SIZE_BITS) / 8 */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SCHC_CONFIG_H */
|
||||
/**
|
||||
* @internal
|
||||
* @}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user