Skip to content

Commit

Permalink
pkg/libcoap: Use Sock interface instead of Posix interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Feb 29, 2024
1 parent 9700088 commit 2cebb3c
Show file tree
Hide file tree
Showing 12 changed files with 2,195 additions and 32 deletions.
2 changes: 2 additions & 0 deletions examples/libcoap-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ USEMODULE += prng_sha1prng

# libcoap support
USEPKG += libcoap
# Uncomment to enable libcoap OSCORE support
# USEMODULE += libcoap_oscore

# Configure if DNS is required
# USEMODULE += sock_dns
Expand Down
11 changes: 3 additions & 8 deletions examples/libcoap-client/client-coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
* of use.
*/

#include "coap_config.h"
#include <thread.h>
#include <debug.h>
#include <coap3/coap.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "client-coap.h"
#include <stdio.h>
#include "macros/utils.h"
#include "net/utils.h"
#include <arpa/inet.h>
#include <thread.h>
#include <debug.h>

#ifdef CONFIG_LIBCOAP_CLIENT_URI
#define COAP_CLIENT_URI CONFIG_LIBCOAP_CLIENT_URI
Expand Down
3 changes: 0 additions & 3 deletions examples/libcoap-client/client-coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
extern "C" {
#endif

#include "coap_config.h"
#include <coap3/coap.h>

/* Start up the CoAP Client */
void client_coap_init(int argc, char **argv);

Expand Down
3 changes: 2 additions & 1 deletion examples/libcoap-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ USEMODULE += prng_sha1prng

# libcoap support
USEPKG += libcoap
# Uncomment to enable libcoap OSCORE support
# USEMODULE += libcoap_oscore

USEMODULE += sock_udp
# Configure if DNS is required
USEMODULE += sock_dns

Expand Down
6 changes: 3 additions & 3 deletions examples/libcoap-server/server-coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ init_coap_context_endpoints(const char *use_psk)
}

coap_address_init(&listenaddress);
listenaddress.addr.sin6.sin6_family = AF_INET6;
memcpy(&listenaddress.addr.sin6.sin6_addr, &addr,
sizeof(listenaddress.addr.sin6.sin6_addr));
listenaddress.riot.family = AF_INET6;
memcpy(&listenaddress.riot.addr.ipv6, &addr,
sizeof(listenaddress.riot.addr.ipv6));
coap_print_ip_addr(&listenaddress, addr_str, sizeof(addr_str));
coap_log_info("Server IP [%s]\n", addr_str);

Expand Down
3 changes: 0 additions & 3 deletions examples/libcoap-server/server-coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
extern "C" {
#endif

#include "coap_config.h"
#include <coap3/coap.h>

/* Start up the CoAP Server */
void server_coap_init(int argc, char **argv);

Expand Down
14 changes: 12 additions & 2 deletions pkg/libcoap/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if KCONFIG_USEPKG_LIBCOAP

choice LIBCOAP_DEBUG_LEVEL
bool "Set CoAP debugging level"
default LIBCOAP_LOG_WARNING
default LIBCOAP_LOG_INFO
help
Set CoAP debugging level

Expand Down Expand Up @@ -57,6 +57,7 @@ config LIBCOAP_IPV4_SUPPORT
Enable IPv4 functionality for CoAP.

If this option is disabled, redundant CoAP IPv4 code is removed.
[RIOT sock gnrc does not support this]

config LIBCOAP_IPV6_SUPPORT
bool "Enable IPv6 support within CoAP"
Expand All @@ -66,6 +67,8 @@ config LIBCOAP_IPV6_SUPPORT

If this option is disabled, redundant CoAP IPv6 code is removed.

if USEMODULE_SOCK_TCP

config LIBCOAP_TCP_SUPPORT
bool "Enable TCP support within CoAP"
default n
Expand All @@ -74,15 +77,22 @@ config LIBCOAP_TCP_SUPPORT
are to be used. Note that RIOT TCP support also needs to be enabled.

If this option is disabled, redundant CoAP TCP code is removed.
[RIOT sock gnrc does not support this]

endif # USEMODULE_SOCK_TCP

if USEMODULE_LIBCOAP_OSCORE

config LIBCOAP_OSCORE_SUPPORT
bool "Enable OSCORE support within CoAP"
default n
default y
help
Enable OSCORE functionality for CoAP.

If this option is disabled, redundant CoAP OSCORE code is removed.

endif # MODULE_LIBCOAP_OSCORE

config LIBCOAP_OBSERVE_PERSIST
bool "Enable Observe persist support within CoAP"
default n
Expand Down
19 changes: 14 additions & 5 deletions pkg/libcoap/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PKG_NAME=libcoap
PKG_URL=https://github.com/obgm/libcoap
PKG_VERSION=a733325b16e9070c03b0a664a6dbe01ffda7de65
PKG_VERSION=9f499ad42f963c52ad475137a526056b82783fe0
PKG_LICENSE=BSD-2-Clause

LIBCOAP_BUILD_DIR=$(BINDIR)/pkg/$(PKG_NAME)
Expand All @@ -9,7 +9,16 @@ 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
ifneq (,$(filter libcoap_oscore,$(USEMODULE)))
all: libcoap libcoap_oscore
else
all: libcoap
endif

libcoap:
$(QQ)@cp $(LIBCOAP_SOURCE_DIR)/coap_config.h.riot $(LIBCOAP_SOURCE_DIR)/coap_config.h
$(QQ)@cp $(LIBCOAP_INCLUDE_DIR)/coap.h.riot $(LIBCOAP_INCLUDE_DIR)/coap.h
$(QQ)"$(MAKE)" -C $(LIBCOAP_SOURCE_DIR)/src -f $(CURDIR)/Makefile.libcoap

libcoap_oscore:
$(QQ)"$(MAKE)" -C $(LIBCOAP_SOURCE_DIR)/src/oscore -f $(CURDIR)/Makefile.oscore
9 changes: 5 additions & 4 deletions pkg/libcoap/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
USEMODULE += posix_headers
USEMODULE += posix_inet
USEMODULE += sock_udp
USEMODULE += sock_tcp
USEMODULE += sock_aux_local
USEMODULE += gnrc_sock_async
USEMODULE += sock_async_event

ifneq (,$(filter libcoap,$(USEPKG)))
USEMODULE += libcoap
endif

ifneq (,$(filter libcoap_oscore,$(USEPKG)))
USEMODULE += libcoap_oscore
endif
10 changes: 10 additions & 0 deletions pkg/libcoap/Makefile.oscore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MODULE := libcoap_oscore

SRC := \
oscore.c \
oscore_cbor.c \
oscore_context.c \
oscore_cose.c \
oscore_crypto.c

include $(RIOTBASE)/Makefile.base
Loading

0 comments on commit 2cebb3c

Please sign in to comment.