Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: Add stdio_coap #19289

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 85 additions & 10 deletions examples/rust-gcoap/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions makefiles/cargo-targets.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ endif
ifneq (,$(filter shell_democommands,$(USEMODULE)))
CARGO_OPTIONS += --features rust_riotmodules/riot-module-shell-democommands
endif
ifneq (,$(filter stdio_coap,$(USEMODULE)))
CARGO_OPTIONS += --features rust_riotmodules/riot-module-stdio-coap
endif

# This is duplicating the compile-commands rule because unlike in the use case
# when a $(RIOTBASE)/compile_commands.json is built, we *want* this to be
Expand Down
18 changes: 18 additions & 0 deletions makefiles/stdio.inc.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
STDIO_MODULES = \
slipdev_stdio \
stdio_cdc_acm \
stdio_coap \
stdio_ethos \
stdio_native \
stdio_nimble \
Expand All @@ -25,6 +26,23 @@ ifneq (,$(filter stdio_cdc_acm,$(USEMODULE)))
USEMODULE += stdio_available
endif

ifneq (,$(filter stdio_coap,$(USEMODULE)))
# FIXME: Does this obsolete the stdio_coap Makefile.{dep,include}?
USEMODULE += rust_riotmodules
PSEUDOMODULES += stdio_coap

# FIXME: Whose responsibility is it to include these?

# either
USEMODULE += netdev_default
#USEMODULE += usbus_cdc_ecm

USEMODULE += gnrc_sock_udp
USEMODULE += gcoap
USEMODULE += gnrc_ipv6_default
USEMODULE += auto_init_gnrc_netif
endif

ifneq (,$(filter stdio_tinyusb_cdc_acm,$(USEMODULE)))
USEPKG += tinyusb
endif
Expand Down
1 change: 1 addition & 0 deletions pkg/tinydtls/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ config DTLS_CONTEXT_MAX

config DTLS_PEER_MAX
int "Max number of peers"
default 2 if KCONFIG_USEMODULE_GCOAP_DTLS
default 1
help
The maximum number of DTLS peers.
Expand Down
25 changes: 25 additions & 0 deletions pkg/tinydtls/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,34 @@ endif
PEER_MAX := $(or $(CONFIG_DTLS_PEER_MAX),$(patsubst -DCONFIG_DTLS_PEER_MAX=%,%,$(filter -DCONFIG_DTLS_PEER_MAX=%,$(CFLAGS))))
ifneq (,$(PEER_MAX))
CFLAGS += -DDTLS_PEER_MAX=$(PEER_MAX)
else ifneq (,$(filter gcoap_dtls,$(USEMODULE)))
# The default value in sys/include/net/dtls.h for CONFIG_DTLS_PEER_MAX is 2
# when gcoap_dtls is active, otherwise 1. As the default in tinydtls is 1,
# we need to set it explicitly if the dtls.h default value deviates from
# the tinydtls default.
CFLAGS += -DDTLS_PEER_MAX=2
endif

HANDSHAKE_MAX := $(or $(CONFIG_DTLS_HANDSHAKE_MAX),$(patsubst -DCONFIG_DTLS_HANDSHAKE_MAX=%,%,$(filter -DCONFIG_DTLS_HANDSHAKE_MAX=%,$(CFLAGS))))
ifneq (,$(HANDSHAKE_MAX))
CFLAGS += -DDTLS_HANDSHAKE_MAX=$(HANDSHAKE_MAX)
endif

ifneq (,$(filter gcoap,$(USEMODULE)))
# Configuring the buffer large enough that a full Gcoap packet can be
# encrypted or decrypted.

# This is the default in gcoap.h, which we don't have access to, so it is copied over.
CONFIG_GCOAP_PDU_BUF_SIZE := $(or $(CONFIG_GCOAP_PDU_BUF_SIZE),128)

# If there were another way to set up DTLS_MAX_BUF, we'd need to set the
# maximum of these here.
#
# 29 bytes are the overhead measured with Wireshark on packets exchanged in
# default configuration; adding some to be safe against variable size fields.
CFLAGS += "-DDTLS_MAX_BUF=($(CONFIG_GCOAP_PDU_BUF_SIZE) + 36)"
endif

# TinyDTLS emits several messages during connection establishment at the info
# level; this is way more verbose than common in RIOT.
CFLAGS += -DLOG_LEVEL=LOG_WARNING
6 changes: 6 additions & 0 deletions sys/include/net/dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#ifndef NET_DTLS_H
#define NET_DTLS_H

#include "modules.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -44,8 +46,12 @@ extern "C" {
* @brief The maximum number DTLS peers (i.e. sessions)
*/
#ifndef CONFIG_DTLS_PEER_MAX
#if IS_USED(MODULE_GCOAP_DTLS)
#define CONFIG_DTLS_PEER_MAX (2)
#else
#define CONFIG_DTLS_PEER_MAX (1)
#endif
#endif

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions sys/rust_riotmodules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ publish = false

riot-module-lsm303agr = { path = "../../drivers/lsm303agr", optional = true }
riot-module-shell-democommands = { path = "../../sys/shell/democommands", optional = true }
riot-module-stdio-coap = { path = "../../sys/stdio_coap", optional = true }
3 changes: 3 additions & 0 deletions sys/rust_riotmodules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ pub use riot_module_lsm303agr as lsm303agr;

#[cfg(feature = "riot-module-shell-democommands")]
pub use riot_module_shell_democommands as democommands;

#[cfg(feature = "riot-module-stdio-coap")]
pub use riot_module_stdio_coap as stdio_coap;
3 changes: 1 addition & 2 deletions sys/rust_riotmodules_standalone/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions sys/stdio_coap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "riot-module-stdio-coap"
version = "0.1.0"
edition = "2021"

authors = ["Christian Amsüss <chrysn@fsfe.org>"]
license = "LGPL-2.1-only"

# Shipped with RIOT-OS; this has no external API that would make
# sense to consume in any context than from within RIOT
publish = false

[dependencies]
coap-scroll-ring-server = "0.1"
riot-wrappers = { version = "^0.8", features = [ "with_coap_handler" ] } # esp. the git version: fixes mutex bug
riot-sys = "0.7"
scroll-ring = "0.1.1"
static_cell = "1"
# for stdin
coap-handler = "0.1"
coap-message = "0.2"
coap-numbers = "0.2"
ringbuf = { version = "0.3.2", default-features = false }
coap-handler-implementations = { git = "https://gitlab.com/chrysn/coap-handler-implementations", features = [ "leaky_names" ] }
Loading