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

pkg/libcsp: add sock_udp [demonstrator] #18010

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

fjmolinas
Copy link
Contributor

Contribution description

For another project, I wanted to use CoAP and many applications depending on it on top of a non-IP stack (libCSP). Since all those are basically using the sock api, and sock is IP based, I implemented sock_udp ep that basically just ignores everything in the IP address but the last hex part, This is just meant to be able to have drop-in network stack replacements, and the same usage through the present CLI tools, but nothing related to IP addressing is actually used. I'm tagging it as demonstrator as this feels a bit like a hack, but might be useful for others.

Testing procedure

There are some incomplete unittests, not sure it's worth the effort right now to pursue further.

Use gcoap as a CoAP server or a as a CoAP client, to do it must be patched a little:

diff --git a/examples/gcoap/Makefile b/examples/gcoap/Makefile
index bcb3c4731e..2b622d0e86 100644
--- a/examples/gcoap/Makefile
+++ b/examples/gcoap/Makefile
@@ -9,25 +9,23 @@ BOARD ?= native
 # This has to be the absolute path to the RIOT base directory:
 RIOTBASE ?= $(CURDIR)/../..

-# Include packages that pull up and auto-init the link layer.
-# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
-USEMODULE += netdev_default
-
-# use GNRC by default
-LWIP ?= 0
-
-ifeq (0,$(LWIP))
-  USEMODULE += auto_init_gnrc_netif
-  # Specify the mandatory networking modules
-  USEMODULE += gnrc_ipv6_default
-  # Additional networking modules that can be dropped if not needed
-  USEMODULE += gnrc_icmpv6_echo
-else
-  USEMODULE += lwip_ipv6
-  USEMODULE += lwip_netdev
-endif
-
+# Use CSP network stack
+USEPKG += libcsp
+# libCSP ports must be <64, so arbitrarily pick port 2 as the default
+# CoAP port instead of 5683
+COAP_PORT ?= 2
+CFLAGS += -DCOAP_PORT=$(COAP_PORT)
+CFLAGS += -DCONFIG_GCOAP_PORT=$(COAP_PORT)
+# Include gcoap
 USEMODULE += gcoap
+ifneq (,$(filter libcsp,$(USEPKG)))
+  ifeq ($(BOARD),native)
+    FEATURES_REQUIRED += periph_can
+  else
+    # Default to MCP2515 for non native BOARDs to cover larger BOARD scpectrum
+    USEMODULE += mcp2515
+  endif
+endif

 # Required by gcoap example
 USEMODULE += od

The gcoap examples in master expects IPv6 addressing. But CSP is used here which does not use or support
IP. To work around this, destination addresses for requests should be formatted as IPv6 addresses with trailing zeros. Internal the CSP sock_udp module ignores all but the first 2 bytes.

e.g.:

> csp
csp
can0       addr: 39:E5 netmask: 4 mtu: 247
           tx: 00000 rx: 00000 txe: 00000 rxe: 00000
           drop: 00000 autherr: 00000 frame: 00000
           txb: 0 (0B) rxb: 0 (0B)

The CSP address 39:E5 or 0x39E5 would become ::39e5 Ipv6 address.

Follow the instructions in README.native.can.md
to setup two virtual can interfaces.

Verify setup from RIOT terminal

> coap info

Expected response:

CoAP server is listening on port 2
 CLI requests sent: 0
CoAP open requests: 0

Send query between RIOT instances

> coap get ::39e5 2 /.well-known/core
coap get ::39e5 2 /.well-known/core
gcoap_cli: sending msg ID 56189, 23 bytes
> gcoap: response Success, code 2.05, 46 bytes
</cli/stats>;ct=0;rt="count";obs,</riot/board>

Issues/PRs references

Depends on #18009

@fjmolinas fjmolinas added State: waiting for other PR State: The PR requires another PR to be merged first State: demonstrator State: This PR (loosely) demonstrates a concept and is not necessarily meant to be merged. labels Apr 26, 2022
@fjmolinas fjmolinas changed the title pkg/libcsp: add sock_udp pkg/libcsp: add sock_udp [demonstrator] Apr 26, 2022
@github-actions github-actions bot added Area: build system Area: Build system Area: doc Area: Documentation Area: network Area: Networking Area: pkg Area: External package ports Area: sys Area: System Area: tests Area: tests and testing framework labels Apr 26, 2022
@Teufelchen1 Teufelchen1 marked this pull request as draft March 26, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: doc Area: Documentation Area: network Area: Networking Area: pkg Area: External package ports Area: sys Area: System Area: tests Area: tests and testing framework State: demonstrator State: This PR (loosely) demonstrates a concept and is not necessarily meant to be merged. State: waiting for other PR State: The PR requires another PR to be merged first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant