Skip to content

Commit

Permalink
LwIP: Rework code to use all of libcoap capabilities
Browse files Browse the repository at this point in the history
Update examples/lwip directory to make it more standalone.

Available directories under examples/lwip/

 config/       Contains LwiP + CoAP configuration files
 libcoap/      Link to the libcoap tree
 lwip/         The LwIP tree
 lwip-contrib/ The LwIP contrib tree (obsoleted in LwIP master branch)
 src/          Local modifications to LwIP
 tinydtls/     Link to the TinyDTLS tree

New files to contain the headers for the appropriate build types, with most
of the #include removed from the other *.[ch] files.

App visibility (selected by build type)
 include/coap3/coap_include_contiki.h
 include/coap3/coap_include_lwip.h
 include/coap3/coap_include_posix.h
 include/coap3/coap_include_windows.h
library visibility (Can have tests for include files etc.)
 include/coap3/coap_include_contiki_internal.h
 include/coap3/coap_include_lwip_internal.h
 include/coap3/coap_include_posix_internal.h
 include/coap3/coap_include_windows_internal.h

mem.[ch] renamed to coap_mem.[ch] to prevent build name clashes.

Changed NO_SYS to 0, and so now accept() is renamed to lwip_accept(), socket()
is renamed to lwip_socket() etc.

Add in TinyDTLS support for packet encryption.

Removed a lot of the WITH_LWIP protected code as it is now redundant.

Removed LwIP specific files no longer in use.

Uses the tap interface to interface with Linux, each new application will
use the next available tap interface.  tap interfaces can be pre-configured
and used.
  • Loading branch information
mrdeep1 committed Jul 23, 2022
1 parent 98ecf5a commit cfaea86
Show file tree
Hide file tree
Showing 87 changed files with 1,624 additions and 1,362 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ jobs:
OS: ["contiki", "lwip"]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: setup
run: |
./autogen.sh
- name: configure
run: |
$GITHUB_WORKSPACE/configure --disable-documentation --disable-examples --disable-tests --disable-dtls
$GITHUB_WORKSPACE/configure --disable-documentation --disable-examples --disable-tests --with-tinydtls
- name: compile
run: |
make -C examples/${{matrix.OS}}
Expand Down
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Makefile.in
aclocal.m4
ar-lib
autom4te.cache/
coap_config.h
coap_config.h.in
/coap_config.h
/coap_config.h.in
compile
config.*
!config.yml
Expand Down Expand Up @@ -88,6 +88,10 @@ examples/coap-server-*
examples/coap-tiny
examples/*.exe

examples/lwip/coap-client
examples/lwip/coap-rd
examples/lwip/coap-server

# the include/ folder
include/coap3/coap.h

Expand Down
5 changes: 3 additions & 2 deletions BUILDING
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ LwIP
====

./autogen.sh
./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
./configure --disable-tests --disable-documentation --disable-examples --with-tinydtls --with-submodule-tinydtls
cd examples/lwip
make

Executable is ./server. See examples/lwip/README for further information
Executables are ./coap-server, ./coap-client or ./coap-rd. See
examples/lwip/README for further information

Contiki
=======
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/src/coap_event.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_hashkey.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_io.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_mem.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_notls.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_option.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_prng.c
Expand All @@ -466,7 +467,6 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/src/coap_time.c
${CMAKE_CURRENT_LIST_DIR}/src/block.c
${CMAKE_CURRENT_LIST_DIR}/src/encode.c
${CMAKE_CURRENT_LIST_DIR}/src/mem.c
${CMAKE_CURRENT_LIST_DIR}/src/net.c
${CMAKE_CURRENT_LIST_DIR}/src/pdu.c
${CMAKE_CURRENT_LIST_DIR}/src/resource.c
Expand All @@ -487,6 +487,7 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_event.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_hashkey.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_io.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_mem.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_option.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_prng.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_session.h
Expand All @@ -495,8 +496,6 @@ target_sources(
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/block.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/encode.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/libcoap.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/lwippools.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/mem.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/net.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/pdu.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/resource.h
Expand Down Expand Up @@ -699,7 +698,6 @@ install(
PATTERN "*.h"
PATTERN "coap.h" EXCLUDE
PATTERN "coap_riot.h" EXCLUDE
PATTERN "lwippools.h" EXCLUDE
PATTERN "utlist.h" EXCLUDE
PATTERN "uthash.h" EXCLUDE
PATTERN "*_internal.h" EXCLUDE)
Expand Down
15 changes: 12 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ EXTRA_DIST = \
include/coap$(LIBCOAP_API_VERSION)/coap_block_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_cache_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_dtls_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_contiki.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_contiki_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_lwip.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_lwip_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_posix.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_posix_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_riot.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_riot_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_windows.h \
include/coap$(LIBCOAP_API_VERSION)/coap_include_windows_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_io_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_net_internal.h \
include/coap$(LIBCOAP_API_VERSION)/coap_pdu_internal.h \
Expand All @@ -53,7 +63,6 @@ EXTRA_DIST = \
include/coap$(LIBCOAP_API_VERSION)/coap.h.in \
include/coap$(LIBCOAP_API_VERSION)/coap.h.windows \
include/coap$(LIBCOAP_API_VERSION)/coap.h.windows.in \
include/coap$(LIBCOAP_API_VERSION)/lwippools.h \
include/coap$(LIBCOAP_API_VERSION)/uthash.h \
include/coap$(LIBCOAP_API_VERSION)/utlist.h \
src/coap_io_riot.c \
Expand Down Expand Up @@ -113,6 +122,7 @@ libcoap_@LIBCOAP_NAME_SUFFIX@_la_SOURCES = \
src/coap_gnutls.c \
src/coap_io.c \
src/coap_mbedtls.c \
src/coap_mem.c \
src/coap_notls.c \
src/coap_openssl.c \
src/coap_option.c \
Expand All @@ -123,7 +133,6 @@ libcoap_@LIBCOAP_NAME_SUFFIX@_la_SOURCES = \
src/coap_time.c \
src/coap_tinydtls.c \
src/encode.c \
src/mem.c \
src/net.c \
src/pdu.c \
src/resource.c \
Expand Down Expand Up @@ -153,14 +162,14 @@ libcoap_include_HEADERS = \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_forward_decls.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_hashkey.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_io.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_mem.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_mutex.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_option.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_session.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_subscribe.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_time.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/encode.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/libcoap.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/mem.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/net.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/pdu.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_prng.h \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.libcoap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
libcoap_src = pdu.c net.c coap_cache.c coap_debug.c encode.c uri.c coap_subscribe.c resource.c str.c coap_option.c coap_async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c coap_address.c coap_tcp.c
libcoap_src = pdu.c net.c coap_cache.c coap_debug.c encode.c uri.c coap_subscribe.c resource.c str.c coap_option.c coap_async.c block.c coap_mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c coap_address.c coap_tcp.c

libcoap_dir := $(filter %libcoap,$(APPDS))
vpath %c $(libcoap_dir)/src
Expand Down
40 changes: 35 additions & 5 deletions coap_config.h.lwip
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* coap_config.h.lwip -- LwIP configuration for libcoap
*
* Copyright (C) 2021 Olaf Bergmann <[email protected]> and others
* Copyright (C) 2021-2022 Olaf Bergmann <[email protected]> and others
*
* SPDX-License-Identifier: BSD-2-Clause
*
Expand All @@ -12,31 +12,61 @@
#ifndef COAP_CONFIG_H_
#define COAP_CONFIG_H_

#include <lwip/opt.h>
#include <lwip/debug.h>
#include <lwip/def.h> /* provide ntohs, htons */
#include "lwipopts.h"

#define WITH_LWIP 1

/* Define if TinyDTLS support is to be included */
#define HAVE_LIBTINYDTLS

/* Define as 1 if the system has small stack size */
#ifndef COAP_CONSTRAINED_STACK
#define COAP_CONSTRAINED_STACK 1
#endif

/* Define as 1 to build without TCP support. */
#ifndef COAP_DISABLE_TCP
#define COAP_DISABLE_TCP 1
#define COAP_DISABLE_TCP 0
#endif

/* Define as 1 if libcoap supports client mode code */
#ifndef COAP_CLIENT_SUPPORT
#define COAP_CLIENT_SUPPORT 1
#endif

/* Define as 1 if libcoap supports server mode code */
#ifndef COAP_SERVER_SUPPORT
#define COAP_SERVER_SUPPORT 1
#endif

/* Define if the system has epoll support */
#undef COAP_EPOLL_SUPPORT

#define PACKAGE_NAME "libcoap"
#define PACKAGE_VERSION "4.3.0"
#define PACKAGE_STRING "libcoap 4.3.0"

#define assert(x) LWIP_ASSERT("CoAP assert failed", x)

/* To keep IPv6 builds happy */
#define IPV6_MULTICAST_HOPS 0x301
#define IPV6_PKTINFO IPV6_CHECKSUM

