diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 710f63bc..62d537fb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -116,11 +116,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - OS: ["contiki", "lwip"] + OS: ["contiki", "lwip", "riot"] steps: - uses: actions/checkout@v3 - name: setup run: | + sudo apt-get update && sudo apt-get install -y libc6-dev-i386 ./autogen.sh - name: configure run: | @@ -221,7 +222,7 @@ jobs: submodules: recursive - name: setup run: | - sudo apt-get update && sudo apt-get install -y libcunit1-dev libtool libtool-bin exuberant-ctags graphviz doxygen libxml2-utils xsltproc docbook-xml docbook-xsl asciidoc + sudo apt-get update && sudo apt-get install -y libcunit1-dev libtool libtool-bin exuberant-ctags graphviz doxygen libxml2-utils xsltproc docbook-xml docbook-xsl asciidoc libc6-dev-i386 ./autogen.sh - name: configure run: | diff --git a/.gitignore b/.gitignore index c29fa05d..98f56d29 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ # ignoring autogenerated files and directories by autoreconf INSTALL -Makefile +/Makefile Makefile.in aclocal.m4 ar-lib @@ -49,6 +49,7 @@ build/ # the doc/ folder doc/Doxyfile +doc/Makefile doc/Makefile.in doc/docbook-xsl.css doc/doxyfile.stamp @@ -77,6 +78,7 @@ man/*.7 # the examples/ folder examples/.deps/ +examples/Makefile examples/*.o examples/coap-client examples/coap-client-* @@ -94,11 +96,15 @@ include/coap3/coap.h # the tests/ folder tests/.deps +tests/Makefile tests/oss-fuzz/Makefile.ci tests/testdriver tests/*.o tests/test_common.h +# the cmake/ folder +cmake/libcoap + # ctags - Sublime plugin tags .tags* diff --git a/BUILDING b/BUILDING index ce458e20..75f2a49f 100644 --- a/BUILDING +++ b/BUILDING @@ -39,7 +39,7 @@ get the TinyDTLS code into your project, so the TinyDTLS library can be used. git submodule init git submodule update -General Building with cmake for linux/windows/macos/android (not for LwIP or Contiki-NG - see below) +General Building with cmake for linux/windows/macos/android (not for RIOT, LwIP or Contiki-NG - see below) ================ cmake -E remove_directory build @@ -61,7 +61,7 @@ General Building with cmake for linux/windows/macos/android (not for LwIP or Con Note: Shared Library support is not currently available for Windows. -General Building with autoconf (not for LwIP or Contiki-NG - see below) +General Building with autoconf (not for RIOT, LwIP or Contiki-NG - see below) ================ ./autogen.sh @@ -114,6 +114,16 @@ function changes, run prior to running 'make'. +RIOT +==== + + ./autogen.sh + ./configure --disable-tests --disable-documentation --disable-examples --disable-dtls + cd examples/riot + make + +See examples/riot/README for further information. + LwIP ==== @@ -122,7 +132,7 @@ LwIP cd examples/lwip make -Executable is ./server. See examples/lwip/README for further information +Executable is ./server. See examples/lwip/README for further information. Contiki-NG ========== @@ -133,7 +143,7 @@ Contiki-NG make Executable is ./server.native. See examples/contiki/README for further -information +information. Windows ======= diff --git a/LICENSE b/LICENSE index 32fbc14f..dee45687 100644 --- a/LICENSE +++ b/LICENSE @@ -115,3 +115,10 @@ When compiled with Mbed TLS support, this software includes components that are licensed under the terms of the Apache 2.0 license (http://www.apache.org/licenses/LICENSE-2.0). +======================================================================== +RIOT + +When compiled with RIOT support, this software includes components +that are licensed under the terms of the the GNU Lesser General Public +License, version 2.1 +(https://raw.githubusercontent.com/RIOT-OS/RIOT/master/LICENSE). diff --git a/Makefile.am b/Makefile.am index 0aad2972..ecf39dad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,6 +62,27 @@ EXTRA_DIST = \ examples/lwip/config/coap_config.h.in \ examples/lwip/config/lwipopts.h \ examples/lwip/config/lwippools.h \ + examples/riot/examples_libcoap_client/client-coap.c \ + examples/riot/examples_libcoap_client/client-coap.h \ + examples/riot/examples_libcoap_client/Kconfig \ + examples/riot/examples_libcoap_client/main.c \ + examples/riot/examples_libcoap_client/Makefile \ + examples/riot/examples_libcoap_client/Makefile.ci \ + examples/riot/examples_libcoap_client/README.md \ + examples/riot/examples_libcoap_server/main.c \ + examples/riot/examples_libcoap_server/Makefile \ + examples/riot/examples_libcoap_server/Makefile.ci \ + examples/riot/examples_libcoap_server/README.md \ + examples/riot/examples_libcoap_server/server-coap.c \ + examples/riot/examples_libcoap_server/server-coap.h \ + examples/riot/examples_libcoap_server/Kconfig \ + examples/riot/Makefile \ + examples/riot/pkg_libcoap/Kconfig \ + examples/riot/pkg_libcoap/Makefile \ + examples/riot/pkg_libcoap/Makefile.dep \ + examples/riot/pkg_libcoap/Makefile.include \ + examples/riot/pkg_libcoap/Makefile.libcoap \ + examples/riot/README \ Makefile.libcoap \ include/coap$(LIBCOAP_API_VERSION)/coap_internal.h \ include/coap$(LIBCOAP_API_VERSION)/coap_riot.h \ @@ -88,6 +109,8 @@ EXTRA_DIST = \ include/coap$(LIBCOAP_API_VERSION)/coap_utlist_internal.h \ include/coap$(LIBCOAP_API_VERSION)/coap_ws_internal.h \ include/coap$(LIBCOAP_API_VERSION)/coap.h.in \ + include/coap$(LIBCOAP_API_VERSION)/coap.h.riot \ + include/coap$(LIBCOAP_API_VERSION)/coap.h.riot.in \ include/coap$(LIBCOAP_API_VERSION)/coap.h.windows \ include/coap$(LIBCOAP_API_VERSION)/coap.h.windows.in \ include/oscore/oscore_cbor.h \ diff --git a/coap_config.h.riot b/coap_config.h.riot index 881ed7c0..0010a2c2 100644 --- a/coap_config.h.riot +++ b/coap_config.h.riot @@ -9,8 +9,8 @@ * of use. */ -#ifndef COAP_CONFIG_H_RIOT_ -#define COAP_CONFIG_H_RIOT_ +#ifndef COAP_CONFIG_H_ +#define COAP_CONFIG_H_ #define WITH_POSIX 1 @@ -18,9 +18,157 @@ #define COAP_CONSTRAINED_STACK 1 #endif +#ifdef CONFIG_LIBCOAP_MAX_LOGGING_LEVEL +#ifndef COAP_MAX_LOGGING_LEVEL +#define COAP_MAX_LOGGING_LEVEL CONFIG_LIBCOAP_MAX_LOGGING_LEVEL +#endif /* COAP_MAX_LOGGING_LEVEL */ +#endif /* CONFIG_LIBCOAP_MAX_LOGGING_LEVEL */ + +#ifdef CONFIG_LIBCOAP_TCP_SUPPORT #ifndef COAP_DISABLE_TCP +#define COAP_DISABLE_TCP 0 +#endif /* COAP_DISABLE_TCP */ +#endif /* CONFIG_LIBCOAP_TCP_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_OSCORE_SUPPORT +#ifndef COAP_OSCORE_SUPPORT +#define COAP_OSCORE_SUPPORT 1 +#endif /* COAP_OSCORE_SUPPORT */ +#endif /* CONFIG_LIBCOAP_OSCORE_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_CLIENT_SUPPORT +#ifndef COAP_CLIENT_SUPPORT +#define COAP_CLIENT_SUPPORT 1 +#endif /* COAP_CLIENT_SUPPORT */ +#endif /* CONFIG_LIBCOAP_CLIENT_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_SERVER_SUPPORT +#ifndef COAP_SERVER_SUPPORT +#define COAP_SERVER_SUPPORT 1 +#endif /* COAP_SERVER_SUPPORT */ +#endif /* CONFIG_LIBCOAP_SERVER_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_MAX_STRING_SIZE +#ifndef COAP_MAX_STRING_SIZE +#define COAP_MAX_STRING_SIZE CONFIG_LIBCOAP_MAX_STRING_SIZE +#endif /* COAP_MAX_STRING_SIZE */ +#endif /* CONFIG_LIBCOAP_OSCORE_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_MAX_ENDPOINTS +#ifndef COAP_MAX_ENDPOINTS +#define COAP_MAX_ENDPOINTS CONFIG_LIBCOAP_MAX_ENDPOINTS +#endif /* COAP_MAX_ENDPOINTS */ +#endif /* CONFIG_LIBCOAP_MAX_ENDPOINTS */ + +#ifdef CONFIG_LIBCOAP_MAX_RESOURCES +#ifndef COAP_MAX_RESOURCES +#define COAP_MAX_RESOURCES CONFIG_LIBCOAP_MAX_RESOURCES +#endif /* COAP_MAX_RESOURCES */ +#endif /* CONFIG_LIBCOAP_MAX_RESOURCES */ + +#ifdef CONFIG_LIBCOAP_MAX_ATTRIBUTE_SIZE +#ifndef COAP_MAX_ATTRIBUTE_SIZE +#define COAP_MAX_ATTRIBUTE_SIZE CONFIG_LIBCOAP_MAX_ATTRIBUTE_SIZE +#endif /* COAP_MAX_ATTRIBUTE_SIZE */ +#endif /* CONFIG_LIBCOAP_MAX_ATTRIBUTE_SIZE */ + +#ifdef CONFIG_LIBCOAP_MAX_ATTRIBUTES +#ifndef COAP_MAX_ATTRIBUTES +#define COAP_MAX_ATTRIBUTES CONFIG_LIBCOAP_MAX_ATTRIBUTES +#endif /* COAP_MAX_ATTRIBUTES */ +#endif /* CONFIG_LIBCOAP_MAX_ATTRIBUTES */ + +#ifdef CONFIG_LIBCOAP_MAX_PACKETS +#ifndef COAP_MAX_PACKETS +#define COAP_MAX_PACKETS CONFIG_LIBCOAP_MAX_PACKETS +#endif /* COAP_MAX_PACKETS */ +#endif /* CONFIG_LIBCOAP_MAX_PACKETS */ + +#ifdef CONFIG_LIBCOAP_MAX_NODES +#ifndef COAP_MAX_NODES +#define COAP_MAX_NODES CONFIG_LIBCOAP_MAX_NODES +#endif /* COAP_MAX_NODES */ +#endif /* CONFIG_LIBCOAP_MAX_NODES */ + +#ifdef CONFIG_LIBCOAP_MAX_CONTEXTS +#ifndef COAP_MAX_CONTEXTS +#define COAP_MAX_CONTEXTS CONFIG_LIBCOAP_MAX_CONTEXTS +#endif /* COAP_MAX_CONTEXTS */ +#endif /* CONFIG_LIBCOAP_MAX_CONTEXTS */ + +#ifdef CONFIG_LIBCOAP_MAX_PDUS +#ifndef COAP_MAX_PDUS +#define COAP_MAX_PDUS CONFIG_LIBCOAP_MAX_PDUS +#endif /* COAP_MAX_PDUS */ +#endif /* CONFIG_LIBCOAP_MAX_PDUS */ + +#ifdef CONFIG_LIBCOAP_MAX_DTLS_SESSIONS +#ifndef COAP_MAX_DTLS_SESSIONS +#define COAP_MAX_DTLS_SESSIONS CONFIG_LIBCOAP_MAX_DTLS_SESSIONS +#endif /* COAP_MAX_DTLS_SESSIONS */ +#endif /* CONFIG_LIBCOAP_MAX_DTLS_SESSIONS */ + +#ifdef CONFIG_LIBCOAP_MAX_SESSIONS +#ifndef COAP_MAX_SESSIONS +#define COAP_MAX_SESSIONS CONFIG_LIBCOAP_MAX_SESSIONS +#endif /* COAP_MAX_SESSIONS */ +#endif /* CONFIG_LIBCOAP_MAX_SESSIONS */ + +#ifdef CONFIG_LIBCOAP_MAX_OPTION_SIZE +#ifndef COAP_MAX_OPTION_SIZE +#define COAP_MAX_OPTION_SIZE CONFIG_LIBCOAP_MAX_OPTION_SIZE +#endif /* COAP_MAX_OPTION_SIZE */ +#endif /* CONFIG_LIBCOAP_MAX_OPTION_SIZE */ + +#ifdef CONFIG_LIBCOAP_MAX_OPTIONS +#ifndef COAP_MAX_OPTIONS +#define COAP_MAX_OPTIONS CONFIG_LIBCOAP_MAX_OPTIONS +#endif /* COAP_MAX_OPTIONS */ +#endif /* CONFIG_LIBCOAP_MAX_OPTIONS */ + +#ifdef CONFIG_LIBCOAP_MAX_CACHE_KEYS +#ifndef COAP_MAX_CACHE_KEYS +#define COAP_MAX_CACHE_KEYS CONFIG_LIBCOAP_MAX_CACHE_KEYS +#endif /* COAP_MAX_CACHE_KEYS */ +#endif /* CONFIG_LIBCOAP_MAX_CACHE_KEYS */ + +#ifdef CONFIG_LIBCOAP_MAX_CACHE_ENTRIES +#ifndef COAP_MAX_CACHE_ENTRIES +#define COAP_MAX_CACHE_ENTRIES CONFIG_LIBCOAP_MAX_CACHE_ENTRIES +#endif /* COAP_MAX_CACHE_ENTRIES */ +#endif /* CONFIG_LIBCOAP_MAX_CACHE_ENTRIES */ + +#ifdef CONFIG_LIBCOAP_MAX_LG_CRCVS +#ifndef COAP_MAX_LG_CRCVS +#define COAP_MAX_LG_CRCVS CONFIG_LIBCOAP_MAX_LG_CRCVS +#endif /* COAP_MAX_LG_CRCVS */ +#endif /* CONFIG_LIBCOAP_MAX_LG_CRCVS */ + +#ifdef CONFIG_LIBCOAP_MAX_LG_SRCVS +#ifndef COAP_MAX_LG_SRCVS +#define COAP_MAX_LG_SRCVS CONFIG_LIBCOAP_MAX_LG_SRCVS +#endif /* COAP_MAX_LG_SRCVS */ +#endif /* CONFIG_LIBCOAP_MAX_LG_SRCVS */ + +#ifdef CONFIG_LIBCOAP_MAX_LG_XMITS +#ifndef COAP_MAX_LG_XMITS +#define COAP_MAX_LG_XMITS CONFIG_LIBCOAP_MAX_LG_XMITS +#endif /* COAP_MAX_LG_XMITS */ +#endif /* CONFIG_LIBCOAP_MAX_LG_XMITS */ + +#ifndef COAP_DISABLE_TCP +#if MODULE_SOCK_TCP +#define COAP_DISABLE_TCP 0 +#else /* ! MODULE_SOCK_TCP */ #define COAP_DISABLE_TCP 1 -#endif +#endif /* ! MODULE_SOCK_TCP */ +#endif /* COAP_DISABLE_TCP */ + +#ifdef MODULE_TINYDTLS +#ifndef HAVE_LIBTINYDTLS +#define HAVE_LIBTINYDTLS 1 +#endif /* ! HAVE_LIBTINYDTLS */ +#endif /* MODULE_TINYDTLS */ /* Define if building universal (internal helper macro) */ /* #undef AC_APPLE_UNIVERSAL_BUILD */ @@ -78,7 +226,7 @@ #define HAVE_STRING_H 1 /* Define to 1 if you have the `strnlen' function. */ -/* #undef HAVE_STRNLEN */ +#define HAVE_STRNLEN 1 /* Define to 1 if you have the `strrchr' function. */ #define HAVE_STRRCHR 1 @@ -140,4 +288,4 @@ /* Define to `int' if does not define. */ /* #undef ssize_t */ -#endif /* COAP_CONFIG_H_RIOT_ */ +#endif /* COAP_CONFIG_H_ */ diff --git a/coap_config.h.riot.in b/coap_config.h.riot.in index 1d674f32..a577ec7c 100644 --- a/coap_config.h.riot.in +++ b/coap_config.h.riot.in @@ -9,8 +9,8 @@ * of use. */ -#ifndef COAP_CONFIG_H_RIOT_ -#define COAP_CONFIG_H_RIOT_ +#ifndef COAP_CONFIG_H_ +#define COAP_CONFIG_H_ #define WITH_POSIX 1 @@ -18,9 +18,157 @@ #define COAP_CONSTRAINED_STACK 1 #endif +#ifdef CONFIG_LIBCOAP_MAX_LOGGING_LEVEL +#ifndef COAP_MAX_LOGGING_LEVEL +#define COAP_MAX_LOGGING_LEVEL CONFIG_LIBCOAP_MAX_LOGGING_LEVEL +#endif /* COAP_MAX_LOGGING_LEVEL */ +#endif /* CONFIG_LIBCOAP_MAX_LOGGING_LEVEL */ + +#ifdef CONFIG_LIBCOAP_TCP_SUPPORT #ifndef COAP_DISABLE_TCP +#define COAP_DISABLE_TCP 0 +#endif /* COAP_DISABLE_TCP */ +#endif /* CONFIG_LIBCOAP_TCP_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_OSCORE_SUPPORT +#ifndef COAP_OSCORE_SUPPORT +#define COAP_OSCORE_SUPPORT 1 +#endif /* COAP_OSCORE_SUPPORT */ +#endif /* CONFIG_LIBCOAP_OSCORE_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_CLIENT_SUPPORT +#ifndef COAP_CLIENT_SUPPORT +#define COAP_CLIENT_SUPPORT 1 +#endif /* COAP_CLIENT_SUPPORT */ +#endif /* CONFIG_LIBCOAP_CLIENT_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_SERVER_SUPPORT +#ifndef COAP_SERVER_SUPPORT +#define COAP_SERVER_SUPPORT 1 +#endif /* COAP_SERVER_SUPPORT */ +#endif /* CONFIG_LIBCOAP_SERVER_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_MAX_STRING_SIZE +#ifndef COAP_MAX_STRING_SIZE +#define COAP_MAX_STRING_SIZE CONFIG_LIBCOAP_MAX_STRING_SIZE +#endif /* COAP_MAX_STRING_SIZE */ +#endif /* CONFIG_LIBCOAP_OSCORE_SUPPORT */ + +#ifdef CONFIG_LIBCOAP_MAX_ENDPOINTS +#ifndef COAP_MAX_ENDPOINTS +#define COAP_MAX_ENDPOINTS CONFIG_LIBCOAP_MAX_ENDPOINTS +#endif /* COAP_MAX_ENDPOINTS */ +#endif /* CONFIG_LIBCOAP_MAX_ENDPOINTS */ + +#ifdef CONFIG_LIBCOAP_MAX_RESOURCES +#ifndef COAP_MAX_RESOURCES +#define COAP_MAX_RESOURCES CONFIG_LIBCOAP_MAX_RESOURCES +#endif /* COAP_MAX_RESOURCES */ +#endif /* CONFIG_LIBCOAP_MAX_RESOURCES */ + +#ifdef CONFIG_LIBCOAP_MAX_ATTRIBUTE_SIZE +#ifndef COAP_MAX_ATTRIBUTE_SIZE +#define COAP_MAX_ATTRIBUTE_SIZE CONFIG_LIBCOAP_MAX_ATTRIBUTE_SIZE +#endif /* COAP_MAX_ATTRIBUTE_SIZE */ +#endif /* CONFIG_LIBCOAP_MAX_ATTRIBUTE_SIZE */ + +#ifdef CONFIG_LIBCOAP_MAX_ATTRIBUTES +#ifndef COAP_MAX_ATTRIBUTES +#define COAP_MAX_ATTRIBUTES CONFIG_LIBCOAP_MAX_ATTRIBUTES +#endif /* COAP_MAX_ATTRIBUTES */ +#endif /* CONFIG_LIBCOAP_MAX_ATTRIBUTES */ + +#ifdef CONFIG_LIBCOAP_MAX_PACKETS +#ifndef COAP_MAX_PACKETS +#define COAP_MAX_PACKETS CONFIG_LIBCOAP_MAX_PACKETS +#endif /* COAP_MAX_PACKETS */ +#endif /* CONFIG_LIBCOAP_MAX_PACKETS */ + +#ifdef CONFIG_LIBCOAP_MAX_NODES +#ifndef COAP_MAX_NODES +#define COAP_MAX_NODES CONFIG_LIBCOAP_MAX_NODES +#endif /* COAP_MAX_NODES */ +#endif /* CONFIG_LIBCOAP_MAX_NODES */ + +#ifdef CONFIG_LIBCOAP_MAX_CONTEXTS +#ifndef COAP_MAX_CONTEXTS +#define COAP_MAX_CONTEXTS CONFIG_LIBCOAP_MAX_CONTEXTS +#endif /* COAP_MAX_CONTEXTS */ +#endif /* CONFIG_LIBCOAP_MAX_CONTEXTS */ + +#ifdef CONFIG_LIBCOAP_MAX_PDUS +#ifndef COAP_MAX_PDUS +#define COAP_MAX_PDUS CONFIG_LIBCOAP_MAX_PDUS +#endif /* COAP_MAX_PDUS */ +#endif /* CONFIG_LIBCOAP_MAX_PDUS */ + +#ifdef CONFIG_LIBCOAP_MAX_DTLS_SESSIONS +#ifndef COAP_MAX_DTLS_SESSIONS +#define COAP_MAX_DTLS_SESSIONS CONFIG_LIBCOAP_MAX_DTLS_SESSIONS +#endif /* COAP_MAX_DTLS_SESSIONS */ +#endif /* CONFIG_LIBCOAP_MAX_DTLS_SESSIONS */ + +#ifdef CONFIG_LIBCOAP_MAX_SESSIONS +#ifndef COAP_MAX_SESSIONS +#define COAP_MAX_SESSIONS CONFIG_LIBCOAP_MAX_SESSIONS +#endif /* COAP_MAX_SESSIONS */ +#endif /* CONFIG_LIBCOAP_MAX_SESSIONS */ + +#ifdef CONFIG_LIBCOAP_MAX_OPTION_SIZE +#ifndef COAP_MAX_OPTION_SIZE +#define COAP_MAX_OPTION_SIZE CONFIG_LIBCOAP_MAX_OPTION_SIZE +#endif /* COAP_MAX_OPTION_SIZE */ +#endif /* CONFIG_LIBCOAP_MAX_OPTION_SIZE */ + +#ifdef CONFIG_LIBCOAP_MAX_OPTIONS +#ifndef COAP_MAX_OPTIONS +#define COAP_MAX_OPTIONS CONFIG_LIBCOAP_MAX_OPTIONS +#endif /* COAP_MAX_OPTIONS */ +#endif /* CONFIG_LIBCOAP_MAX_OPTIONS */ + +#ifdef CONFIG_LIBCOAP_MAX_CACHE_KEYS +#ifndef COAP_MAX_CACHE_KEYS +#define COAP_MAX_CACHE_KEYS CONFIG_LIBCOAP_MAX_CACHE_KEYS +#endif /* COAP_MAX_CACHE_KEYS */ +#endif /* CONFIG_LIBCOAP_MAX_CACHE_KEYS */ + +#ifdef CONFIG_LIBCOAP_MAX_CACHE_ENTRIES +#ifndef COAP_MAX_CACHE_ENTRIES +#define COAP_MAX_CACHE_ENTRIES CONFIG_LIBCOAP_MAX_CACHE_ENTRIES +#endif /* COAP_MAX_CACHE_ENTRIES */ +#endif /* CONFIG_LIBCOAP_MAX_CACHE_ENTRIES */ + +#ifdef CONFIG_LIBCOAP_MAX_LG_CRCVS +#ifndef COAP_MAX_LG_CRCVS +#define COAP_MAX_LG_CRCVS CONFIG_LIBCOAP_MAX_LG_CRCVS +#endif /* COAP_MAX_LG_CRCVS */ +#endif /* CONFIG_LIBCOAP_MAX_LG_CRCVS */ + +#ifdef CONFIG_LIBCOAP_MAX_LG_SRCVS +#ifndef COAP_MAX_LG_SRCVS +#define COAP_MAX_LG_SRCVS CONFIG_LIBCOAP_MAX_LG_SRCVS +#endif /* COAP_MAX_LG_SRCVS */ +#endif /* CONFIG_LIBCOAP_MAX_LG_SRCVS */ + +#ifdef CONFIG_LIBCOAP_MAX_LG_XMITS +#ifndef COAP_MAX_LG_XMITS +#define COAP_MAX_LG_XMITS CONFIG_LIBCOAP_MAX_LG_XMITS +#endif /* COAP_MAX_LG_XMITS */ +#endif /* CONFIG_LIBCOAP_MAX_LG_XMITS */ + +#ifndef COAP_DISABLE_TCP +#if MODULE_SOCK_TCP +#define COAP_DISABLE_TCP 0 +#else /* ! MODULE_SOCK_TCP */ #define COAP_DISABLE_TCP 1 -#endif +#endif /* ! MODULE_SOCK_TCP */ +#endif /* COAP_DISABLE_TCP */ + +#ifdef MODULE_TINYDTLS +#ifndef HAVE_LIBTINYDTLS +#define HAVE_LIBTINYDTLS 1 +#endif /* ! HAVE_LIBTINYDTLS */ +#endif /* MODULE_TINYDTLS */ /* Define if building universal (internal helper macro) */ /* #undef AC_APPLE_UNIVERSAL_BUILD */ @@ -78,7 +226,7 @@ #define HAVE_STRING_H 1 /* Define to 1 if you have the `strnlen' function. */ -/* #undef HAVE_STRNLEN */ +#define HAVE_STRNLEN 1 /* Define to 1 if you have the `strrchr' function. */ #define HAVE_STRRCHR 1 @@ -140,4 +288,4 @@ /* Define to `int' if does not define. */ /* #undef ssize_t */ -#endif /* COAP_CONFIG_H_RIOT_ */ +#endif /* COAP_CONFIG_H_ */ diff --git a/configure.ac b/configure.ac index 41ab240c..aff74d50 100644 --- a/configure.ac +++ b/configure.ac @@ -1041,6 +1041,7 @@ doc/Makefile examples/Makefile examples/lwip/config/coap_config.h include/coap$LIBCOAP_API_VERSION/coap.h +include/coap$LIBCOAP_API_VERSION/coap.h.riot include/coap$LIBCOAP_API_VERSION/coap.h.windows man/coap.txt man/coap_address.txt diff --git a/examples/riot/.gitignore b/examples/riot/.gitignore new file mode 100644 index 00000000..4bd702b5 --- /dev/null +++ b/examples/riot/.gitignore @@ -0,0 +1,2 @@ +# not going for submodules here to keep things easy +RIOT diff --git a/examples/riot/Makefile b/examples/riot/Makefile new file mode 100644 index 00000000..91ad0e26 --- /dev/null +++ b/examples/riot/Makefile @@ -0,0 +1,41 @@ +# Makefile +# +# Copyright (C) 2010-2023 Olaf Bergmann and others +# +# SPDX-License-Identifier: BSD-2-Clause +# +# This file is part of the CoAP C library libcoap. Please see README and +# COPYING for terms of use. + +RIOT=RIOT +TARGET?=native + +all: RIOT pkg examples client server + +RIOT: + git clone --depth 1 https://github.com/RIOT-OS/RIOT.git $@ + +pkg: + rm -rf RIOT/pkg/libcoap && mkdir RIOT/pkg/libcoap + cd pkg_libcoap && cp -r * ../RIOT/pkg/libcoap + @HAVE_KCONFIG=`grep libcoap/Kconfig RIOT/pkg/Kconfig | wc -l` ; \ + if [ "$${HAVE_KCONFIG}" = 0 ] ; then \ + sed -i '/rsource "libcose\/Kconfig"/irsource "libcoap\/Kconfig"' RIOT/pkg/Kconfig ; \ + fi + +examples: + rm -rf RIOT/examples/libcoap-client && mkdir RIOT/examples/libcoap-client + cd examples_libcoap_client && cp -r * ../RIOT/examples/libcoap-client + rm -rf RIOT/examples/libcoap-server && mkdir RIOT/examples/libcoap-server + cd examples_libcoap_server && cp -r * ../RIOT/examples/libcoap-server + +client: RIOT pkg examples + $(MAKE) -C RIOT/examples/libcoap-client/ + +server: RIOT pkg examples + $(MAKE) -C RIOT/examples/libcoap-server/ + +clean: + rm -rf RIOT/pkg/libcoap + rm -rf RIOT/examples/libcoap-client + rm -rf RIOT/examples/libcoap-server diff --git a/examples/riot/README b/examples/riot/README new file mode 100644 index 00000000..fec58487 --- /dev/null +++ b/examples/riot/README @@ -0,0 +1,44 @@ +Example of libcoap running on RIOT +================================== + +To build the examples, do + + $ make + +This will + +* download RIOT from the upstream git sources +* update the RIOT environment with pkg/libcoap, examples/libcoap-client + and examples/libcoap-server taken from pkg_libcoap/, examples_client/ + and examples_server respectively/. +* build the client application +* build the server application + +To run the server application + +* cd RIOT/examples-libcoap-server +* make term +* (at the shell prompt) coaps start + +The server creates a resource for 'time' with a query 'ticks'. This is +reported for `.well-known/core`. The work flow for adding more resources does +not differ from regular libcoap usage. + +To run the client application + +* cd RIOT/examples-libcoap-client +* make term +* (at the shell prompt) coapc + +The client will try to connect to the URI defined in app.config named +CONFIG_LIBCOAP_CLIENT_URI (unless overridden by running 'make menuconfig'). + +Note to developers +================== + +PKG_VERSION= in pkg_libcoap/Makefile needs updating if you need a different +version of libcoap to get installed into RIOT/pkg/libcoap. + +Kconfig support is available. Running make in the libcoap distribution +examples/riot directory will try to add in a 'rsource "libcoap/Kconfig"' +entry into RIOT/pkg/Kconfig diff --git a/examples/riot/examples_libcoap_client/Kconfig b/examples/riot/examples_libcoap_client/Kconfig new file mode 100644 index 00000000..1d6308ec --- /dev/null +++ b/examples/riot/examples_libcoap_client/Kconfig @@ -0,0 +1,19 @@ +if USEMODULE_LIBCOAP +config LIBCOAP_CLIENT_URI + string "CoAP URI to connect to" + default "coap://[fe80::405:5aff:fe15:9b7f]/.well-known/core" +config LIBCOAP_USE_PSK + string "Secret to use for PSK communications" + default "secretPSK" + depends on USEMODULE_TINYDTLS +config LIBCOAP_USE_PSK_ID + string "User ID to use for PSK communications" + default "user_abc" + depends on USEMODULE_TINYDTLS +config LIBCOAP_SERVER_SUPPORT + bool "Set to y if server support is required" + default n +config LIBCOAP_CLIENT_SUPPORT + bool "Set to y if client support is required" + default y +endif # USEMODULE_LIBCOAP diff --git a/examples/riot/examples_libcoap_client/Makefile b/examples/riot/examples_libcoap_client/Makefile new file mode 100644 index 00000000..813a521c --- /dev/null +++ b/examples/riot/examples_libcoap_client/Makefile @@ -0,0 +1,67 @@ +# name of your application +APPLICATION = libcoap-client + +# If no BOARD is found in the environment, use this default: +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 +USEMODULE += auto_init_gnrc_netif + +# Activate ICMPv6 error messages +USEMODULE += gnrc_icmpv6_error + +# Specify the mandatory networking module for a IPv6 routing node +USEMODULE += gnrc_ipv6_router_default + +# Add a routing protocol +USEMODULE += gnrc_rpl +USEMODULE += auto_init_gnrc_rpl + +# Additional networking modules that can be dropped if not needed +USEMODULE += gnrc_icmpv6_echo + +# Specify the mandatory networking modules for IPv6 and UDP +USEMODULE += gnrc_ipv6_default +USEMODULE += memarray +USEMODULE += ipv4_addr + +# a cryptographically secure implementation of PRNG is needed for tinydtls +# Uncomment the following 3 lines for tinydtls support +CFLAGS += -DWITH_RIOT_SOCK +USEPKG += tinydtls +USEMODULE += prng_sha1prng + +# libcoap support +USEPKG += libcoap + +# Configure if DNS is required +# USEMODULE += sock_dns + +# Support 64 bit ticks +USEMODULE += ztimer64_xtimer_compat + +# Add also the shell, some shell commands +USEMODULE += shell +USEMODULE += shell_cmds_default +USEMODULE += ps +USEMODULE += netstats_l2 +USEMODULE += netstats_ipv6 +USEMODULE += netstats_rpl + +# libcoap needs some space +CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\) + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +# QUIET ?= 1 + +include $(RIOTBASE)/Makefile.include diff --git a/examples/riot/examples_libcoap_client/Makefile.ci b/examples/riot/examples_libcoap_client/Makefile.ci new file mode 100644 index 00000000..0e7e4cfc --- /dev/null +++ b/examples/riot/examples_libcoap_client/Makefile.ci @@ -0,0 +1,49 @@ +BOARD_INSUFFICIENT_MEMORY := \ + airfy-beacon \ + b-l072z-lrwan1 \ + blackpill-stm32f103c8 \ + blackpill-stm32f103cb \ + bluepill-stm32f030c8 \ + bluepill-stm32f103c8 \ + bluepill-stm32f103cb \ + calliope-mini \ + cc2650-launchpad \ + cc2650stk \ + hifive1 \ + hifive1b \ + i-nucleo-lrwan1 \ + im880b \ + lsn50 \ + maple-mini \ + microbit \ + nrf51dk \ + nrf51dongle \ + nrf6310 \ + nucleo-f030r8 \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-f070rb \ + nucleo-f072rb \ + nucleo-f103rb \ + nucleo-f302r8 \ + nucleo-f303k8 \ + nucleo-f334r8 \ + nucleo-l011k4 \ + nucleo-l031k6 \ + nucleo-l053r8 \ + nucleo-l073rz \ + opencm904 \ + samd10-xmini \ + saml10-xpro \ + saml11-xpro \ + slstk3400a \ + spark-core \ + stk3200 \ + stm32f030f4-demo \ + stm32f0discovery \ + stm32f7508-dk \ + stm32g0316-disco \ + stm32l0538-disco \ + stm32mp157c-dk2 \ + yunjia-nrf51822 \ + # diff --git a/examples/riot/examples_libcoap_client/README.md b/examples/riot/examples_libcoap_client/README.md new file mode 100644 index 00000000..6d4f5301 --- /dev/null +++ b/examples/riot/examples_libcoap_client/README.md @@ -0,0 +1,24 @@ +# libcoap client example + +This example shows how to configure a client to use libcoap + +## Fast configuration (Between RIOT instances): + +Preparing the logical interfaces: + + sudo ./../../dist/tools/tapsetup/tapsetup --create 2 + +## Client invocation +For the client: + + PORT=tap0 make term + coapc + +The IP address to connect to needs to be that as returned by libcoap_server, +or that of the tap0 interface, etc. + +## Handling the static memory allocation + +libcoap for RIOT is using the `sys/memarray` module and therefore there +are certain limits. Said resources are defined in `libcoap/src/coap_mem.c`, +but can be overwritten at compile time. diff --git a/examples/riot/examples_libcoap_client/app.config b/examples/riot/examples_libcoap_client/app.config new file mode 100644 index 00000000..bab86085 --- /dev/null +++ b/examples/riot/examples_libcoap_client/app.config @@ -0,0 +1,8 @@ +CONFIG_LIBCOAP_CLIENT_SUPPORT=y +CONFIG_LIBCOAP_CLIENT_URI="coap://[fe80::405:5aff:fe15:9b7f]/.well-known/core" + +CONFIG_LIBCOAP_USE_PSK="secretPSK" +CONFIG_LIBCOAP_USE_PSK_ID="user_abc" + +CONFIG_KCONFIG_USEPKG_LIBCOAP=y +# Logging levels are defined in pkg/libcoap using Kconfig diff --git a/examples/riot/examples_libcoap_client/client-coap.c b/examples/riot/examples_libcoap_client/client-coap.c new file mode 100644 index 00000000..01e98800 --- /dev/null +++ b/examples/riot/examples_libcoap_client/client-coap.c @@ -0,0 +1,249 @@ +/* + * client-coap.c -- RIOT client example + * + * Copyright (C) 2023 Jon Shallow + * + * SPDX-License-Identifier: BSD-2-Clause + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +#include "coap_config.h" +#include +#include +#include +#include +#include "client-coap.h" +#include "net/utils.h" +#include +#include +#include + +#ifdef CONFIG_LIBCOAP_CLIENT_URI +#define COAP_CLIENT_URI CONFIG_LIBCOAP_CLIENT_URI +#else /* ! CONFIG_LIBCOAP_CLIENT_URI */ +#define COAP_CLIENT_URI "coap://[fe80::405:5aff:fe15:9b7f]/.well-known/core" +#endif /* ! CONFIG_LIBCOAP_CLIENT_URI */ + +#ifdef CONFIG_LIBCOAP_USE_PSK +#define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK +#else /* ! CONFIG_LIBCOAP_USE_PSK */ +#define COAP_USE_PSK NULL +#endif /* ! CONFIG_LIBCOAP_USE_PSK */ + +#ifdef CONFIG_LIBCOAP_USE_PSK_ID +#define COAP_USE_PSK_ID CONFIG_LIBCOAP_USE_PSK_ID +#else /* ! CONFIG_LIBCOAP_USE_PSK_ID */ +#define COAP_USE_PSK_ID NULL +#endif /* ! CONFIG_LIBCOAP_USE_PSK_ID */ + +#ifndef min +#define min(a,b) ((a) < (b) ? (a) : (b)) +#endif + +static coap_context_t *main_coap_context = NULL; +static coap_optlist_t *optlist = NULL; + +static int quit = 0; + +static coap_response_t +message_handler(coap_session_t *session, + const coap_pdu_t *sent, + const coap_pdu_t *received, + const coap_mid_t id) { + const uint8_t *data; + size_t len; + size_t offset; + size_t total; + + (void)session; + (void)sent; + (void)id; + if (coap_get_data_large(received, &len, &data, &offset, &total)) { + printf("%*.*s", (int)len, (int)len, (const char*)data); + if (len + offset == total) { + printf("\n"); + quit = 1; + } + } + return COAP_RESPONSE_OK; +} + +static void +nack_handler(coap_session_t *session COAP_UNUSED, + const coap_pdu_t *sent COAP_UNUSED, + const coap_nack_reason_t reason, + const coap_mid_t id COAP_UNUSED) { + + switch(reason) { + case COAP_NACK_TOO_MANY_RETRIES: + case COAP_NACK_NOT_DELIVERABLE: + case COAP_NACK_RST: + case COAP_NACK_TLS_FAILED: + case COAP_NACK_TLS_LAYER_FAILED: + case COAP_NACK_WS_LAYER_FAILED: + case COAP_NACK_WS_FAILED: + coap_log_err("cannot send CoAP pdu\n"); + quit = 1; + break; + case COAP_NACK_ICMP_ISSUE: + case COAP_NACK_BAD_RESPONSE: + default: + ; + } + return; +} + +static int +resolve_address(const char *host, const char *service, coap_address_t *dst, + int scheme_hint_bits) { + uint16_t port = service ? atoi(service) : 0; + int ret = 0; + coap_str_const_t str_host; + coap_addr_info_t *addr_info; + + str_host.s = (const uint8_t *)host; + str_host.length = strlen(host); + addr_info = coap_resolve_address_info(&str_host, port, port, AF_UNSPEC, + scheme_hint_bits); + if (addr_info) { + ret = 1; + *dst = addr_info->addr; + } + + coap_free_address_info(addr_info); + return ret; +} + +void +client_coap_init(int argc, char **argv) { + coap_session_t *session = NULL; + coap_pdu_t *pdu; + coap_address_t dst; + coap_mid_t mid; + int len; + coap_uri_t uri; + char portbuf[8]; +#define BUFSIZE 100 + unsigned char buf[BUFSIZE]; + int res; + + (void)argc; + (void)argv; + + coap_startup(); + coap_set_log_level(COAP_MAX_LOGGING_LEVEL); + + /* Parse the URI */ + len = coap_split_uri((const unsigned char *)COAP_CLIENT_URI, strlen(COAP_CLIENT_URI), &uri); + if (len != 0) { + coap_log_warn("Failed to parse uri %s\n", COAP_CLIENT_URI); + goto fail; + } + + snprintf(portbuf, sizeof(portbuf), "%d", uri.port); + snprintf((char *)buf, sizeof(buf), "%*.*s", (int)uri.host.length, + (int)uri.host.length, (const char *)uri.host.s); + /* resolve destination address where packet should be sent */ + len = resolve_address((const char*)buf, portbuf, &dst, 1 << uri.scheme); + if (len <= 0) { + coap_log_warn("Failed to resolve address %*.*s\n", (int)uri.host.length, + (int)uri.host.length, (const char *)uri.host.s); + goto fail; + } + + main_coap_context = coap_new_context(NULL); + if (!main_coap_context) { + coap_log_warn("Failed to initialize context\n"); + goto fail; + } + + coap_context_set_block_mode(main_coap_context, COAP_BLOCK_USE_LIBCOAP); + + if (uri.scheme == COAP_URI_SCHEME_COAP) { + session = coap_new_client_session(main_coap_context, NULL, &dst, + COAP_PROTO_UDP); + } else if (uri.scheme == COAP_URI_SCHEME_COAP_TCP) { + session = coap_new_client_session(main_coap_context, NULL, &dst, + COAP_PROTO_TCP); +#if defined (COAP_USE_PSK) && defined(COAP_USE_PSK_ID) + } else { + static coap_dtls_cpsk_t dtls_psk; + static char client_sni[256]; + + memset(client_sni, 0, sizeof(client_sni)); + memset (&dtls_psk, 0, sizeof(dtls_psk)); + dtls_psk.version = COAP_DTLS_CPSK_SETUP_VERSION; + if (uri.host.length) + memcpy(client_sni, uri.host.s, + min(uri.host.length, sizeof(client_sni) - 1)); + else + memcpy(client_sni, "localhost", 9); + dtls_psk.client_sni = client_sni; + dtls_psk.psk_info.identity.s = (const uint8_t *)COAP_USE_PSK_ID; + dtls_psk.psk_info.identity.length = strlen(COAP_USE_PSK_ID); + dtls_psk.psk_info.key.s = (const uint8_t *)COAP_USE_PSK; + dtls_psk.psk_info.key.length = strlen(COAP_USE_PSK); + + session = coap_new_client_session_psk2(main_coap_context, NULL, &dst, + COAP_PROTO_DTLS, &dtls_psk); +#else /* ! COAP_USE_PSK && ! COAP_USE_PSK_ID */ + coap_log_err("CONFIG_LIBCOAP_USE_PSK and CONFIG_LIBCOAP_USE_PSK_ID not defined\n"); + goto fail; +#endif /* ! COAP_USE_PSK && ! COAP_USE_PSK_ID */ + } + + if (!session) { + coap_log_warn("Failed to create session\n"); + goto fail; + } + + coap_register_response_handler(main_coap_context, message_handler); + coap_register_nack_handler(main_coap_context, nack_handler); + + /* construct CoAP message */ + pdu = coap_pdu_init(COAP_MESSAGE_CON, + COAP_REQUEST_CODE_GET, + coap_new_message_id(session), + coap_session_max_pdu_size(session)); + if (!pdu) { + coap_log_warn("Failed to create PDU\n"); + goto fail; + } + + len = coap_uri_into_options(&uri, &optlist, 1, buf, sizeof(buf)); + if (len) { + coap_log_warn("Failed to create options\n"); + goto fail; + } + + /* Add option list (which will be sorted) to the PDU */ + if (optlist) { + res = coap_add_optlist_pdu(pdu, &optlist); + if (res != 1) { + coap_log_warn("Failed to add options to PDU\n"); + goto fail; + } + } + + /* and send the PDU */ + mid = coap_send(session, pdu); + if (mid == COAP_INVALID_MID) { + coap_log_warn("Failed to send PDU\n"); + goto fail; + } + while (!quit) { + coap_io_process(main_coap_context, 1000); + } +fail: + /* Clean up library usage so client can be run again */ + quit = 0; + coap_delete_optlist(optlist); + optlist = NULL; + coap_session_release(session); + session = NULL; + coap_free_context(main_coap_context); + main_coap_context = NULL; + coap_cleanup(); +} diff --git a/examples/riot/examples_libcoap_client/client-coap.h b/examples/riot/examples_libcoap_client/client-coap.h new file mode 100644 index 00000000..ee51170b --- /dev/null +++ b/examples/riot/examples_libcoap_client/client-coap.h @@ -0,0 +1,16 @@ +/* + * client-coap.h -- RIOT client example + * + * Copyright (C) 2023 Jon Shallow + * + * SPDX-License-Identifier: BSD-2-Clause + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +#include "coap_config.h" +#include + +/* Start up the CoAP Client */ +void client_coap_init(int argc, char **argv); diff --git a/examples/riot/examples_libcoap_client/main.c b/examples/riot/examples_libcoap_client/main.c new file mode 100644 index 00000000..bd7f885d --- /dev/null +++ b/examples/riot/examples_libcoap_client/main.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * Copyright (C) 2018 Inria + * + * 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. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Example application for libcoap client + * + * @author Raul Fuentes <> + * + * @} + */ + +#include + +#include "shell.h" +#include "msg.h" + +#include "coap3/coap.h" + +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +extern int client_coap_init(int argc, char **argv); + +static const shell_command_t shell_commands[] = { + { "coapc", "Start a libcoap client", client_coap_init }, + { NULL, NULL, NULL } +}; + +int main(void) +{ + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("RIOT libcoap client testing implementation"); + + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should be never reached */ + return 0; +} diff --git a/examples/riot/examples_libcoap_server/Kconfig b/examples/riot/examples_libcoap_server/Kconfig new file mode 100644 index 00000000..2150cb3d --- /dev/null +++ b/examples/riot/examples_libcoap_server/Kconfig @@ -0,0 +1,12 @@ +if USEMODULE_LIBCOAP +config LIBCOAP_USE_PSK + string "Secret to use for PSK communications" + default "secretPSK" + depends on USEMODULE_TINYDTLS +config LIBCOAP_SERVER_SUPPORT + bool "Set to y if server support is required" + default y +config LIBCOAP_CLIENT_SUPPORT + bool "Set to y if ongoing proxy support is required" + default n +endif # USEMODULE_LIBCOAP diff --git a/examples/riot/examples_libcoap_server/Makefile b/examples/riot/examples_libcoap_server/Makefile new file mode 100644 index 00000000..954d91de --- /dev/null +++ b/examples/riot/examples_libcoap_server/Makefile @@ -0,0 +1,69 @@ +# name of your application +APPLICATION = libcoap-server + +# If no BOARD is found in the environment, use this default: +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 +USEMODULE += auto_init_gnrc_netif + +# Activate ICMPv6 error messages +# USEMODULE += gnrc_icmpv6_error + +# Specify the mandatory networking module for a IPv6 routing node +USEMODULE += gnrc_ipv6_router_default + +# Add a routing protocol +USEMODULE += gnrc_rpl +USEMODULE += auto_init_gnrc_rpl + +# Additional networking modules that can be dropped if not needed +USEMODULE += gnrc_icmpv6_echo +USEMODULE += shell_cmd_gnrc_udp + +# Specify the mandatory networking modules for IPv6 and UDP +USEMODULE += gnrc_ipv6_default +USEMODULE += memarray +USEMODULE += ipv4_addr + +# a cryptographically secure implementation of PRNG is needed for tinydtls +# Uncomment the following 3 lines for tinydtls support +CFLAGS += -DWITH_RIOT_SOCK +USEPKG += tinydtls +USEMODULE += prng_sha1prng + +# libcoap support +USEPKG += libcoap + +USEMODULE += sock_udp +# Configure if DNS is required +USEMODULE += sock_dns + +# USEMODULE += xtimer +USEMODULE += ztimer64_xtimer_compat + +# Add also the shell, some shell commands +USEMODULE += shell +USEMODULE += shell_cmds_default +USEMODULE += ps +USEMODULE += netstats_l2 +USEMODULE += netstats_ipv6 +USEMODULE += netstats_rpl + +# libcoap needs some space +CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\) + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +include $(RIOTBASE)/Makefile.include diff --git a/examples/riot/examples_libcoap_server/Makefile.ci b/examples/riot/examples_libcoap_server/Makefile.ci new file mode 100644 index 00000000..0e7e4cfc --- /dev/null +++ b/examples/riot/examples_libcoap_server/Makefile.ci @@ -0,0 +1,49 @@ +BOARD_INSUFFICIENT_MEMORY := \ + airfy-beacon \ + b-l072z-lrwan1 \ + blackpill-stm32f103c8 \ + blackpill-stm32f103cb \ + bluepill-stm32f030c8 \ + bluepill-stm32f103c8 \ + bluepill-stm32f103cb \ + calliope-mini \ + cc2650-launchpad \ + cc2650stk \ + hifive1 \ + hifive1b \ + i-nucleo-lrwan1 \ + im880b \ + lsn50 \ + maple-mini \ + microbit \ + nrf51dk \ + nrf51dongle \ + nrf6310 \ + nucleo-f030r8 \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-f070rb \ + nucleo-f072rb \ + nucleo-f103rb \ + nucleo-f302r8 \ + nucleo-f303k8 \ + nucleo-f334r8 \ + nucleo-l011k4 \ + nucleo-l031k6 \ + nucleo-l053r8 \ + nucleo-l073rz \ + opencm904 \ + samd10-xmini \ + saml10-xpro \ + saml11-xpro \ + slstk3400a \ + spark-core \ + stk3200 \ + stm32f030f4-demo \ + stm32f0discovery \ + stm32f7508-dk \ + stm32g0316-disco \ + stm32l0538-disco \ + stm32mp157c-dk2 \ + yunjia-nrf51822 \ + # diff --git a/examples/riot/examples_libcoap_server/README.md b/examples/riot/examples_libcoap_server/README.md new file mode 100644 index 00000000..ed6458c6 --- /dev/null +++ b/examples/riot/examples_libcoap_server/README.md @@ -0,0 +1,25 @@ +# libcoap server example + +This example shows how to configure a server to use libcoap + +## Fast configuration (Between RIOT instances): + +Preparing the logical interfaces: + + sudo ./../../dist/tools/tapsetup/tapsetup --create 2 + +## Server invocation +For the server: + + PORT=tap0 make term + coaps {stop|start} + +The server supports requests for + coap://[ip]/time?ticks + coap://[ip]/.well-known/core + +## Handling the static memory allocation + +libcoap for RIOT is using the `sys/memarray` module and therefore there +are certain limits. Said resources are defined in `libcoap/src/coap_mem.c`, +but can be overwritten at compile time. diff --git a/examples/riot/examples_libcoap_server/app.config b/examples/riot/examples_libcoap_server/app.config new file mode 100644 index 00000000..ecf27db3 --- /dev/null +++ b/examples/riot/examples_libcoap_server/app.config @@ -0,0 +1,6 @@ +CONFIG_LIBCOAP_SERVER_SUPPORT=y + +CONFIG_LIBCOAP_USE_PSK="secretPSK" + +CONFIG_KCONFIG_USEPKG_LIBCOAP=y +# Logging levels are defined in pkg/libcoap using Kconfig diff --git a/examples/riot/examples_libcoap_server/main.c b/examples/riot/examples_libcoap_server/main.c new file mode 100644 index 00000000..2692c0dc --- /dev/null +++ b/examples/riot/examples_libcoap_server/main.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * Copyright (C) 2018 Inria + * + * 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. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Example application for libcoap server + * + * @author Raul Fuentes <> + * + * @} + */ + +#include + +#include "shell.h" +#include "msg.h" + +#include "coap3/coap.h" + +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +extern int server_coap_init(int argc, char **argv); + +static const shell_command_t shell_commands[] = { + { "coaps", "Start a libcoap server", server_coap_init }, + { NULL, NULL, NULL } +}; + +int main(void) +{ + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("RIOT libcoap server testing implementation"); + + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should be never reached */ + return 0; +} diff --git a/examples/riot/examples_libcoap_server/server-coap.c b/examples/riot/examples_libcoap_server/server-coap.c new file mode 100644 index 00000000..3eafe820 --- /dev/null +++ b/examples/riot/examples_libcoap_server/server-coap.c @@ -0,0 +1,283 @@ +/* + * server-coap.c -- RIOT example + * + * Copyright (C) 2023 Jon Shallow + * + * SPDX-License-Identifier: BSD-2-Clause + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +#include "coap_config.h" +#include +#include "server-coap.h" + +#ifdef CONFIG_LIBCOAP_USE_PSK +#define COAP_USE_PSK CONFIG_LIBCOAP_USE_PSK +#else /* CONFIG_LIBCOAP_USE_PSK */ +#define COAP_USE_PSK NULL +#endif /* CONFIG_LIBCOAP_USE_PSK */ + +static volatile int running = 0; +static int quit; + +coap_context_t *main_coap_context; + +static coap_time_t clock_offset; +/* changeable clock base (see handle_put_time()) */ +static coap_time_t my_clock_base = 0; +static coap_resource_t *time_resource = NULL; /* just for testing */ + +#ifndef min +# define min(a,b) ((a) < (b) ? (a) : (b)) +#endif + +static void +hnd_get_time(coap_resource_t *resource, coap_session_t *session, + const coap_pdu_t *request, const coap_string_t *query, + coap_pdu_t *response) { + unsigned char buf[40]; + size_t len; + coap_tick_t now; + coap_tick_t t; + + (void)resource; + (void)session; + (void)request; + /* FIXME: return time, e.g. in human-readable by default and ticks + * when query ?ticks is given. */ + + /* if my_clock_base was deleted, we pretend to have no such resource */ + coap_pdu_set_code(response, my_clock_base ? COAP_RESPONSE_CODE_CONTENT : + COAP_RESPONSE_CODE_NOT_FOUND); + if (my_clock_base) + coap_add_option(response, COAP_OPTION_CONTENT_FORMAT, + coap_encode_var_safe(buf, sizeof(buf), + COAP_MEDIATYPE_TEXT_PLAIN), + buf); + + coap_add_option(response, COAP_OPTION_MAXAGE, + coap_encode_var_safe(buf, sizeof(buf), 0x01), buf); + + if (my_clock_base) { + + /* calculate current time */ + coap_ticks(&t); + now = my_clock_base + (t / COAP_TICKS_PER_SECOND); + + if (query != NULL + && coap_string_equal(query, coap_make_str_const("ticks"))) { + /* output ticks */ + len = snprintf((char *)buf, sizeof(buf), "%u", (unsigned int)now); + coap_add_data(response, len, buf); + } + } +} + +static void +init_coap_resources(coap_context_t *ctx) { + coap_resource_t *r; +#if 0 + r = coap_resource_init(NULL, 0, 0); + coap_register_handler(r, COAP_REQUEST_GET, hnd_get_index); + + coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0); + coap_add_attr(r, coap_make_str_const("title"), coap_make_str_const("\"General Info\""), 0); + coap_add_resource(ctx, r); +#endif + /* store clock base to use in /time */ + my_clock_base = clock_offset; + + r = coap_resource_init(coap_make_str_const("time"), 0); + if (!r) + goto error; + + coap_resource_set_get_observable(r, 1); + time_resource = r; + coap_register_handler(r, COAP_REQUEST_GET, hnd_get_time); +#if 0 + coap_register_handler(r, COAP_REQUEST_PUT, hnd_put_time); + coap_register_handler(r, COAP_REQUEST_DELETE, hnd_delete_time); +#endif + coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0); + /* coap_add_attr(r, coap_make_str_const("title"), coap_make_str_const("\"Internal Clock\""), 0); */ + coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("\"ticks\""), 0); + coap_add_attr(r, coap_make_str_const("if"), coap_make_str_const("\"clock\""), 0); + + coap_add_resource(ctx, r); +#if 0 +#ifndef WITHOUT_ASYNC + r = coap_resource_init(coap_make_str_const("async"), 0); + coap_register_handler(r, COAP_REQUEST_GET, hnd_get_async); + + coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0); + coap_add_resource(ctx, r); +#endif /* WITHOUT_ASYNC */ +#endif + + return; + error: + coap_log_crit("cannot create resource\n"); +} + +static int +init_coap_context_endpoints(const char *use_psk) { + coap_address_t listenaddress; + gnrc_netif_t *netif = gnrc_netif_iter(NULL); + ipv6_addr_t addr; + char addr_str[INET6_ADDRSTRLEN + 8]; + int scheme_hint_bits = 1 << COAP_URI_SCHEME_COAP; + coap_addr_info_t *info = NULL; + coap_addr_info_t *info_list = NULL; + coap_str_const_t local; + int have_ep = 0; + + /* Get the first address on the interface */ + if (gnrc_netif_ipv6_addrs_get(netif, &addr, sizeof(addr)) < 0) { + puts("Unable to get first address of the interface"); + return 0; + } + + coap_address_init(&listenaddress); + listenaddress.addr.sin6.sin6_family = AF_INET6; + memcpy(&listenaddress.addr.sin6.sin6_addr, &addr, + sizeof(listenaddress.addr.sin6.sin6_addr)); + coap_print_ip_addr(&listenaddress, addr_str, sizeof(addr_str)); + coap_log_info("Server IP [%s]\n", addr_str); + + main_coap_context = coap_new_context(NULL); + if (!main_coap_context) + return 0; + + if (use_psk && coap_dtls_is_supported()) { + coap_dtls_spsk_t setup_data; + + /* Need PSK set up before setting up endpoints */ + memset(&setup_data, 0, sizeof(setup_data)); + setup_data.version = COAP_DTLS_SPSK_SETUP_VERSION; + setup_data.psk_info.key.s = (const uint8_t *)use_psk; + setup_data.psk_info.key.length = strlen(use_psk); + coap_context_set_psk2(main_coap_context, &setup_data); + scheme_hint_bits |= 1 << COAP_URI_SCHEME_COAPS; + } + + local.s = (uint8_t *)addr_str; + local.length = strlen(addr_str); + info_list = coap_resolve_address_info(&local, COAP_DEFAULT_PORT, + COAPS_DEFAULT_PORT, + 0, + scheme_hint_bits); + for (info = info_list; info != NULL; info = info->next) { + coap_endpoint_t *ep; + + ep = coap_new_endpoint(main_coap_context, &info->addr, info->proto); + if (!ep) { + coap_log_warn("cannot create endpoint for proto %u\n", + info->proto); + } else { + have_ep = 1; + } + } + coap_free_address_info(info_list); + if (!have_ep) + return 0; + + return 1; +} + +void * +server_coap_run(void *arg) { + (void)arg; + + coap_set_log_level(COAP_MAX_LOGGING_LEVEL); + + if (!init_coap_context_endpoints(COAP_USE_PSK)) + goto fail; + + /* Limit the number of idle sessions to save RAM */ + coap_context_set_max_idle_sessions(main_coap_context, 2); + clock_offset = 1; /* Need a non-zero value */ + init_coap_resources(main_coap_context); + + coap_log_info("libcoap server ready\n"); + /* Keep on processing ... */ + while (quit == 0) { + coap_io_process(main_coap_context, 1000); + } +fail: + /* Clean up library usage so client can be run again */ + coap_free_context(main_coap_context); + main_coap_context = NULL; + coap_cleanup(); + running = 0; + quit = 0; + coap_log_info("libcoap server stopped\n"); + return NULL; +} + +static char server_stack[THREAD_STACKSIZE_MAIN + + THREAD_EXTRA_STACKSIZE_PRINTF]; + +static +void start_server(void) { + kernel_pid_t server_pid; + + /* Only one instance of the server */ + if (running) { + puts("Error: server already running"); + return; + } + + /* The server is initialized */ + server_pid = thread_create(server_stack, + sizeof(server_stack), + THREAD_PRIORITY_MAIN - 1, + THREAD_CREATE_STACKTEST, + server_coap_run, NULL, "libcoap_server"); + + /* Uncommon but better be sure */ + if (server_pid == EINVAL) { + puts("ERROR: Thread invalid"); + return; + } + + if (server_pid == EOVERFLOW) { + puts("ERROR: Thread overflow!"); + return; + } + + running = 1; + return; +} + +static +void stop_server(void) { + /* check if server is running at all */ + if (running == 0) { + puts("Error: libcoap server is not running"); + return; + } + + quit = 1; + + puts("Stopping server..."); +} + +void +server_coap_init(int argc, char **argv) { + if (argc < 2) { + printf("usage: %s start|stop\n", argv[0]); + return; + } + if (strcmp(argv[1], "start") == 0) { + start_server(); + } + else if (strcmp(argv[1], "stop") == 0) { + stop_server(); + } + else { + printf("Error: invalid command. Usage: %s start|stop\n", argv[0]); + } + return; +} diff --git a/examples/riot/examples_libcoap_server/server-coap.h b/examples/riot/examples_libcoap_server/server-coap.h new file mode 100644 index 00000000..44cf26ff --- /dev/null +++ b/examples/riot/examples_libcoap_server/server-coap.h @@ -0,0 +1,16 @@ +/* + * server-coap.h -- RIOT client example + * + * Copyright (C) 2023 Jon Shallow + * + * SPDX-License-Identifier: BSD-2-Clause + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +#include "coap_config.h" +#include + +/* Start up the CoAP Server */ +void server_coap_init(int argc, char **argv); diff --git a/examples/riot/pkg_libcoap/Kconfig b/examples/riot/pkg_libcoap/Kconfig new file mode 100644 index 00000000..8d3a4be5 --- /dev/null +++ b/examples/riot/pkg_libcoap/Kconfig @@ -0,0 +1,210 @@ +# Copyright (c) 2019 HAW Hamburg +# +# 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_LIBCOAP + bool "Configure libcoap" + depends on USEPKG_LIBCOAP + help + Configure libcoap package via Kconfig. + +if KCONFIG_USEPKG_LIBCOAP + +choice LIBCOAP_DEBUG_LEVEL + bool "Set CoAP debugging level" + default LIBCOAP_LOG_DEBUG + help + Set CoAP debugging level + + config LIBCOAP_LOG_EMERG + bool "Emergency" + config LIBCOAP_LOG_ALERT + bool "Alert" + config LIBCOAP_LOG_CRIT + bool "Critical" + config LIBCOAP_LOG_ERROR + bool "Error" + config LIBCOAP_LOG_WARNING + bool "Warning" + config LIBCOAP_LOG_NOTICE + bool "Notice" + config LIBCOAP_LOG_INFO + bool "Info" + config LIBCOAP_LOG_DEBUG + bool "Debug" + config LIBCOAP_LOG_OSCORE + bool "OSCORE" +endchoice + +config LIBCOAP_MAX_LOGGING_LEVEL + int + default 0 if LIBCOAP_LOG_EMERG + default 1 if LIBCOAP_LOG_ALERT + default 2 if LIBCOAP_LOG_CRIT + default 3 if LIBCOAP_LOG_ERROR + default 4 if LIBCOAP_LOG_WARNING + default 5 if LIBCOAP_LOG_NOTICE + default 6 if LIBCOAP_LOG_INFO + default 7 if LIBCOAP_LOG_DEBUG + default 8 if LIBCOAP_LOG_OSCORE + +config LIBCOAP_TCP_SUPPORT + bool "Enable TCP support within CoAP" + default n + help + Enable TCP functionality for CoAP. This is required if TLS sessions + are to be used. Note that RIOT TCP support also needs to be enabled. + + If this option is disabled, redundent CoAP TCP code is removed. + +config LIBCOAP_OSCORE_SUPPORT + bool "Enable OSCORE support within CoAP" + default n + help + Enable OSCORE functionality for CoAP. + + If this option is disabled, redundent CoAP OSCORE code is removed. + +config LIBCOAP_CLIENT_SUPPORT + bool "Enable Client functionality within CoAP" + default n + help + Enable client functionality (ability to make requests and receive + responses) for CoAP. If the server is going to act as a proxy, then + this needs to be enabled to support the ongoing session going to + the next hop. + + If this option is disabled, redundent CoAP client only code is + removed. + If both this option and LIBCOAP_SERVER_SUPPORT are disabled, then + both are automatically enabled for backwards compatability. + +config LIBCOAP_SERVER_SUPPORT + bool "Enable Server functionality within CoAP" + default n + help + Enable server functionality (ability to receive requests and send + responses) for CoAP. + + If this option is disabled, redundent CoAP server only code is + removed. + If both this option and LIBCOAP_CLIENT_SUPPORT are disabled, then + both are automatically enabled for backwards compatability. + +config LIBCOAP_MAX_STRING_SIZE + int "Max size of string memory allocation" + default 64 + help + The maximum size of a supported string. + +config LIBCOAP_MAX_STRINGS + int "Max number of strings supported" + default 16 + help + The maximum number of supported strings. + +config LIBCOAP_MAX_ENDPOINTS + int "Max number of endpoints supported" + default 4 + help + The maximum number of supported endpoints. + +config LIBCOAP_MAX_RESOURCES + int "Max number of resources supported" + default 8 + help + The maximum number of supported resources. + +config LIBCOAP_MAX_ATTRIBUTE_SIZE + int "Max size of attribute memory allocation" + default 16 + help + The maximum size of a supported attribute. + +config LIBCOAP_MAX_ATTRIBUTES + int "Max number of resource attributes supported" + default 32 + help + The maximum number of supported resource attributes. + +config LIBCOAP_MAX_PACKETS + int "Max number of packets supported" + default 4 + help + The maximum number of supported packets. + +config LIBCOAP_MAX_NODES + int "Max number of nodes supported" + default 16 + help + The maximum number of supported nodes. + +config LIBCOAP_MAX_CONTEXTS + int "Max number of contexts supported" + default 1 + help + The maximum number of supported contexts. + +config LIBCOAP_MAX_PDUS + int "Max number of PDUs supported" + default 16 + help + The maximum number of supported PDUs. + +config LIBCOAP_MAX_DTLS_SESSIONS + int "Max number of DTLS sessions supported" + default 2 + help + The maximum number of supported DTLS sessions. + +config LIBCOAP_MAX_SESSIONS + int "Max number of sessions supported" + default 4 + help + The maximum number of supported sessions. + +config LIBCOAP_MAX_OPTION_SIZE + int "Max size of option memory allocation" + default 16 + help + The maximum size of a supported options. + +config LIBCOAP_MAX_OPTIONS + int "Max number of options supported" + default 16 + help + The maximum number of supported options. + +config LIBCOAP_MAX_CACHE_KEYS + int "Max number of cache keys supported" + default 2 + help + The maximum number of supported cache keys. + +config LIBCOAP_MAX_CACHE_ENTRIES + int "Max number of cache entries supported" + default 2 + help + The maximum number of supported cache entries. + +config LIBCOAP_MAX_LG_CRCVS + int "Max number of client large receives supported" + default 1 + help + The maximum number of supported client large receives. + +config LIBCOAP_MAX_LG_SRCVS + int "Max number of server large receives supported" + default 2 + help + The maximum number of supported server large receives. + +config LIBCOAP_MAX_LG_XMITS + int "Max number of large transmits supported" + default 2 + help + The maximum number of supported large trqnsmits. + +endif # KCONFIG_USEPKG_LIBCOAP diff --git a/examples/riot/pkg_libcoap/Makefile b/examples/riot/pkg_libcoap/Makefile new file mode 100644 index 00000000..9950bcd9 --- /dev/null +++ b/examples/riot/pkg_libcoap/Makefile @@ -0,0 +1,15 @@ +PKG_NAME=libcoap +PKG_URL=https://github.com/mrdeep1/libcoap +PKG_VERSION=3ce58786c6a87176afc0cea2148cc8888da5153a +PKG_LICENSE=BSD-2-Clause + +LIBCOAP_BUILD_DIR=$(BINDIR)/pkg/$(PKG_NAME) +LIBCOAP_SOURCE_DIR=$(RIOTBASE)/build/pkg/$(PKG_NAME) +LIBCOAP_INCLUDE_DIR=$(RIOTBASE)/build/pkg/$(PKG_NAME)/include/coap3 + +include $(RIOTBASE)/pkg/pkg.mk + +all: + @cp $(LIBCOAP_SOURCE_DIR)/coap_config.h.riot $(LIBCOAP_SOURCE_DIR)/coap_config.h + @cp $(LIBCOAP_INCLUDE_DIR)/coap.h.riot $(LIBCOAP_INCLUDE_DIR)/coap.h + "$(MAKE)" -C $(LIBCOAP_SOURCE_DIR)/src -f $(CURDIR)/Makefile.libcoap diff --git a/examples/riot/pkg_libcoap/Makefile.dep b/examples/riot/pkg_libcoap/Makefile.dep new file mode 100644 index 00000000..5c70d309 --- /dev/null +++ b/examples/riot/pkg_libcoap/Makefile.dep @@ -0,0 +1,10 @@ +USEMODULE += posix_sockets +USEMODULE += posix_headers +USEMODULE += posix_inet +USEMODULE += posix_select +USEMODULE += sock_udp +CFLAGS += -DPOSIX_SETSOCKOPT + +ifneq (,$(filter libcoap,$(USEPKG))) + USEMODULE += libcoap +endif diff --git a/examples/riot/pkg_libcoap/Makefile.include b/examples/riot/pkg_libcoap/Makefile.include new file mode 100644 index 00000000..a51fce2d --- /dev/null +++ b/examples/riot/pkg_libcoap/Makefile.include @@ -0,0 +1,2 @@ +INCLUDES += -I$(PKGDIRBASE)/libcoap \ + -I$(PKGDIRBASE)/libcoap/include diff --git a/examples/riot/pkg_libcoap/Makefile.libcoap b/examples/riot/pkg_libcoap/Makefile.libcoap new file mode 100644 index 00000000..4e42b634 --- /dev/null +++ b/examples/riot/pkg_libcoap/Makefile.libcoap @@ -0,0 +1,40 @@ +MODULE := libcoap + +SRC := coap_address.c \ + coap_asn1.c \ + coap_async.c \ + block.c \ + coap_cache.c \ + coap_debug.c \ + coap_dtls.c \ + coap_encode.c \ + coap_event.c \ + coap_gnutls.c\ + coap_hashkey.c \ + coap_io.c \ + coap_io_riot.c\ + coap_layers.c\ + coap_mbedtls.c\ + coap_mem.c \ + net.c \ + coap_netif.c \ + coap_notls.c \ + coap_openssl.c\ + coap_option.c \ + coap_oscore.c \ + pdu.c \ + coap_prng.c \ + resource.c \ + coap_session.c \ + coap_str.c \ + coap_subscribe.c \ + coap_tcp.c \ + coap_tinydtls.c \ + coap_uri.c \ + coap_ws.c + +ifneq (,$(filter libcoap_tinydtls,$(USEMODULE))) +CFLAGS += -DHAVE_LIBTINYDTLS +endif + +include $(RIOTBASE)/Makefile.base diff --git a/include/coap3/coap.h.riot b/include/coap3/coap.h.riot new file mode 100644 index 00000000..f49d5c64 --- /dev/null +++ b/include/coap3/coap.h.riot @@ -0,0 +1,67 @@ +/* + * coap.h -- main header file for CoAP stack of libcoap (RIOT) + * + * Copyright (C) 2010-2012,2015-2017 Olaf Bergmann + * 2015 Carsten Schoenert + * + * SPDX-License-Identifier: BSD-2-Clause + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +#ifndef COAP_H_ +#define COAP_H_ + +/* Define the address where bug reports for libcoap should be sent. */ +#define LIBCOAP_PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net" + +/* Define the full name of libcoap. */ +#define LIBCOAP_PACKAGE_NAME "libcoap" + +/* Define the full name and version of libcoap. */ +#define LIBCOAP_PACKAGE_STRING "libcoap 4.3.1" + +/* Define the home page for libcoap. */ +#define LIBCOAP_PACKAGE_URL "https://libcoap.net/" + +/* Define the version of libcoap this file belongs to. */ +#define LIBCOAP_PACKAGE_VERSION "4.3.1" + +/* Define the numeric version identifier for libcoap */ +#define LIBCOAP_VERSION (4003001U) + +#ifdef __cplusplus +extern "C" { +#endif + +#include "libcoap.h" + +#include "coap_forward_decls.h" +#include "coap_address.h" +#include "coap_async.h" +#include "block.h" +#include "coap_cache.h" +#include "coap_debug.h" +#include "coap_dtls.h" +#include "coap_encode.h" +#include "coap_event.h" +#include "coap_io.h" +#include "coap_mem.h" +#include "coap_net.h" +#include "coap_option.h" +#include "coap_oscore.h" +#include "pdu.h" +#include "coap_prng.h" +#include "resource.h" +#include "coap_str.h" +#include "coap_subscribe.h" +#include "coap_time.h" +#include "coap_uri.h" +#include "coap_ws.h" + +#ifdef __cplusplus +} +#endif + +#endif /* COAP_H_ */ diff --git a/include/coap3/coap.h.riot.in b/include/coap3/coap.h.riot.in new file mode 100644 index 00000000..cdf3ed20 --- /dev/null +++ b/include/coap3/coap.h.riot.in @@ -0,0 +1,67 @@ +/* + * coap.h -- main header file for CoAP stack of libcoap (RIOT) + * + * Copyright (C) 2010-2012,2015-2017 Olaf Bergmann + * 2015 Carsten Schoenert + * + * SPDX-License-Identifier: BSD-2-Clause + * + * This file is part of the CoAP library libcoap. Please see README for terms + * of use. + */ + +#ifndef COAP_H_ +#define COAP_H_ + +/* Define the address where bug reports for libcoap should be sent. */ +#define LIBCOAP_PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" + +/* Define the full name of libcoap. */ +#define LIBCOAP_PACKAGE_NAME "@PACKAGE_NAME@" + +/* Define the full name and version of libcoap. */ +#define LIBCOAP_PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define the home page for libcoap. */ +#define LIBCOAP_PACKAGE_URL "@PACKAGE_URL@" + +/* Define the version of libcoap this file belongs to. */ +#define LIBCOAP_PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Define the numeric version identifier for libcoap */ +#define LIBCOAP_VERSION (@LIBCOAP_VERSION@U) + +#ifdef __cplusplus +extern "C" { +#endif + +#include "libcoap.h" + +#include "coap_forward_decls.h" +#include "coap_address.h" +#include "coap_async.h" +#include "block.h" +#include "coap_cache.h" +#include "coap_debug.h" +#include "coap_dtls.h" +#include "coap_encode.h" +#include "coap_event.h" +#include "coap_io.h" +#include "coap_mem.h" +#include "coap_net.h" +#include "coap_option.h" +#include "coap_oscore.h" +#include "pdu.h" +#include "coap_prng.h" +#include "resource.h" +#include "coap_str.h" +#include "coap_subscribe.h" +#include "coap_time.h" +#include "coap_uri.h" +#include "coap_ws.h" + +#ifdef __cplusplus +} +#endif + +#endif /* COAP_H_ */ diff --git a/include/coap3/coap_debug.h b/include/coap3/coap_debug.h index 4cf69329..23bce54e 100644 --- a/include/coap3/coap_debug.h +++ b/include/coap3/coap_debug.h @@ -136,6 +136,7 @@ COAP_STATIC_INLINE void coap_no_log(void) { } * * In a future update, they will get removed. */ +#if !defined(RIOT_VERSION) #ifndef LOG_EMERG # define LOG_EMERG COAP_LOG_EMERG #endif @@ -160,6 +161,7 @@ COAP_STATIC_INLINE void coap_no_log(void) { } #ifndef LOG_DEBUG # define LOG_DEBUG COAP_LOG_DEBUG #endif +#endif /* ! RIOT_VERSION */ /** * Get the current logging level. diff --git a/include/coap3/coap_net.h b/include/coap3/coap_net.h index be6de1a1..63fe047d 100644 --- a/include/coap3/coap_net.h +++ b/include/coap3/coap_net.h @@ -620,7 +620,6 @@ coap_mcast_per_resource(coap_context_t *context); */ int coap_io_process(coap_context_t *ctx, uint32_t timeout_ms); -#ifndef RIOT_VERSION /** * The main message processing loop with additional fds for internal select. * @@ -651,7 +650,6 @@ int coap_io_process(coap_context_t *ctx, uint32_t timeout_ms); int coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms, int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds); -#endif /* !RIOT_VERSION */ /** * Check to see if there is any i/o pending for the @p context. diff --git a/include/coap3/coap_time.h b/include/coap3/coap_time.h index 47d11367..591c6d7c 100644 --- a/include/coap3/coap_time.h +++ b/include/coap3/coap_time.h @@ -92,7 +92,7 @@ COAP_STATIC_INLINE uint64_t coap_ticks_to_rt_us(coap_tick_t t) { #ifdef XTIMER_HZ #define COAP_TICKS_PER_SECOND (XTIMER_HZ) #else /* XTIMER_HZ */ -#define COAP_TICKS_PER_SECOND (XTIMER_HZ_BASE) +#define COAP_TICKS_PER_SECOND (1000000U) #endif /* XTIMER_HZ */ typedef uint64_t coap_tick_t; @@ -102,7 +102,11 @@ typedef uint32_t coap_time_t; static inline void coap_clock_init(void) {} static inline void coap_ticks(coap_tick_t *t) { +#ifdef MODULE_ZTIMER64_XTIMER_COMPAT *t = xtimer_now_usec64(); +#else /* MODULE_ZTIMER64_XTIMER_COMPAT */ + *t = xtimer_now_usec(); +#endif /* MODULE_ZTIMER64_XTIMER_COMPAT */ } static inline coap_time_t coap_ticks_to_rt(coap_tick_t t) { diff --git a/scripts/github_dist.sh b/scripts/github_dist.sh index c2963b14..ce3acb16 100755 --- a/scripts/github_dist.sh +++ b/scripts/github_dist.sh @@ -27,6 +27,10 @@ if test $err = 0 -a "x$ARCHIVE" != "x"; then make -C $DIR/examples/contiki err=$? fi + if [ $err = 0 ] ; then + make -C $DIR/examples/riot + err=$? + fi fi exit $err diff --git a/src/coap_address.c b/src/coap_address.c index f75a33ff..b8f33148 100644 --- a/src/coap_address.c +++ b/src/coap_address.c @@ -113,11 +113,10 @@ void coap_address_init(coap_address_t *addr) { #endif } -#ifndef WITH_CONTIKI int coap_address_set_unix_domain(coap_address_t *addr, const uint8_t *host, size_t host_len) { -#if !defined(WITH_LWIP) +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) && !defined(RIOT_VERSION) size_t i; size_t ofs = 0; @@ -139,14 +138,15 @@ coap_address_set_unix_domain(coap_address_t *addr, else addr->addr.cun.sun_path[ofs-1] = '\000'; return 1; -#else /* WITH_LWIP */ +#else /* WITH_LWIP || WITH_CONTIKI || RIOT_VERSION */ (void)addr; (void)host; (void)host_len; return 0; -#endif /* WITH_LWIP */ +#endif /* WITH_LWIP || WITH_CONTIKI || RIOT_VERSION */ } +#if !defined(WITH_CONTIKI) static void update_port(coap_address_t *addr, uint16_t port, uint16_t default_port) { if (port == 0) @@ -233,7 +233,7 @@ coap_resolve_address_info(const coap_str_const_t *server, uint16_t secure_port, int ai_hints_flags, int scheme_hint_bits) { - +#if !defined(RIOT_VERSION) struct addrinfo *res, *ainfo; struct addrinfo hints; static char addrstr[256]; @@ -242,9 +242,9 @@ coap_resolve_address_info(const coap_str_const_t *server, coap_addr_info_t *info_prev = NULL; coap_addr_info_t *info_list = NULL; coap_uri_scheme_t scheme; - coap_proto_t proto; + coap_proto_t proto = 0; -#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) +#if !defined(WITH_LWIP) if (server && coap_host_is_unix_domain(server)) { /* There can only be one unique filename entry for AF_UNIX */ if (server->length >= COAP_UNIX_PATH_MAX) { @@ -318,7 +318,7 @@ coap_resolve_address_info(const coap_str_const_t *server, } return info; } -#endif /* ! WITH_LWIP && ! WITH_CONTIKI */ +#endif /* ! WITH_LWIP */ memset(addrstr, 0, sizeof(addrstr)); if (server && server->length) @@ -446,7 +446,7 @@ coap_resolve_address_info(const coap_str_const_t *server, #if !defined(WITH_LWIP) info->addr.size = (socklen_t)ainfo->ai_addrlen; memcpy(&info->addr.addr, ainfo->ai_addr, ainfo->ai_addrlen); -#else /* defined(WITH_LWIP) */ +#else /* WITH_LWIP */ memset(&info->addr, 0, sizeof(info->addr)); switch (ainfo->ai_family) { struct sockaddr_in *sock4; @@ -455,22 +455,18 @@ coap_resolve_address_info(const coap_str_const_t *server, sock4 = (struct sockaddr_in *)ainfo->ai_addr; info->addr.port = ntohs(sock4->sin_port); memcpy(&info->addr.addr, &sock4->sin_addr, 4); -#ifdef WITH_LWIP info->addr.addr.type = IPADDR_TYPE_V4; -#endif /* WITH_LWIP */ break; case AF_INET6: sock6 = (struct sockaddr_in6 *)ainfo->ai_addr; info->addr.port = ntohs(sock6->sin6_port); memcpy(&info->addr.addr, &sock6->sin6_addr, 16); -#ifdef WITH_LWIP info->addr.addr.type = IPADDR_TYPE_V6; -#endif /* WITH_LWIP */ break; default: ; } -#endif /* defined(WITH_LWIP) */ +#endif /* WITH_LWIP */ switch (scheme) { case COAP_URI_SCHEME_COAP: update_port(&info->addr, port, COAP_DEFAULT_PORT); @@ -510,6 +506,116 @@ coap_resolve_address_info(const coap_str_const_t *server, freeaddrinfo(res); return info_list; +#else /* RIOT_VERSION */ +#include "net/utils.h" + ipv6_addr_t addr_ipv6; + netif_t *netif = NULL; + coap_addr_info_t *info = NULL; + coap_addr_info_t *info_prev = NULL; + coap_addr_info_t *info_list = NULL; + coap_uri_scheme_t scheme; + coap_proto_t proto = 0; + (void)ai_hints_flags; + + if (netutils_get_ipv6(&addr_ipv6, &netif, (const char *)server->s) >= 0) { + for (scheme = 0; scheme < COAP_URI_SCHEME_LAST; scheme++) { + if (scheme_hint_bits & (1 << scheme)) { + switch (scheme) { + case COAP_URI_SCHEME_COAP: + proto = COAP_PROTO_UDP; + break; + case COAP_URI_SCHEME_COAPS: + if (!coap_dtls_is_supported()) + continue; + proto = COAP_PROTO_DTLS; + break; + case COAP_URI_SCHEME_COAP_TCP: + if (!coap_tcp_is_supported()) + continue; + proto = COAP_PROTO_TCP; + break; + case COAP_URI_SCHEME_COAPS_TCP: + if (!coap_tls_is_supported()) + continue; + proto = COAP_PROTO_TLS; + break; + case COAP_URI_SCHEME_HTTP: + if (!coap_tcp_is_supported()) + continue; + proto = COAP_PROTO_NONE; + break; + case COAP_URI_SCHEME_HTTPS: + if (!coap_tls_is_supported()) + continue; + proto = COAP_PROTO_NONE; + break; + case COAP_URI_SCHEME_COAP_WS: + if (!coap_ws_is_supported()) + continue; + proto = COAP_PROTO_WS; + break; + case COAP_URI_SCHEME_COAPS_WS: + if (!coap_wss_is_supported()) + continue; + proto = COAP_PROTO_WSS; + break; + case COAP_URI_SCHEME_LAST: + default: + continue; + } + + info = coap_malloc_type(COAP_STRING, sizeof(coap_addr_info_t)); + if (info == NULL) { + /* malloc failure - return what we have so far */ + return info_list; + } + info->next = NULL; + /* Need to return in same order as getaddrinfo() */ + if (!info_prev) { + info_list = info; + info_prev = info; + } else { + info_prev->next = info; + info_prev = info; + } + + info->scheme = scheme; + info->proto = proto; + coap_address_init(&info->addr); + info->addr.size = sizeof(struct sockaddr_in6); + info->addr.addr.sin6.sin6_family = AF_INET6; + memcpy(&info->addr.addr.sin6.sin6_addr, &addr_ipv6, + sizeof(info->addr.addr.sin6.sin6_addr)); + info->addr.addr.sin6.sin6_scope_id = (uint32_t)netif_get_id(netif); + switch (scheme) { + case COAP_URI_SCHEME_COAP: + update_port(&info->addr, port, COAP_DEFAULT_PORT); + break; + case COAP_URI_SCHEME_COAPS: + update_port(&info->addr, secure_port, COAPS_DEFAULT_PORT); + break; + case COAP_URI_SCHEME_COAP_TCP: + update_port(&info->addr, port, COAP_DEFAULT_PORT); + break; + case COAP_URI_SCHEME_COAPS_TCP: + update_port(&info->addr, secure_port, COAPS_DEFAULT_PORT); + break; + case COAP_URI_SCHEME_HTTP: + update_port(&info->addr, port, 80); + break; + case COAP_URI_SCHEME_HTTPS: + update_port(&info->addr, secure_port, 443); + break; + case COAP_URI_SCHEME_LAST: + default: + break; + } + } + } + return info_list; + } + return NULL; +#endif /* RIOT_VERSION */ } #endif /* !WITH_CONTIKI */ diff --git a/src/coap_io.c b/src/coap_io.c index cbc291b8..3f7089cd 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -94,7 +94,9 @@ coap_socket_bind_udp(coap_socket_t *sock, coap_address_t *bound_addr) { #ifndef RIOT_VERSION int on = 1, off = 0; -#endif /* RIOT_VERSION */ +#else /* ! RIOT_VERSION */ + struct timeval timeout = {0, 0}; +#endif /* ! RIOT_VERSION */ #ifdef _WIN32 u_long u_on = 1; #endif @@ -150,7 +152,13 @@ coap_socket_bind_udp(coap_socket_t *sock, coap_log_alert("coap_socket_bind_udp: unsupported sa_family\n"); break; } -#endif /* RIOT_VERSION */ +#else /* ! RIOT_VERSION */ + if (setsockopt(sock->fd, SOL_SOCKET, SO_RCVTIMEO, OPTVAL_T(&timeout), + (socklen_t)sizeof(timeout)) == COAP_SOCKET_ERROR) + coap_log_alert( + "coap_socket_bind_udp: setsockopt SO_RCVTIMEO: %s\n", + coap_socket_strerror()); +#endif /* ! RIOT_VERSION */ if (bind(sock->fd, &listen_addr->addr.sa, listen_addr->addr.sa.sa_family == AF_INET ? @@ -168,6 +176,14 @@ coap_socket_bind_udp(coap_socket_t *sock, coap_socket_strerror()); goto error; } +#if defined(RIOT_VERSION) && defined(COAP_SERVER_SUPPORT) + if (sock->endpoint && + bound_addr->addr.sa.sa_family == AF_INET6) { + bound_addr->addr.sin6.sin6_scope_id = + listen_addr->addr.sin6.sin6_scope_id; + bound_addr->addr.sin6.sin6_flowinfo = 0; + } +#endif /* RIOT_VERSION && COAP_SERVER_SUPPORT */ return 1; @@ -187,12 +203,16 @@ coap_socket_connect_udp(coap_socket_t *sock, #ifndef RIOT_VERSION int on = 1; int off = 0; -#endif /* RIOT_VERSION */ +#else /* ! RIOT_VERSION */ + struct timeval timeout = {0, 0}; +#endif /* ! RIOT_VERSION */ #ifdef _WIN32 u_long u_on = 1; #endif coap_address_t connect_addr; +#if !defined(RIOT_VERSION) int is_mcast = coap_is_mcast(server); +#endif /* !defined(RIOT_VERSION) */ coap_address_copy(&connect_addr, server); sock->flags &= ~(COAP_SOCKET_CONNECTED | COAP_SOCKET_MULTICAST); @@ -206,10 +226,11 @@ coap_socket_connect_udp(coap_socket_t *sock, #ifndef RIOT_VERSION #ifdef _WIN32 - if (ioctlsocket(sock->fd, FIONBIO, &u_on) == COAP_SOCKET_ERROR) { + if (ioctlsocket(sock->fd, FIONBIO, &u_on) == COAP_SOCKET_ERROR) #else - if (ioctl(sock->fd, FIONBIO, &on) == COAP_SOCKET_ERROR) { + if (ioctl(sock->fd, FIONBIO, &on) == COAP_SOCKET_ERROR) #endif + { coap_log_warn("coap_socket_connect_udp: ioctl FIONBIO: %s\n", coap_socket_strerror()); } @@ -234,8 +255,9 @@ coap_socket_connect_udp(coap_socket_t *sock, case AF_UNIX: break; default: - coap_log_alert("coap_socket_connect_udp: unsupported sa_family\n"); - break; + coap_log_alert("coap_socket_connect_udp: unsupported sa_family %d\n", + connect_addr.addr.sa.sa_family); + goto error;; } if (local_if && local_if->addr.sa.sa_family) { @@ -265,6 +287,7 @@ coap_socket_connect_udp(coap_socket_t *sock, } /* special treatment for sockets that are used for multicast communication */ +#if !defined(RIOT_VERSION) if (is_mcast) { if (!(local_if && local_if->addr.sa.sa_family)) { /* Bind to a (unused) port to simplify logging */ @@ -291,6 +314,30 @@ coap_socket_connect_udp(coap_socket_t *sock, sock->flags |= COAP_SOCKET_MULTICAST; return 1; } +#else /* defined(RIOT_VERSION) */ + if (!(local_if && local_if->addr.sa.sa_family)) { + /* Bind to a (unused) port to simplify logging */ + coap_address_t bind_addr; + + coap_address_init(&bind_addr); + bind_addr.addr.sa.sa_family = connect_addr.addr.sa.sa_family; + if (bind_addr.addr.sa.sa_family == AF_INET6) + bind_addr.addr.sin6.sin6_scope_id = connect_addr.addr.sin6.sin6_scope_id; + if (bind(sock->fd, &bind_addr.addr.sa, + bind_addr.addr.sa.sa_family == AF_INET ? + (socklen_t)sizeof(struct sockaddr_in) : + (socklen_t)bind_addr.size) == COAP_SOCKET_ERROR) { + coap_log_warn("coap_socket_connect_udp: bind: %s\n", + coap_socket_strerror()); + goto error; + } + } + if (setsockopt(sock->fd, SOL_SOCKET, SO_RCVTIMEO, OPTVAL_T(&timeout), + (socklen_t)sizeof(timeout)) == COAP_SOCKET_ERROR) + coap_log_alert( + "coap_socket_bind_udp: setsockopt SO_RCVTIMEO: %s\n", + coap_socket_strerror()); +#endif /* defined(RIOT_VERSION) */ if (connect(sock->fd, &connect_addr.addr.sa, connect_addr.size) == COAP_SOCKET_ERROR) { if (connect_addr.addr.sa.sa_family == AF_UNIX) { @@ -298,8 +345,8 @@ coap_socket_connect_udp(coap_socket_t *sock, connect_addr.addr.cun.sun_path, coap_socket_strerror()); } else { - coap_log_warn("coap_socket_connect_udp: connect: %s\n", - coap_socket_strerror()); + coap_log_warn("coap_socket_connect_udp: connect: %s (%d)\n", + coap_socket_strerror(), connect_addr.addr.sa.sa_family); } goto error; } @@ -856,7 +903,7 @@ coap_packet_get_memmapped(coap_packet_t *packet, unsigned char **address, size_t *length = packet->length; } -#if !defined(RIOT_VERSION) && !defined(WITH_LWIP) && !defined(WITH_CONTIKI) +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) /* * dgram * return +ve Number of bytes written. @@ -955,6 +1002,14 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) { len = recvfrom(sock->fd, (void *)packet->payload, COAP_RXBUFFER_SIZE, 0, &packet->addr_info.remote.addr.sa, &packet->addr_info.remote.size); +#if defined(RIOT_VERSION) && defined(COAP_SERVER_SUPPORT) + if (sock->endpoint && + packet->addr_info.remote.addr.sa.sa_family == AF_INET6) { + packet->addr_info.remote.addr.sin6.sin6_scope_id = + sock->endpoint->bind_addr.addr.sin6.sin6_scope_id; + packet->addr_info.remote.addr.sin6.sin6_flowinfo = 0; + } +#endif /* RIOT_VERSION && COAP_SERVER_SUPPORT */ #endif /* ! HAVE_STRUCT_CMSGHDR */ if (len < 0) { @@ -1050,6 +1105,14 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) { coap_log_debug("Cannot determine local port\n"); goto error; } +#if defined(RIOT_VERSION) && defined(COAP_SERVER_SUPPORT) + if (sock->endpoint && + packet->addr_info.local.addr.sa.sa_family == AF_INET6) { + packet->addr_info.local.addr.sin6.sin6_scope_id = + sock->endpoint->bind_addr.addr.sin6.sin6_scope_id; + packet->addr_info.local.addr.sin6.sin6_flowinfo = 0; + } +#endif /* RIOT_VERSION && COAP_SERVER_SUPPORT */ #endif /* ! HAVE_STRUCT_CMSGHDR */ } } @@ -1059,7 +1122,7 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) { error: return -1; } -#endif /* ! RIOT_VERSION && ! WITH_LWIP && ! WITH_CONTIKI */ +#endif /* ! WITH_LWIP && ! WITH_CONTIKI */ unsigned int coap_io_prepare_epoll(coap_context_t *ctx, coap_tick_t now) { @@ -1344,7 +1407,7 @@ release_2: return (unsigned int)((timeout * 1000 + COAP_TICKS_PER_SECOND - 1) / COAP_TICKS_PER_SECOND); } -#if !defined(RIOT_VERSION) && !defined(WITH_LWIP) && !defined(CONTIKI) +#if !defined(WITH_LWIP) && !defined(CONTIKI) int coap_io_process(coap_context_t *ctx, uint32_t timeout_ms) { return coap_io_process_with_fds(ctx, timeout_ms, 0, NULL, NULL, NULL); @@ -1529,7 +1592,7 @@ coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms, return (int)(((now - before) * 1000) / COAP_TICKS_PER_SECOND); } -#endif /* ! RIOT_VERSION && ! WITH_LWIP && ! WITH_CONTIKI */ +#endif /* ! WITH_LWIP && ! WITH_CONTIKI */ /* * return 1 I/O pending diff --git a/src/coap_io_riot.c b/src/coap_io_riot.c index 8a221ffc..b112699b 100644 --- a/src/coap_io_riot.c +++ b/src/coap_io_riot.c @@ -42,7 +42,7 @@ #include "net/gnrc/netreg.h" #include "net/udp.h" -#include "coap_riot.h" +#include "coap3/coap_riot.h" /* * dgram @@ -72,225 +72,9 @@ coap_socket_send(coap_socket_t *sock, return bytes_written; } -static udp_hdr_t * -get_udp_header(gnrc_pktsnip_t *pkt) { - gnrc_pktsnip_t *udp = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_UDP); - return udp ? (udp_hdr_t *)udp->data : NULL; -} - -/* - * dgram - * return +ve Number of bytes written. - * -1 Error error in errno). - * -2 ICMP error response - */ -ssize_t -coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) { - size_t len; - ipv6_hdr_t *ipv6_hdr; - /* The GNRC API currently only supports UDP. */ - gnrc_pktsnip_t *udp; - udp_hdr_t *udp_hdr; - const gnrc_nettype_t type = GNRC_NETTYPE_UDP; - - assert(sock); - assert(packet); - - if ((sock->flags & COAP_SOCKET_CAN_READ) == 0) { - coap_log_debug("coap_socket_recv: COAP_SOCKET_CAN_READ not set\n"); - return -1; - } else { - /* clear has-data flag */ - sock->flags &= ~COAP_SOCKET_CAN_READ; - } - - /* Search for the transport header in the packet received from the - * network interface driver. */ - udp = gnrc_pktsnip_search_type(sock->pkt, type); - ipv6_hdr = gnrc_ipv6_get_header(sock->pkt); - - if (!ipv6_hdr || !udp || !(udp_hdr = (udp_hdr_t *)udp->data)) { - coap_log_debug("no UDP header found in packet\n"); - return -EFAULT; - } - udp_hdr_print(udp_hdr); - - len = (size_t)gnrc_pkt_len_upto(sock->pkt, type) - sizeof(udp_hdr_t); - coap_log_debug("coap_socket_recv: recvfrom got %zd bytes\n", len); - if (len > COAP_RXBUFFER_SIZE) { - coap_log_warn("packet exceeds buffer size, truncated\n"); - len = COAP_RXBUFFER_SIZE; - } - packet->ifindex = sock->fd; - - assert(sizeof(struct in6_addr) == sizeof(ipv6_addr_t)); - packet->addr_info.remote.size = sizeof(struct sockaddr_in6); - memset(&packet->addr_info.remote.addr, 0, - sizeof(packet->addr_info.remote.addr)); - packet->addr_info.remote.addr.sin6.sin6_family = AF_INET6; - memcpy(&packet->addr_info.remote.addr.sin6.sin6_addr, - &ipv6_hdr->src, sizeof(ipv6_addr_t)); - memcpy(&packet->addr_info.remote.addr.sin6.sin6_port, - &udp_hdr->src_port, sizeof(udp_hdr->src_port)); - - packet->addr_info.local.size = sizeof(struct sockaddr_in6); - memset(&packet->addr_info.local.addr, 0, sizeof(packet->addr_info.local.addr)); - packet->addr_info.local.addr.sin6.sin6_family = AF_INET6; - memcpy(&packet->addr_info.local.addr.sin6.sin6_addr, - &ipv6_hdr->dst, sizeof(ipv6_addr_t)); - memcpy(&packet->addr_info.local - .addr.sin6.sin6_port, &udp_hdr->dst_port, sizeof(udp_hdr->src_port)); - - packet->ifindex = sock->fd; - packet->length = (len > 0) ? len : 0; - memcpy(packet->payload, (uint8_t*)udp_hdr + sizeof(udp_hdr_t), len); - if (COAP_LOG_DEBUG <= coap_get_log_level()) { - unsigned char addr_str[INET6_ADDRSTRLEN + 8]; - - if (coap_print_addr(&packet->addr_info.remote, addr_str, INET6_ADDRSTRLEN + 8)) { - coap_log_debug("received %zd bytes from %s\n", len, addr_str); - } - } - - return len; -} - static msg_t _msg_q[LIBCOAP_MSG_QUEUE_SIZE]; void coap_riot_startup(void) { msg_init_queue(_msg_q, LIBCOAP_MSG_QUEUE_SIZE); } - -/** - * Returns the port of @p addr in network byte order or 0 on error. - */ -static uint16_t -get_port(const coap_address_t *addr) { - if (addr) { - switch (addr->addr.sa.sa_family) { - case AF_INET: return addr->addr.sin.sin_port; - case AF_INET6: return addr->addr.sin6.sin6_port; - default: - ; - } - } - return 0; -} - -static coap_socket_t * -find_socket(coap_fd_t fd, coap_socket_t *sockets[], unsigned int num_sockets) { - for (unsigned int i = 0; i < num_sockets; i++) { - if (fd == sockets[i]->fd) - return sockets[i]; - } - return NULL; -} - -static bool -address_equals(const coap_address_t *a, const ipv6_addr_t *b) { - assert(a); - assert(b); - return IN6_IS_ADDR_UNSPECIFIED(&a->addr.sin6.sin6_addr) || - (memcmp(&a->addr.sin6.sin6_addr, b->u8, sizeof(struct in6_addr)) == 0); -} - -int -coap_io_process(coap_context_t *ctx, uint32_t timeout_ms) { - coap_tick_t before, now; - coap_socket_t *sockets[LIBCOAP_MAX_SOCKETS]; - unsigned int num_sockets = 0, timeout; - gnrc_netreg_entry_t coap_reg = - GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, thread_getpid()); - msg_t msg; - bool found_port = false; - - coap_ticks(&before); - - timeout = - coap_io_prepare_io(ctx, sockets, ARRAY_SIZE(sockets), &num_sockets, before); - if (timeout == 0 || timeout_ms < timeout) - timeout = timeout_ms; - - if (num_sockets > 0) { - gnrc_netreg_register(GNRC_NETTYPE_UDP, &coap_reg); - } - - if (timeout == 0 || timeout_ms < timeout) - timeout = timeout_ms; - - xtimer_msg_receive_timeout(&msg, timeout_ms * US_PER_SEC); - switch (msg.type) { - case GNRC_NETAPI_MSG_TYPE_RCV: { - coap_log_debug("coap_run_once: GNRC_NETAPI_MSG_TYPE_RCV\n"); - - coap_session_t *s, *rtmp; - udp_hdr_t *udp_hdr = get_udp_header((gnrc_pktsnip_t *)msg.content.ptr); - ipv6_hdr_t *ip6_hdr = - gnrc_ipv6_get_header((gnrc_pktsnip_t *)msg.content.ptr); - if (!udp_hdr || !ip6_hdr) - break; - coap_log_debug("coap_run_once: found UDP header\n"); - - /* Traverse all sessions and set COAP_SOCKET_CAN_READ if the - * received packet's destination address matches. */ - SESSIONS_ITER(ctx->sessions, s, rtmp) { - coap_log_debug("coap_run_once: check ctx->sessions %u == %u\n", - ntohs(get_port(&s->addr_info.local)), - ntohs(udp_hdr->dst_port.u16)); - if ((get_port(&s->addr_info.local) == udp_hdr->dst_port.u16) && - (address_equals(&s->addr_info.local, &ip6_hdr->dst))) { - coap_socket_t *sock = find_socket(s->sock.fd, sockets, num_sockets); - - if (sock && (sock->flags & (COAP_SOCKET_WANT_READ))) { - coap_log_debug("fd %d on port %u can read\n", - sock->fd, ntohs(get_port(&s->addr_info.local))); - sock->flags |= COAP_SOCKET_CAN_READ; - sock->pkt = msg.content.ptr; - found_port = true; - break; /* found session, finish loop */ - } - } - } - - /* If no session was found for received packet, traverse all - * endpoints and set COAP_SOCKET_CAN_READ if the received packet's - * destination address matches the endpoint. */ - if (!found_port) { - coap_endpoint_t *ep; - LL_FOREACH(ctx->endpoint, ep) { - if ((get_port(&ep->bind_addr) == udp_hdr->dst_port.u16) && - (address_equals(&ep->bind_addr, &ip6_hdr->dst))) { - coap_socket_t *sock = find_socket(ep->sock.fd, sockets, num_sockets); - - if (sock && (sock->flags & (COAP_SOCKET_WANT_READ))) { - coap_log_debug("fd %d on port %u can read\n", - sock->fd, ntohs(get_port(&ep->bind_addr))); - sock->flags |= COAP_SOCKET_CAN_READ; - sock->pkt = msg.content.ptr; - found_port = true; - break; /* found session, finish loop */ - } - } - } - } - break; - } - case GNRC_NETAPI_MSG_TYPE_SND: - break; - case GNRC_NETAPI_MSG_TYPE_SET: - /* fall through */ - case GNRC_NETAPI_MSG_TYPE_GET: - break; - default: - break; - } - - coap_ticks(&now); - coap_io_do_io(ctx, now); - - /* cleanup */ - gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &coap_reg); - - return (int)(((now - before) * 1000) / COAP_TICKS_PER_SECOND); -} diff --git a/src/coap_mbedtls.c b/src/coap_mbedtls.c index 3d543000..a3b87051 100644 --- a/src/coap_mbedtls.c +++ b/src/coap_mbedtls.c @@ -1690,6 +1690,9 @@ coap_dtls_context_set_cpsk(coap_context_t *c_context, coap_dtls_cpsk_t *setup_data ) { #if !defined(MBEDTLS_SSL_CLI_C) + (void)c_context; + (void)setup_data; + coap_log_emerg("coap_context_set_cpsk:" " libcoap not compiled for Client Mode for Mbed TLS" " - update Mbed TLS to include Client Mode\n"); diff --git a/src/coap_mem.c b/src/coap_mem.c index dbb97195..ecb0c4ce 100644 --- a/src/coap_mem.c +++ b/src/coap_mem.c @@ -22,16 +22,16 @@ #undef PACKAGE_STRING #undef PACKAGE_TARNAME #undef PACKAGE_VERSION -#include +#include #undef PACKAGE_NAME #undef PACKAGE_STRING #undef PACKAGE_TARNAME #undef PACKAGE_VERSION -#include "coap_session.h" -#include "net.h" -#include "pdu.h" -#include "resource.h" +#include "coap3/coap_session.h" +#include "coap3/coap_net.h" +#include "coap3/pdu.h" +#include "coap3/resource.h" /** * The maximum size of a string on platforms that allocate fixed-size @@ -175,6 +175,42 @@ #define COAP_MAX_CACHE_ENTRIES (2U) #endif /* COAP_MAX_CACHE_ENTRIES */ +/** + * The maximum number lg_crcv entries that allocate + * fixed-size memory blocks. + */ +#ifndef COAP_MAX_LG_CRCVS +#if COAP_CLIENT_SUPPORT +#define COAP_MAX_LG_CRCVS (1U) +#else /* ! COAP_CLIENT_SUPPORT */ +#define COAP_MAX_LG_CRCVS (0U) +#endif /* ! COAP_CLIENT_SUPPORT */ +#endif /* COAP_MAX_LG_CRCVS */ + +/** + * The maximum number lg_srcv entries that allocate + * fixed-size memory blocks. + */ +#ifndef COAP_MAX_LG_SRCVS +#if COAP_SERVER_SUPPORT +#define COAP_MAX_LG_SRCVS (2U) +#else /* ! COAP_SERVER_SUPPORT */ +#define COAP_MAX_LG_SRCVS (0U) +#endif /* ! COAP_SERVER_SUPPORT */ +#endif /* COAP_MAX_LG_SRCVS */ + +/** + * The maximum number lg_xmit entries that allocate + * fixed-size memory blocks. + */ +#ifndef COAP_MAX_LG_XMITS +#if COAP_SERVER_SUPPORT +#define COAP_MAX_LG_XMITS (2U) +#else /* ! COAP_SERVER_SUPPORT */ +#define COAP_MAX_LG_XMITS (1U) +#endif /* ! COAP_SERVER_SUPPORT */ +#endif /* COAP_MAX_LG_XMITS */ + /* The memstr is the storage for holding coap_string_t structure * together with its contents. */ union memstr_t { @@ -193,6 +229,7 @@ union attrstr_t { static union memstr_t string_storage_data[COAP_MAX_STRINGS]; static memarray_t string_storage; +#if COAP_SERVER_SUPPORT static coap_endpoint_t endpoint_storage_data[COAP_MAX_ENDPOINTS]; static memarray_t endpoint_storage; @@ -201,6 +238,7 @@ static memarray_t attr_storage; static coap_attr_t resattr_storage_data[COAP_MAX_ATTRIBUTES]; static memarray_t resattr_storage; +#endif /* COAP_SERVER_SUPPORT */ static coap_packet_t pkt_storage_data[COAP_MAX_PACKETS]; static memarray_t pkt_storage; @@ -224,10 +262,14 @@ union pdubuf_t { static union pdubuf_t pdubuf_storage_data[COAP_MAX_PDUS]; static memarray_t pdubuf_storage; +#if COAP_SERVER_SUPPORT static coap_resource_t resource_storage_data[COAP_MAX_RESOURCES]; static memarray_t resource_storage; +#endif /* COAP_SERVER_SUPPORT */ #ifdef HAVE_LIBTINYDTLS +#undef PACKAGE_BUGREPORT +#include static session_t dtls_storage_data[COAP_MAX_DTLS_SESSIONS]; static memarray_t dtls_storage; #endif /* HAVE_LIBTINYDTLS */ @@ -243,11 +285,26 @@ struct optbuf_t { static struct optbuf_t option_storage_data[COAP_MAX_OPTIONS]; static memarray_t option_storage; +#if COAP_SERVER_SUPPORT static coap_cache_key_t cache_key_storage_data[COAP_MAX_CACHE_KEYS]; static memarray_t cache_key_storage; static coap_cache_entry_t cache_entry_storage_data[COAP_MAX_CACHE_ENTRIES]; static memarray_t cache_entry_storage; +#endif /* COAP_SERVER_SUPPORT */ + +#if COAP_CLIENT_SUPPORT +static coap_lg_crcv_t cache_lg_crcv_storage_data[COAP_MAX_LG_CRCVS]; +static memarray_t cache_lg_crcv_storage; +#endif /* COAP_CLIENT_SUPPORT */ + +#if COAP_SERVER_SUPPORT +static coap_lg_srcv_t cache_lg_srcv_storage_data[COAP_MAX_LG_SRCVS]; +static memarray_t cache_lg_srcv_storage; + +static coap_lg_xmit_t cache_lg_xmit_storage_data[COAP_MAX_LG_XMITS]; +static memarray_t cache_lg_xmit_storage; +#endif /* COAP_SERVER_SUPPORT */ #define INIT_STORAGE(Storage, Count) \ memarray_init(&(Storage ## _storage), (Storage ## _storage_data), sizeof(Storage ## _storage_data[0]), (Count)); @@ -257,45 +314,73 @@ static memarray_t cache_entry_storage; void coap_memory_init(void) { INIT_STORAGE(string, COAP_MAX_STRINGS); +#if COAP_SERVER_SUPPORT INIT_STORAGE(endpoint, COAP_MAX_ENDPOINTS); INIT_STORAGE(attr, COAP_MAX_ATTRIBUTE_STRINGS); +#endif /* COAP_SERVER_SUPPORT */ INIT_STORAGE(pkt, COAP_MAX_PACKETS); INIT_STORAGE(node, COAP_MAX_NODES); INIT_STORAGE(context, COAP_MAX_CONTEXTS); INIT_STORAGE(pdu, COAP_MAX_PDUS); INIT_STORAGE(pdubuf, COAP_MAX_PDUS); +#if COAP_SERVER_SUPPORT INIT_STORAGE(resource, COAP_MAX_RESOURCES); INIT_STORAGE(resattr, COAP_MAX_ATTRIBUTES); +#endif /* COAP_SERVER_SUPPORT */ #ifdef HAVE_LIBTINYDTLS INIT_STORAGE(dtls, COAP_MAX_DTLS_SESSIONS); #endif INIT_STORAGE(session, COAP_MAX_SESSIONS); INIT_STORAGE(option, COAP_MAX_OPTIONS); +#if COAP_SERVER_SUPPORT INIT_STORAGE(cache_key, COAP_MAX_CACHE_KEYS); INIT_STORAGE(cache_entry, COAP_MAX_CACHE_ENTRIES); +#endif /* COAP_SERVER_SUPPORT */ +#if COAP_CLIENT_SUPPORT + INIT_STORAGE(cache_lg_crcv, COAP_MAX_LG_CRCVS); +#endif /* COAP_SERVER_SUPPORT */ +#if COAP_SERVER_SUPPORT + INIT_STORAGE(cache_lg_srcv, COAP_MAX_LG_SRCVS); + INIT_STORAGE(cache_lg_xmit, COAP_MAX_LG_XMITS); +#endif /* COAP_SERVER_SUPPORT */ } static memarray_t * get_container(coap_memory_tag_t type) { switch(type) { +#if COAP_SERVER_SUPPORT case COAP_ATTRIBUTE_NAME: /* fall through */ case COAP_ATTRIBUTE_VALUE: return &attr_storage; +#endif /* COAP_SERVER_SUPPORT */ case COAP_PACKET: return &pkt_storage; case COAP_NODE: return &node_storage; case COAP_CONTEXT: return STORAGE_PTR(context); +#if COAP_SERVER_SUPPORT case COAP_ENDPOINT: return &endpoint_storage; +#endif /* COAP_SERVER_SUPPORT */ case COAP_PDU: return &pdu_storage; case COAP_PDU_BUF: return &pdubuf_storage; +#if COAP_SERVER_SUPPORT case COAP_RESOURCE: return &resource_storage; case COAP_RESOURCEATTR: return &resattr_storage; +#endif /* COAP_SERVER_SUPPORT */ #ifdef HAVE_LIBTINYDTLS case COAP_DTLS_SESSION: return &dtls_storage; #endif case COAP_SESSION: return &session_storage; case COAP_OPTLIST: return &option_storage; +#if COAP_SERVER_SUPPORT case COAP_CACHE_KEY: return &cache_key_storage; - case COAP_CACHE_ENTRY: return &cache_key_entry; + case COAP_CACHE_ENTRY: return &cache_entry_storage; +#endif /* COAP_SERVER_SUPPORT */ +#if COAP_CLIENT_SUPPORT + case COAP_LG_CRCV: return &cache_lg_crcv_storage; +#endif /* COAP_CLIENT_SUPPORT */ +#if COAP_SERVER_SUPPORT + case COAP_LG_SRCV: return &cache_lg_srcv_storage; + case COAP_LG_XMIT: return &cache_lg_xmit_storage; +#endif /* COAP_SERVER_SUPPORT */ case COAP_STRING: /* fall through */ default: diff --git a/src/coap_prng.c b/src/coap_prng.c index 31cbcfc0..66320117 100644 --- a/src/coap_prng.c +++ b/src/coap_prng.c @@ -90,6 +90,10 @@ coap_prng_default(void *buf, size_t len) { } } return 1; +#elif defined(RIOT_VERSION) +#include + random_bytes(buf, len); + return 1; #elif defined(WITH_CONTIKI) size_t i; diff --git a/src/coap_tinydtls.c b/src/coap_tinydtls.c index 028b9b9d..51d6a927 100644 --- a/src/coap_tinydtls.c +++ b/src/coap_tinydtls.c @@ -27,9 +27,17 @@ #undef PACKAGE_URL #undef PACKAGE_VERSION +#ifndef RIOT_VERSION #include #include #include +#include +#else /* RIOT_VERSION */ +#include +#include +#include +#include +#endif /* RIOT_VERSION */ typedef struct coap_tiny_context_t { struct dtls_context_t *dtls_context; @@ -176,9 +184,9 @@ coap_dtls_set_log_level(coap_log_t c_level) { d_level = DTLS_LOG_ALERT; break; case COAP_LOG_CRIT: + case COAP_LOG_ERR: d_level = DTLS_LOG_CRIT; break; - case COAP_LOG_ERR: case COAP_LOG_WARN: d_level = DTLS_LOG_WARN; break; @@ -210,7 +218,22 @@ get_session_addr(const session_t *s, coap_address_t *a) { #if defined(WITH_CONTIKI) || defined(WITH_LWIP) a->addr = s->addr; a->port = s->port; -#else /* ! WITH_CONTIKI && ! WITH_LWIP */ +#elif defined(WITH_RIOT_SOCK) + if (s->addr.family == AF_INET6) { + a->size = (socklen_t)sizeof(a->addr.sin6); + a->addr.sa.sa_family = s->addr.family; + memcpy(&a->addr.sin6.sin6_addr, &s->addr.ipv6, + sizeof(a->addr.sin6.sin6_addr)); + a->addr.sin6.sin6_port = s->addr.port; +#ifdef SOCK_HAS_IPV4 + } else if (s->addr.family == AF_INET) { + a->addr.sa.sa_family = s->addr.family; + a->size = (socklen_t)sizeof(a->addr.sin); + memcpy(&a->addr.sin.sin_addr, &s->addr.ipv4, sizeof(a->addr.sin.sin_addr)); + a->addr.sin.sin_port = s->addr.port; +#endif /* SOCK_HAS_IPV4 */ + } +#else /* ! WITH_CONTIKI && ! WITH_LWIP && ! WITH_RIOT_SOCK */ if (s->addr.sa.sa_family == AF_INET6) { a->size = (socklen_t)sizeof(a->addr.sin6); a->addr.sin6 = s->addr.sin6; @@ -221,7 +244,7 @@ get_session_addr(const session_t *s, coap_address_t *a) { a->size = (socklen_t)s->size; a->addr.sa = s->addr.sa; } -#endif /* ! WITH_CONTIKI && ! WITH_LWIP */ +#endif /* ! WITH_CONTIKI && ! WITH_LWIP && ! WITH_RIOT_SOCK */ } static void @@ -230,7 +253,22 @@ put_session_addr(const coap_address_t *a, session_t *s) { s->size = (unsigned char)sizeof(s->addr); s->addr = a->addr; s->port = a->port; -#else /* ! WITH_CONTIKI && ! WITH_LWIP */ +#elif defined(WITH_RIOT_SOCK) + if (a->addr.sa.sa_family == AF_INET6) { + s->size = (socklen_t)sizeof(s->addr.ipv6); + s->addr.family = a->addr.sa.sa_family; + memcpy(&s->addr.ipv6, &a->addr.sin6.sin6_addr, + sizeof(s->addr.ipv6)); + s->addr.port = a->addr.sin6.sin6_port; +#ifdef SOCK_HAS_IPV4 + } else if (a->addr.sa.sa_family == AF_INET) { + s->size = (socklen_t)sizeof(s->addr.ipv4); + s->addr.family = a->addr.sa.sa_family; + memcpy(&a->addr.ipv4, &s->addr.sin.sin_addr, sizeof(a->addr.ipv4)); + s->addr.port = a->addr.sin.sin_port; +#endif /* SOCK_HAS_IPV4 */ + } +#else /* ! WITH_CONTIKI && ! WITH_LWIP && ! WITH_RIOT_SOCK */ if (a->addr.sa.sa_family == AF_INET6) { s->size = (socklen_t)sizeof(s->addr.sin6); s->addr.sin6 = a->addr.sin6; @@ -241,7 +279,7 @@ put_session_addr(const coap_address_t *a, session_t *s) { s->size = (socklen_t)a->size; s->addr.sa = a->addr.sa; } -#endif /* ! WITH_CONTIKI && ! WITH_LWIP */ +#endif /* ! WITH_CONTIKI && ! WITH_LWIP && ! WITH_RIOT_SOCK */ } static int