-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,700 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += event | ||
USEMODULE += event_timeout_ztimer | ||
USEMODULE += event_thread | ||
USEMODULE += fmt | ||
USEMODULE += ipv6_addr | ||
USEMODULE += od | ||
USEMODULE += shell | ||
USEMODULE += ztimer_msec | ||
|
||
USEPKG += libschc | ||
USEMODULE += libschc_coap | ||
|
||
# add custom rules | ||
INCLUDES += -I$(CURDIR)/include | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @internal | ||
* @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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,330 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @internal | ||
* @author Martine S. Lenders <m.lenders@fu-berlin.de> | ||
*/ | ||
#ifndef RULES_RULES_H | ||
#define RULES_RULES_H | ||
|
||
#include "schc.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if USE_IP6 | ||
static const struct schc_ipv6_rule_t ipv6_rule1 = { | ||
.rule_id = 1, .up = 10, .down = 10, .length = 10, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "version", 0, 4, 1, BI, {6}, &mo_equal, NOTSENT }, | ||
{ "traffic class", 0, 8, 1, BI, {0}, &mo_ignore, NOTSENT }, | ||
{ "flow label", 0, 20, 1, BI, {0, 0, 0}, &mo_ignore, NOTSENT }, | ||
{ "length", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH }, | ||
{ "next header", 3, 8, 1, BI, {6, 17, 58}, &mo_matchmap, MAPPINGSENT }, | ||
{ "hop limit", 0, 8, 1, BI, {64}, &mo_ignore, NOTSENT }, | ||
{ "src prefix", 4, 64, 1, BI, { | ||
/* you can store as many IPs as (MAX_FIELD_LENGTH / 8) */ | ||
0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0xBB, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0xDD, 0xDD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_matchmap, MAPPINGSENT }, | ||
{ "src iid", 0, 64, 1, BI, { | ||
0x8C, 0x0D, 0x14, 0xFF, 0xFE, 0x1f, 0xE1, 0xD8 | ||
}, &mo_equal, NOTSENT }, | ||
{ "dest prefix", 0, 64, 1, BI, { | ||
0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_equal, NOTSENT }, | ||
/* match the 60 first bits, send the last 4 */ | ||
{ "dest iid", 60, 64, 1, BI, { | ||
0xE8, 0x12, 0xE4, 0xFF, 0xFE, 0xDD, 0x4F, 0xEE | ||
}, &mo_MSB, LSB }, | ||
} | ||
}; | ||
|
||
/* link local test rule */ | ||
static const struct schc_ipv6_rule_t ipv6_rule2 = { | ||
.rule_id = 1, .up = 10, .down = 10, .length = 10, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "version", 0, 4, 1, BI, {6}, &mo_equal, NOTSENT }, | ||
{ "traffic class", 0, 8, 1, BI, {0}, &mo_equal, NOTSENT }, | ||
{ "flow label", 0, 20, 1, BI, {0, 0, 0}, &mo_ignore, NOTSENT }, | ||
{ "length", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH }, | ||
{ "next header", 0, 8, 1, BI, {17}, &mo_equal, NOTSENT }, | ||
{ "hop limit", 0, 8, 1, BI, {64}, &mo_ignore, NOTSENT }, | ||
{ "src prefix", 0, 64, 1, BI, { | ||
0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_equal, NOTSENT }, | ||
{ "src iid", 0, 64, 1, BI, { | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_ignore, NOTSENT }, | ||
{ "dest prefix", 0, 64, 1, BI, { | ||
0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_equal, NOTSENT }, | ||
{ "dest iid", 0, 64, 1, BI, { | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_ignore, NOTSENT }, | ||
} | ||
}; | ||
|
||
static const struct schc_ipv6_rule_t ipv6_rule3 = { | ||
.rule_id = 3, .up = 10, .down = 10, .length = 10, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "version", 0, 4, 1, BI, {6}, &mo_equal, VALUESENT }, | ||
{ "traffic class", 0, 8, 1, BI, {0}, &mo_ignore, NOTSENT }, | ||
{ "flow label", 0, 20, 1, BI, {0, 0, 0}, &mo_ignore, NOTSENT }, | ||
{ "length", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH }, | ||
{ "next header", 0, 8, 1, BI, {17}, &mo_equal, NOTSENT }, | ||
{ "hop limit", 0, 8, 1, BI, {64}, &mo_ignore, NOTSENT }, | ||
{ "src prefix", 0, 64, 1, BI, { | ||
0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_equal, NOTSENT }, | ||
{ "src iid", 0, 64, 1, BI, { | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 | ||
}, &mo_equal, NOTSENT }, | ||
{ "dest prefix", 0, 64, 1, BI, { | ||
0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_equal, NOTSENT }, | ||
{ "dest iid", 60, 64, 1, BI, { | ||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}, &mo_MSB, LSB }, | ||
} | ||
}; | ||
#endif | ||
|
||
#if USE_UDP | ||
static const struct schc_udp_rule_t udp_rule1 = { | ||
.rule_id = 1, .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 */ | ||
{ "src port", 2, 16, 1, BI, { | ||
0x33, 0x16, 0x33, 0x17 /* 5683 or 5684 */ | ||
}, &mo_matchmap, MAPPINGSENT }, | ||
{ "dest port", 2, 16, 1, BI, { | ||
0x33, 0x16, 0x33, 0x17 /* 5683 or 5684 */ | ||
}, &mo_matchmap, MAPPINGSENT }, | ||
{ "length", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH }, | ||
{ "checksum", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPCHK }, | ||
} | ||
}; | ||
|
||
static const struct schc_udp_rule_t udp_rule2 = { | ||
.rule_id = 2, .up = 4, .down = 4, .length = 4, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "src port", 12, 16, 1, BI, {0x1F, 0x40}, &mo_MSB, LSB }, | ||
{ "dest port", 12, 16, 1, BI, {0x1F, 0x40}, &mo_MSB, LSB }, | ||
{ "length", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH }, | ||
{ "checksum", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPCHK }, | ||
} | ||
}; | ||
|
||
static const struct schc_udp_rule_t udp_rule3 = { | ||
.rule_id = 3, .up = 4, .down = 4, .length = 4, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "src port", 0, 16, 1, BI, {0x13, 0x89}, &mo_equal, NOTSENT }, | ||
{ "dest port", 0, 16, 1, BI, {0x13, 0x88}, &mo_equal, NOTSENT }, | ||
{ "length", 0, 16, 1, BI, {0, 0}, &mo_ignore, COMPLENGTH }, | ||
{ "checksum", 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 = { | ||
.rule_id = 1, .up = 9, .down = 7, .length = 9, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "version", 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT }, | ||
{ "type", 4, 2, 1, BI, { | ||
CT_CON, CT_NON, CT_ACK, CT_RST | ||
}, &mo_matchmap, MAPPINGSENT }, | ||
{ "token length", 0, 4, 1, BI, {4}, &mo_equal, NOTSENT }, | ||
{ "code", 0, 8, 1, BI, {CC_PUT}, &mo_equal, NOTSENT }, | ||
{ "message ID", 0, 16, 1, BI, {0x23, 0xBB}, &mo_equal, NOTSENT }, | ||
{ "token", 24, 32, 1, BI, { | ||
0x21, 0xFA, 0x01, 0x00 | ||
}, &mo_MSB, LSB }, | ||
{ "uri-path", 0, 40, 1, BI, "usage", &mo_equal, NOTSENT }, | ||
{ "no-response", 0, 8, 1, BI, {0x1A}, &mo_equal, NOTSENT }, | ||
{ "payload marker", 0, 8, 1, BI, {0xFF}, &mo_equal, NOTSENT } | ||
} | ||
}; | ||
|
||
/* POST temperature value */ | ||
static const struct schc_coap_rule_t coap_rule2 = { | ||
.rule_id = 2, .up = 8, .down = 8, .length = 10, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "version", 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT }, | ||
/* the MO_param_length (ML) is used to indicate the true length of the list */ | ||
{ "type", 3, 2, 1, BI, { | ||
CT_CON, CT_ACK, CT_NON | ||
}, &mo_matchmap, MAPPINGSENT }, | ||
{ "token length", 0, 4, 1, BI, {4}, &mo_equal, NOTSENT }, | ||
{ "code", 0, 4, 1, UP, {CC_CONTENT}, &mo_equal, NOTSENT }, | ||
{ "code", 0, 8, 1, DOWN, {CC_GET}, &mo_equal, NOTSENT }, | ||
{ "message ID", 12, 16, 1, UP, {0x23, 0xBB}, &mo_MSB, LSB }, | ||
/* match the first 12 bits */ | ||
{ "message ID", 12, 16, 1, DOWN, {0x7A, 0x10}, &mo_MSB, LSB }, | ||
/* GET sensor value */ | ||
{ "token", 0, 32, 1, BI, {0, 0, 0, 0}, &mo_ignore, VALUESENT }, | ||
{ "uri-path", 4, 0, 2, BI, | ||
"[\"temp\",\"humi\",\"batt\",\"r\"]\0", &mo_matchmap, MAPPINGSENT }, | ||
/* respond with CONTENT */ | ||
{ "payload marker", 0, 8, 1, BI, {255}, &mo_equal, NOTSENT } | ||
} | ||
}; | ||
|
||
static const struct schc_coap_rule_t coap_rule3 = { | ||
.rule_id = 3, .up = 1, .down = 1, .length = 1, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "version", 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT }, | ||
} | ||
}; | ||
|
||
static const struct schc_coap_rule_t coap_rule4 = { | ||
.rule_id = 4, .up = 12, .down = 12, .length = 12, | ||
{ | ||
/* field, ML, len, pos, dir, val, MO, CDA */ | ||
{ "version", 0, 2, 1, BI, {COAP_V1}, &mo_equal, NOTSENT }, | ||
{ "type", 0, 2, 1, BI, {CT_CON}, &mo_equal, NOTSENT }, | ||
{ "token length", 0, 4, 1, BI, {8}, &mo_equal, NOTSENT }, | ||
{ "code", 0, 8, 1, BI, {CC_POST}, &mo_equal, NOTSENT }, | ||
{ "message ID", 0, 16, 1, BI, {0x23, 0xBB}, &mo_ignore, VALUESENT }, | ||
/* match the 24 first bits, send the last 8 */ | ||
{ "token", 24, 32, 1, BI, { | ||
0x21, 0xFA, 0x01, 0x00 | ||
}, &mo_MSB, LSB }, | ||
{ "uri-path", 0, 16, 1, BI, "rd", &mo_equal, NOTSENT }, | ||
{ "content-format", 0, 8, 1, BI, {0x28}, &mo_equal, NOTSENT }, | ||
{ "uri-query", 0, 72, 1, BI, "lwm2m=1.0", &mo_equal, NOTSENT }, | ||
{ "uri-query", 0, 88, 1, BI, "ep=magician", &mo_equal, NOTSENT }, | ||
{ "uri-query", 0, 48, 1, BI, "lt=121", &mo_equal, NOTSENT }, | ||
/* respond with CONTENT */ | ||
{ "payload marker", 0, 8, 1, BI, {255}, &mo_equal, NOTSENT } | ||
} | ||
}; | ||
#endif | ||
|
||
const struct schc_compression_rule_t comp_rule_1 = { | ||
#if USE_IP6 | ||
&ipv6_rule1, | ||
#endif | ||
#if USE_UDP | ||
&udp_rule1, | ||
#endif | ||
#if USE_COAP | ||
&coap_rule1, | ||
#endif | ||
}; | ||
|
||
const struct schc_compression_rule_t comp_rule_2 = { | ||
#if USE_IP6 | ||
&ipv6_rule1, | ||
#endif | ||
#if USE_UDP | ||
&udp_rule2, | ||
#endif | ||
#if USE_COAP | ||
&coap_rule2, | ||
#endif | ||
}; | ||
|
||
const struct schc_compression_rule_t comp_rule_3 = { | ||
#if USE_IP6 | ||
&ipv6_rule2, | ||
#endif | ||
#if USE_UDP | ||
&udp_rule2, | ||
#endif | ||
#if USE_COAP | ||
&coap_rule4, | ||
#endif | ||
}; | ||
|
||
const struct schc_compression_rule_t comp_rule_4 = { | ||
#if USE_IP6 | ||
&ipv6_rule3, | ||
#endif | ||
#if USE_UDP | ||
&udp_rule2, | ||
#endif | ||
#if USE_COAP | ||
&coap_rule1, | ||
#endif | ||
}; | ||
|
||
const struct schc_compression_rule_t comp_rule_5 = { | ||
#if USE_IP6 | ||
&ipv6_rule2, | ||
#endif | ||
#if USE_UDP | ||
&udp_rule2, | ||
#endif | ||
#if USE_COAP | ||
&coap_rule3, | ||
#endif | ||
}; | ||
|
||
const struct schc_rule_t schc_rule_1 = { { 0x01 }, &comp_rule_1, NOT_FRAGMENTED, 0, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_2 = { { 0x02 }, &comp_rule_1, NO_ACK, 1, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_3 = { { 0x03 }, &comp_rule_1, ACK_ON_ERROR, 3, 6, 1, 0 }; | ||
const struct schc_rule_t schc_rule_4 = { { 0x04 }, &comp_rule_1, ACK_ALWAYS, 3, 6, 1, 0 }; | ||
|
||
const struct schc_rule_t schc_rule_5 = { { 0x05 }, &comp_rule_2, NOT_FRAGMENTED, 0, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_6 = { { 0x06 }, &comp_rule_2, NO_ACK, 1, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_7 = { { 0x07 }, &comp_rule_2, ACK_ON_ERROR, 3, 6, 1, 0 }; | ||
const struct schc_rule_t schc_rule_8 = { { 0x08 }, &comp_rule_2, ACK_ALWAYS, 3, 6, 1, 0 }; | ||
|
||
const struct schc_rule_t schc_rule_9 = { { 0x09 }, &comp_rule_3, NOT_FRAGMENTED, 0, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_10 = { { 0x0A }, &comp_rule_3, NO_ACK, 1, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_11 = { { 0x0B }, &comp_rule_3, ACK_ON_ERROR, 3, 6, 1, 0 }; | ||
const struct schc_rule_t schc_rule_12 = { { 0x0C }, &comp_rule_3, ACK_ALWAYS, 3, 6, 1, 0 }; | ||
|
||
const struct schc_rule_t schc_rule_13 = { { 0x0D }, &comp_rule_5, NOT_FRAGMENTED, 0, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_14 = { { 0x0E }, &comp_rule_5, NO_ACK, 1, 0, 0, 0 }; | ||
const struct schc_rule_t schc_rule_15 = { { 0x0F }, &comp_rule_5, ACK_ALWAYS, 3, 6, 1, 0 }; | ||
const struct schc_rule_t schc_rule_16 = { { 0x10 }, &comp_rule_5, ACK_ON_ERROR, 3, 6, 1, 0 }; | ||
|
||
const uint8_t UNCOMPRESSED_ID[RULE_SIZE_BYTES] = { 0x00 }; | ||
|
||
/* save rules in flash */ | ||
const struct schc_rule_t* node1_schc_rules[] = { | ||
&schc_rule_1, &schc_rule_2, &schc_rule_3, &schc_rule_4, | ||
&schc_rule_5, &schc_rule_6, &schc_rule_7, &schc_rule_8, | ||
&schc_rule_9, &schc_rule_10, &schc_rule_11, &schc_rule_12, | ||
&schc_rule_13, &schc_rule_14, &schc_rule_15, &schc_rule_16 | ||
}; | ||
|
||
/* rules for a particular device */ | ||
const struct schc_device node1 = { 1, 16, &node1_schc_rules }; | ||
const struct schc_device node2 = { 2, 16, &node1_schc_rules }; | ||
|
||
/* server keeps track of multiple devices: add devices to device list */ | ||
const struct schc_device* devices[] = { &node1, &node2 }; | ||
|
||
#define DEVICE_COUNT ((int)(sizeof(devices) / sizeof(devices[0]))) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* RULES_RULES_H */ |
Oops, something went wrong.