/* To keep IPv6 builds happy */
#define OPTVAL_T(t) (t)
#define OPTVAL_GT(t) (t)

/* it's just provided by libc. i hope we don't get too many of those, as
* actually we'd need autotools again to find out what environment we're
* building in */
#define HAVE_STRNLEN 1

#define HAVE_LIMITS_H

#define HAVE_SNPRINTF

#define HAVE_STRUCT_CMSGHDR

#define ESPIDF_VERSION 1

#endif /* COAP_CONFIG_H_ */
40 changes: 35 additions & 5 deletions coap_config.h.lwip.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* coap_config.h.lwip -- LwIP configuration for libcoap
*
* Copyright (C) 2021 Olaf Bergmann <[email protected]> and others
* Copyright (C) 2021-2022 Olaf Bergmann <[email protected]> and others
*
* SPDX-License-Identifier: BSD-2-Clause
*
Expand All @@ -12,31 +12,61 @@
#ifndef COAP_CONFIG_H_
#define COAP_CONFIG_H_

#include <lwip/opt.h>
#include <lwip/debug.h>
#include <lwip/def.h> /* provide ntohs, htons */
#include "lwipopts.h"

#define WITH_LWIP 1

/* Define if TinyDTLS support is to be included */
#define HAVE_LIBTINYDTLS

/* Define as 1 if the system has small stack size */
#ifndef COAP_CONSTRAINED_STACK
#define COAP_CONSTRAINED_STACK 1
#endif

/* Define as 1 to build without TCP support. */
#ifndef COAP_DISABLE_TCP
#define COAP_DISABLE_TCP 1
#define COAP_DISABLE_TCP 0
#endif

/* Define as 1 if libcoap supports client mode code */
#ifndef COAP_CLIENT_SUPPORT
#define COAP_CLIENT_SUPPORT 1
#endif

/* Define as 1 if libcoap supports server mode code */
#ifndef COAP_SERVER_SUPPORT
#define COAP_SERVER_SUPPORT 1
#endif

/* Define if the system has epoll support */
#undef COAP_EPOLL_SUPPORT

#define PACKAGE_NAME "@PACKAGE_NAME@"
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
#define PACKAGE_STRING "@PACKAGE_STRING@"

#define assert(x) LWIP_ASSERT("CoAP assert failed", x)

/* To keep IPv6 builds happy */
#define IPV6_MULTICAST_HOPS 0x301
#define IPV6_PKTINFO IPV6_CHECKSUM

/* To keep IPv6 builds happy */
#define OPTVAL_T(t) (t)
#define OPTVAL_GT(t) (t)

/* it's just provided by libc. i hope we don't get too many of those, as
* actually we'd need autotools again to find out what environment we're
* building in */
#define HAVE_STRNLEN 1

#define HAVE_LIMITS_H

#define HAVE_SNPRINTF

#define HAVE_STRUCT_CMSGHDR

#define ESPIDF_VERSION 1

#endif /* COAP_CONFIG_H_ */
1 change: 0 additions & 1 deletion doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,6 @@ RECURSIVE = NO

EXCLUDE = @top_srcdir@/src/coap_io_lwip.c \
@top_srcdir@/src/coap_io_riot.c \
@top_srcdir@/include/coap@LIBCOAP_API_VERSION@/lwippools.h \
@top_srcdir@/include/coap@LIBCOAP_API_VERSION@/uthash.h \
@top_srcdir@/include/coap@LIBCOAP_API_VERSION@/utlist.h

Expand Down
38 changes: 7 additions & 31 deletions examples/coap-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,17 @@
* use.
*/

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
/*
* If additional system header files are needed, consider updating the
* include/coap3/coap_include_*.h files as appropriate depending on your
* build environment. If necessary, submit a PR to add these in.
*/

#include <coap3/coap.h>
#ifdef _WIN32
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define fileno _fileno
#include "getopt.c"
#if !defined(S_ISDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
static char* strndup(const char* s1, size_t n)
{
char* copy = (char*)malloc(n + 1);
if (copy) {
memcpy(copy, s1, n);
copy[n] = 0;
}
return copy;
};
#else
#include <unistd.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif

#include <coap3/coap.h>

#define MAX_USER 128 /* Maximum length of a user name (i.e., PSK
* identity) in bytes. */
#define MAX_KEY 64 /* Maximum length of a key (i.e., PSK) in bytes. */
Expand Down
Loading

0 comments on commit cfaea86

Please sign in to comment.