mirror of
https://github.com/openharmony/third_party_libcoap.git
synced 2026-07-01 03:23:17 -04:00
-90
@@ -1,90 +0,0 @@
|
||||
# .gitignore for libcoap
|
||||
|
||||
# ignoring autogenerated files and directories by autoreconf
|
||||
INSTALL
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
ar-lib
|
||||
autom4te.cache/
|
||||
coap_config.h.in
|
||||
compile
|
||||
config.*
|
||||
configure
|
||||
debian/
|
||||
depcomp
|
||||
install-sh
|
||||
libcoap-*.tar.bz2
|
||||
libtool
|
||||
ltmain.sh
|
||||
m4/libtool.m4
|
||||
m4/ltoptions.m4
|
||||
m4/ltsugar.m4
|
||||
m4/ltversion.m4
|
||||
m4/lt~obsolete.m4
|
||||
missing
|
||||
stamp-h1
|
||||
|
||||
# ignoring more files generated by the configure script or the make actions
|
||||
.libs/
|
||||
libcoap*.la
|
||||
libcoap*.pc
|
||||
src/**/.deps/
|
||||
src/**/.dirstamp
|
||||
src/**/.libs/
|
||||
src/**/*.o
|
||||
src/**/*.lo
|
||||
src/*.lo
|
||||
src/*.o
|
||||
src/.deps/
|
||||
src/.dirstamp
|
||||
src/.libs/
|
||||
|
||||
# the doc/ folder
|
||||
doc/Doxyfile
|
||||
doc/Makefile.in
|
||||
doc/doxyfile.stamp
|
||||
doc/doxygen_sqlite3.db
|
||||
doc/DoxygenLayout.xml
|
||||
doc/html/
|
||||
doc/man_html/
|
||||
doc/man_tmp/
|
||||
|
||||
# the man/ folder
|
||||
man/docbook-xsl.css
|
||||
man/Makefile
|
||||
man/Makefile.in
|
||||
man/*.html
|
||||
man/*.txt
|
||||
man/*.xml
|
||||
man/*.3
|
||||
man/*.5
|
||||
man/*.7
|
||||
|
||||
# the examples/ folder
|
||||
examples/.deps/
|
||||
examples/*.o
|
||||
examples/coap-client
|
||||
examples/coap-etsi_iot_01
|
||||
examples/coap-rd
|
||||
examples/coap-server
|
||||
examples/coap-tiny
|
||||
|
||||
# the include/ folder
|
||||
# include/coap2/coap.h
|
||||
|
||||
# the tests/ folder
|
||||
tests/.deps
|
||||
tests/oss-fuzz/Makefile.ci
|
||||
tests/testdriver
|
||||
tests/*.o
|
||||
|
||||
# ctags - Sublime plugin
|
||||
tags
|
||||
.tags*
|
||||
TAGS
|
||||
|
||||
# ignore gcov-generated files
|
||||
**/*.gcda
|
||||
**/*.gcno
|
||||
**/*.gcov
|
||||
@@ -1,4 +0,0 @@
|
||||
[submodule "ext/tinydtls"]
|
||||
path = ext/tinydtls
|
||||
url = https://github.com/eclipse/tinydtls.git
|
||||
ignore = dirty
|
||||
+18
-30
@@ -1,4 +1,6 @@
|
||||
sudo: required
|
||||
os:
|
||||
- linux
|
||||
|
||||
language: c
|
||||
|
||||
compiler:
|
||||
@@ -16,24 +18,14 @@ env:
|
||||
- PLATFORM=posix TESTS=yes TLS=gnutls SMALL_STACK=no EPOLL=no
|
||||
- PLATFORM=posix TESTS=yes TLS=openssl
|
||||
- PLATFORM=posix TESTS=yes TLS=tinydtls
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- compiler: clang
|
||||
env: PLATFORM=posix TESTS=yes TLS=no
|
||||
- compiler: clang
|
||||
env: PLATFORM=posix TESTS=yes TLS=tinydtls
|
||||
- compiler: clang
|
||||
env: PLATFORM=posix TESTS=yes TLS=gnutls SMALL_STACK=yes EPOLL=no
|
||||
- compiler: clang
|
||||
env: PLATFORM=posix TESTS=yes TLS=gnutls SMALL_STACK=no EPOLL=no
|
||||
- PLATFORM=posix TESTS=yes TLS=mbedtls
|
||||
|
||||
before_install:
|
||||
- docker build -t obgm/libcoap:travis-env .
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- main
|
||||
- develop
|
||||
- /^release-.*$/
|
||||
- travis-test
|
||||
@@ -46,24 +38,20 @@ stages:
|
||||
jobs:
|
||||
include:
|
||||
- stage: other platforms
|
||||
compiler: gcc
|
||||
env:
|
||||
- PLATFORM=contiki TLS=no
|
||||
script:
|
||||
- docker run -e CC -e PLATFORM -e TLS obgm/libcoap:travis-env /bin/sh -c "scripts/build.sh"
|
||||
- stage: other platforms
|
||||
compiler: gcc
|
||||
env:
|
||||
- PLATFORM=lwip TLS=no
|
||||
script:
|
||||
- docker run -e CC -e PLATFORM -e TLS obgm/libcoap:travis-env /bin/sh -c "scripts/build.sh"
|
||||
- stage: dist
|
||||
compiler: gcc
|
||||
env:
|
||||
- PLATFORM=posix TESTS=yes TLS=no DOCS=yes
|
||||
env: PLATFORM=contiki TLS=no
|
||||
before_script:
|
||||
script:
|
||||
- docker run -e CC -e PLATFORM -e TESTS -e DOCS -e TLS obgm/libcoap:travis-env /bin/sh -c "scripts/dist.sh"
|
||||
- docker run --privileged -e CC -e PLATFORM -e TLS obgm/libcoap:travis-env /bin/sh -c "scripts/build.sh"
|
||||
- stage: other platforms
|
||||
env: PLATFORM=lwip TLS=no
|
||||
before_script:
|
||||
script:
|
||||
- docker run --privileged -e CC -e PLATFORM -e TLS obgm/libcoap:travis-env /bin/sh -c "scripts/build.sh"
|
||||
- stage: dist
|
||||
env: PLATFORM=posix TESTS=yes TLS=no DOCS=yes
|
||||
before_script:
|
||||
script:
|
||||
- docker run --privileged -e CC -e PLATFORM -e TESTS -e DOCS -e TLS obgm/libcoap:travis-env /bin/sh -c "scripts/dist.sh"
|
||||
|
||||
# Docker disables IPv6 in containers by default, so re-enable it.
|
||||
before_script:
|
||||
@@ -79,4 +67,4 @@ before_script:
|
||||
# Paranoia log: what if our config got overwritten?
|
||||
- sudo cat /etc/docker/daemon.json
|
||||
script:
|
||||
- docker run -e CC -e PLATFORM -e TESTS -e DOCS -e TLS -e EPOLL -e SMALL_STACK obgm/libcoap:travis-env /bin/sh -c "scripts/build.sh"
|
||||
- docker run --privileged -e CC -e PLATFORM -e TESTS -e DOCS -e TLS -e EPOLL -e SMALL_STACK obgm/libcoap:travis-env /bin/sh -c "scripts/build.sh"
|
||||
|
||||
@@ -21,7 +21,10 @@ if (defined(ohos_lite)) {
|
||||
cflags_cc = cflags
|
||||
ldflags = [ "-fPIC" ]
|
||||
config("libcoap_config") {
|
||||
include_dirs = [ "include/coap2" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
defines = [ "_GNU_SOURCE" ]
|
||||
}
|
||||
source_set("libcoap_src") {
|
||||
@@ -29,14 +32,21 @@ if (defined(ohos_lite)) {
|
||||
"src/address.c",
|
||||
"src/async.c",
|
||||
"src/block.c",
|
||||
"src/coap_asn1.c",
|
||||
"src/coap_cache.c",
|
||||
"src/coap_debug.c",
|
||||
"src/coap_event.c",
|
||||
"src/coap_gnutls.c",
|
||||
"src/coap_hashkey.c",
|
||||
"src/coap_io.c",
|
||||
"src/coap_mbedtls.c",
|
||||
"src/coap_notls.c",
|
||||
"src/coap_openssl.c",
|
||||
"src/coap_prng.c",
|
||||
"src/coap_session.c",
|
||||
"src/coap_tcp.c",
|
||||
"src/coap_time.c",
|
||||
"src/coap_tinydtls.c",
|
||||
"src/encode.c",
|
||||
"src/mem.c",
|
||||
"src/net.c",
|
||||
@@ -62,7 +72,10 @@ if (defined(ohos_lite)) {
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("libcoap_config") {
|
||||
include_dirs = [ "include/coap2" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("libcoap_src") {
|
||||
@@ -70,14 +83,21 @@ if (defined(ohos_lite)) {
|
||||
"src/address.c",
|
||||
"src/async.c",
|
||||
"src/block.c",
|
||||
"src/coap_asn1.c",
|
||||
"src/coap_cache.c",
|
||||
"src/coap_debug.c",
|
||||
"src/coap_event.c",
|
||||
"src/coap_gnutls.c",
|
||||
"src/coap_hashkey.c",
|
||||
"src/coap_io.c",
|
||||
"src/coap_mbedtls.c",
|
||||
"src/coap_notls.c",
|
||||
"src/coap_openssl.c",
|
||||
"src/coap_prng.c",
|
||||
"src/coap_session.c",
|
||||
"src/coap_tcp.c",
|
||||
"src/coap_time.c",
|
||||
"src/coap_tinydtls.c",
|
||||
"src/encode.c",
|
||||
"src/mem.c",
|
||||
"src/net.c",
|
||||
|
||||
@@ -7,8 +7,8 @@ To get the libcoap library source, you need to do either the following
|
||||
|
||||
* Obtain the latest distribution package file from
|
||||
https://github.com/obgm/libcoap/archive/develop.zip
|
||||
[There is a stable master version at
|
||||
https://github.com/obgm/libcoap/archive/master.zip]
|
||||
[There is a stable version at
|
||||
https://github.com/obgm/libcoap/archive/main.zip]
|
||||
* Change to the directory that you want to install the libcoap sub-directory
|
||||
into
|
||||
* Unpack the distribution package file
|
||||
@@ -21,8 +21,8 @@ or alternatively, clone the libcoap git repository from github
|
||||
* Then clone the latest (develop) version of the code:-
|
||||
git clone https://github.com/obgm/libcoap.git
|
||||
* Change into the top level directory of the cloned files
|
||||
* Optionally, change the branch from develop to the stable master branch:-
|
||||
git checkout master
|
||||
* Optionally, change the branch from develop to the stable main branch:-
|
||||
git checkout main
|
||||
|
||||
Building Libcoap Libraries and Examples
|
||||
=======================================
|
||||
@@ -39,7 +39,29 @@ get the TinyDTLS code into your project, so the TinyDTLS library can be used.
|
||||
git submodule init
|
||||
git submodule update
|
||||
|
||||
General Building (not for LwIP or Contiki - see below)
|
||||
General Building with cmake for linux/windows/macos/android (not for LwIP or Contiki - see below)
|
||||
================
|
||||
|
||||
cmake -E remove_directory build
|
||||
cmake -E make_directory build
|
||||
cd build
|
||||
cmake .. -DENABLE_TESTS=ON
|
||||
cmake --build .
|
||||
[sudo] cmake --build . -- install
|
||||
cd ..
|
||||
|
||||
Note: to see possible options (TLS lib, doc, tests, examples etc.):
|
||||
cmake -LH build
|
||||
|
||||
Note: For Windows, this is supported by Visual Studio Code with CMake extension
|
||||
Note: You must use cmake version >=3.10.
|
||||
|
||||
Note: you can use cmake's find package after installation: find_package(libcoap-2 REQUIRED),
|
||||
and target_link_libraries(myTarget PRIVATE libcoap::coap-2)
|
||||
|
||||
Note: Shared Library support is not currently available for Windows.
|
||||
|
||||
General Building with autoconf (not for LwIP or Contiki - see below)
|
||||
================
|
||||
|
||||
./autogen.sh
|
||||
@@ -53,7 +75,7 @@ that is missing. Install the missing package and try ./autogen.sh again.
|
||||
It is possible that you may need to provide some options to ./configure
|
||||
to customize your installation.
|
||||
|
||||
In particular you may need to define which (D)TLS ligrary to use as well as
|
||||
In particular you may need to define which (D)TLS library to use as well as
|
||||
disable some building of documentation.
|
||||
|
||||
General configure instructions can be found in INSTALL, which is built
|
||||
@@ -131,3 +153,5 @@ You may need to edit win32\libcoap.props to update the OpenSSLRootDir and
|
||||
OpenSSLRootDirDbg variables to point to the top level directory where OpenSSL
|
||||
is installed so that the include, lib etc. directories are correctly set up.
|
||||
Note: Make sure that you include a trailing \ in the variable definitions.
|
||||
|
||||
Alternatively you can build everything in Visual Studio with CMake.
|
||||
|
||||
+673
@@ -0,0 +1,673 @@
|
||||
# CMakeLists.txt for libcoap
|
||||
#
|
||||
# Copyright (C) 2020 Carlos Gomes Martinho <carlos.gomes_martinho@siemens.com>
|
||||
# Copyright (C) 2020-2021 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# This file is part of the CoAP library libcoap. Please see README for terms
|
||||
# of use.
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(
|
||||
libcoap
|
||||
VERSION 4.3.0
|
||||
LANGUAGES CXX C)
|
||||
|
||||
set(LIBCOAP_API_VERSION 3)
|
||||
set(COAP_LIBRARY_NAME "coap-${LIBCOAP_API_VERSION}")
|
||||
|
||||
option(
|
||||
BUILD_SHARED_LIBS
|
||||
"Build shared libs"
|
||||
OFF)
|
||||
|
||||
add_library(${COAP_LIBRARY_NAME})
|
||||
|
||||
#
|
||||
# options to tweak the library
|
||||
#
|
||||
|
||||
option(
|
||||
ENABLE_DTLS
|
||||
"Enable building with DTLS support"
|
||||
ON)
|
||||
set(DTLS_BACKEND
|
||||
"default"
|
||||
CACHE
|
||||
STRING
|
||||
"\
|
||||
Name of the dtls backend, only relevant if `ENABLE_DTLS` is ON which is default. \
|
||||
Possible values: default, gnutls, openssl, tinydtls and mbedtls. \
|
||||
If specified then this library will be searched and if found also used. \
|
||||
If not found then the cmake configuration will stop with an error. \
|
||||
If not specified, then cmake will try to use the first one found in the following order: \
|
||||
gnutls, openssl, tinydtls, mbedtls \
|
||||
")
|
||||
set_property(
|
||||
CACHE DTLS_BACKEND
|
||||
PROPERTY STRINGS
|
||||
default
|
||||
openssl
|
||||
gnutls
|
||||
tinydtls
|
||||
mbedtls)
|
||||
option(
|
||||
USE_VENDORED_TINYDTLS
|
||||
"compile with the tinydtls project in the submodule if on, otherwise try to find the compiled lib with find_package"
|
||||
ON)
|
||||
option(
|
||||
WITH_EPOLL
|
||||
"compile with epoll support"
|
||||
ON)
|
||||
option(
|
||||
ENABLE_SMALL_STACK
|
||||
"Define if the system has small stack size"
|
||||
OFF)
|
||||
option(
|
||||
ENABLE_TCP
|
||||
"Enable building with TCP support"
|
||||
ON)
|
||||
option(
|
||||
ENABLE_TESTS
|
||||
"build also tests"
|
||||
OFF)
|
||||
option(
|
||||
ENABLE_EXAMPLES
|
||||
"build also examples"
|
||||
ON)
|
||||
option(
|
||||
ENABLE_DOCS
|
||||
"build also doxygen documentation"
|
||||
ON)
|
||||
|
||||
if(NOT CMAKE_C_STANDARD)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
include(CheckCSourceCompiles)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckTypeSize)
|
||||
include(TestBigEndian)
|
||||
|
||||
# check for headers
|
||||
check_include_file(byteswap.h HAVE_BYTESWAP_H)
|
||||
check_include_file(inttypes.h HAVE_INTTYPES_H)
|
||||
check_include_file(limits.h HAVE_LIMITS_H)
|
||||
check_include_file(memory.h HAVE_MEMORY_H)
|
||||
check_include_file(strings.h HAVE_STRINGS_H)
|
||||
check_include_file(string.h HAVE_STRING_H)
|
||||
check_include_file(sys/sysctl.h HAVE_SYS_SYSCTL_H)
|
||||
check_include_file(net/if.h HAVE_NET_IF_H)
|
||||
check_include_file(netinet/in.h HAVE_NETINET_IN_H)
|
||||
check_include_file(sys/epoll.h HAVE_EPOLL_H)
|
||||
check_include_file(sys/timerfd.h HAVE_TIMERFD_H)
|
||||
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
|
||||
check_include_file(stdbool.h HAVE_STDBOOL_H)
|
||||
check_include_file(netdb.h HAVE_NETDB_H)
|
||||
check_include_file(pthread.h HAVE_PTHREAD_H)
|
||||
check_include_file(stdlib.h HAVE_STDINT_H)
|
||||
check_include_file(stdint.h HAVE_STDLIB_H)
|
||||
check_include_file(inttypes.h HAVE_INTTYPES_H)
|
||||
check_include_file(syslog.h HAVE_SYSLOG_H)
|
||||
check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
|
||||
check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
|
||||
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
|
||||
check_include_file(sys/time.h HAVE_SYS_TIME_H)
|
||||
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
|
||||
check_include_file(sys/unistd.h HAVE_SYS_UNISTD_H)
|
||||
check_include_file(time.h HAVE_TIME_H)
|
||||
check_include_file(unistd.h HAVE_UNISTD_H)
|
||||
check_include_file(float.h HAVE_FLOAT_H)
|
||||
check_include_file(stddef.h HAVE_STDDEF_H)
|
||||
check_include_file(winsock2.h HAVE_WINSOCK2_H)
|
||||
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)
|
||||
|
||||
# check for functions
|
||||
check_function_exists(malloc HAVE_MALLOC)
|
||||
check_function_exists(memset HAVE_MEMSET)
|
||||
check_function_exists(select HAVE_SELECT)
|
||||
check_function_exists(socket HAVE_SOCKET)
|
||||
check_function_exists(strcasecmp HAVE_STRCASECMP)
|
||||
check_function_exists(pthread_mutex_lock HAVE_PTHREAD_MUTEX_LOCK)
|
||||
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
|
||||
check_function_exists(strnlen HAVE_STRNLEN)
|
||||
check_function_exists(strrchr HAVE_STRRCHR)
|
||||
check_function_exists(getrandom HAVE_GETRANDOM)
|
||||
|
||||
# check for symbols
|
||||
if(WIN32)
|
||||
set(HAVE_STRUCT_CMSGHDR 1)
|
||||
else()
|
||||
check_symbol_exists(
|
||||
cmsghdr
|
||||
sys/socket.h
|
||||
HAVE_STRUCT_CMSGHDR)
|
||||
endif()
|
||||
|
||||
if(${WITH_EPOLL}
|
||||
AND ${HAVE_EPOLL_H}
|
||||
AND ${HAVE_TIMERFD_H})
|
||||
set(COAP_EPOLL_SUPPORT "1")
|
||||
message(STATUS "compiling with epoll support")
|
||||
else()
|
||||
message(STATUS "compiling without epoll support")
|
||||
endif()
|
||||
|
||||
if(ENABLE_SMALL_STACK)
|
||||
set(ENABLE_SMALL_STACK "${ENABLE_SMALL_STACK}")
|
||||
message(STATUS "compiling with small stack support")
|
||||
endif()
|
||||
|
||||
set(WITH_GNUTLS OFF)
|
||||
set(WITH_OPENSSL OFF)
|
||||
set(WITH_TINYDTLS OFF)
|
||||
set(WITH_MBEDTLS OFF)
|
||||
|
||||
function(compile_tinydtls)
|
||||
set(TINYDTLS_SOURCES_DIR ${CMAKE_CURRENT_LIST_DIR}/ext/tinydtls)
|
||||
set(TINYDTLS_SOURCES_GENERATED ${TINYDTLS_SOURCES_DIR}/dtls_config.h)
|
||||
|
||||
message(STATUS "compiling the tinydtls lib")
|
||||
|
||||
include(ExternalProject)
|
||||
|
||||
externalproject_add(
|
||||
external_tinydtls
|
||||
SOURCE_DIR "${TINYDTLS_SOURCES_DIR}"
|
||||
BUILD_IN_SOURCE 1
|
||||
DOWNLOAD_COMMAND ""
|
||||
UPDATE_COMMAND ""
|
||||
CONFIGURE_COMMAND
|
||||
${TINYDTLS_SOURCES_DIR}/configure
|
||||
--disable-manpages
|
||||
--prefix=${CMAKE_BINARY_DIR}
|
||||
BUILD_COMMAND make install
|
||||
INSTALL_COMMAND ""
|
||||
LOG_DOWNLOAD 1
|
||||
LOG_CONFIGURE 1)
|
||||
|
||||
externalproject_add_step(
|
||||
external_tinydtls autoreconf
|
||||
COMMAND autoreconf --force --install
|
||||
ALWAYS 1
|
||||
WORKING_DIRECTORY "${TINYDTLS_SOURCES_DIR}"
|
||||
DEPENDERS configure
|
||||
DEPENDEES download)
|
||||
|
||||
# Let cmake know that it needs to execute the external_tinydtls target to generate those files.
|
||||
add_custom_command(
|
||||
OUTPUT ${TINYDTLS_SOURCES_GENERATED}
|
||||
WORKING_DIRECTORY "${TINYDTLS_SOURCES_DIR}"
|
||||
COMMAND "make install"
|
||||
DEPENDS external_tinydtls)
|
||||
|
||||
add_dependencies(${COAP_LIBRARY_NAME} external_tinydtls)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(LIBTINYDTLS_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib/libtinydtls.so")
|
||||
else()
|
||||
set(LIBTINYDTLS_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib/libtinydtls.a")
|
||||
endif()
|
||||
|
||||
add_library(
|
||||
tinydtls
|
||||
UNKNOWN
|
||||
IMPORTED)
|
||||
set_target_properties(
|
||||
tinydtls
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${LIBTINYDTLS_PATH}")
|
||||
|
||||
endfunction()
|
||||
|
||||
if(ENABLE_DTLS)
|
||||
message(STATUS "compiling with DTLS support")
|
||||
message(STATUS "DTLS_BACKEND: ${DTLS_BACKEND}")
|
||||
|
||||
if(DTLS_BACKEND
|
||||
STREQUAL
|
||||
"default")
|
||||
# try to find a crypto lib and use it, use the first one found
|
||||
|
||||
# libgnutls (e.g. debian libgnutls28-dev)
|
||||
find_package(GnuTLS)
|
||||
if(GnuTLS_FOUND)
|
||||
set(WITH_GNUTLS ON)
|
||||
message(STATUS "compiling with gnutls support")
|
||||
set(HAVE_LIBGNUTLS 1)
|
||||
else()
|
||||
# gnutls not found
|
||||
find_package(OpenSSL)
|
||||
if(OpenSSL_FOUND)
|
||||
set(WITH_OPENSSL ON)
|
||||
message(STATUS "compiling with openssl support")
|
||||
set(HAVE_OPENSSL 1)
|
||||
else()
|
||||
# openssl not found
|
||||
# libmbedtls (e.g. debian libmbedtls-dev)
|
||||
find_package(MbedTLS)
|
||||
if(MbedTLS_FOUND)
|
||||
set(WITH_MBEDTLS ON)
|
||||
message(STATUS "compiling with mbedtls support")
|
||||
set(HAVE_MBEDTLS 1)
|
||||
else()
|
||||
# mbedtls not found
|
||||
if(USE_VENDORED_TINYDTLS)
|
||||
compile_tinydtls()
|
||||
else()
|
||||
find_package(TinyDTLS)
|
||||
if(TINYDTLS_FOUND)
|
||||
|
||||
else()
|
||||
# no cryto lib found
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"cannot find any cryto lib, either install one or compile without DTLS support"
|
||||
)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
set(WITH_TINYDTLS ON)
|
||||
message(STATUS "compiling with tinydtls support")
|
||||
set(HAVE_LIBTINYDTLS 1)
|
||||
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
else()
|
||||
# DTLS_BACKEND variable is not empty, so set all to false and set the only right to true
|
||||
set(WITH_GNUTLS OFF)
|
||||
set(WITH_TINYDTLS OFF)
|
||||
set(WITH_MBEDTLS OFF)
|
||||
set(WITH_OPENSSL OFF)
|
||||
|
||||
if(DTLS_BACKEND
|
||||
STREQUAL
|
||||
"gnutls")
|
||||
# libgnutls (e.g. debian libgnutls28-dev)
|
||||
find_package(GnuTLS REQUIRED)
|
||||
set(WITH_GNUTLS ON)
|
||||
message(STATUS "compiling with gnutls support")
|
||||
set(HAVE_LIBGNUTLS 1)
|
||||
endif()
|
||||
|
||||
if(DTLS_BACKEND
|
||||
STREQUAL
|
||||
"openssl")
|
||||
# libssl (e.g. debian libssl1.0-dev)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
set(WITH_OPENSSL ON)
|
||||
message(STATUS "compiling with openssl support")
|
||||
set(HAVE_OPENSSL 1)
|
||||
endif()
|
||||
|
||||
if(DTLS_BACKEND
|
||||
STREQUAL
|
||||
"mbedtls")
|
||||
# libmbedtls (e.g. debian libmbedtls-dev)
|
||||
find_package(MbedTLS REQUIRED)
|
||||
set(WITH_MBEDTLS ON)
|
||||
message(STATUS "compiling with mbedtls support")
|
||||
set(HAVE_MBEDTLS 1)
|
||||
endif()
|
||||
|
||||
if(DTLS_BACKEND
|
||||
STREQUAL
|
||||
"tinydtls")
|
||||
|
||||
if(USE_VENDORED_TINYDTLS)
|
||||
compile_tinydtls()
|
||||
else(USE_VENDORED_TINYDTLS)
|
||||
find_package(TinyDTLS REQUIRED)
|
||||
endif(USE_VENDORED_TINYDTLS)
|
||||
|
||||
message(STATUS "compiling with tinydtls support")
|
||||
set(WITH_TINYDTLS ON)
|
||||
set(HAVE_LIBTINYDTLS 1)
|
||||
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
message(STATUS "ENABLE_DTLS:.....................${ENABLE_DTLS}")
|
||||
message(STATUS "ENABLE_TCP:......................${ENABLE_TCP}")
|
||||
message(STATUS "ENABLE_DOCS:.....................${ENABLE_DOCS}")
|
||||
message(STATUS "ENABLE_EXAMPLES:.................${ENABLE_EXAMPLES}")
|
||||
message(STATUS "DTLS_BACKEND:....................${DTLS_BACKEND}")
|
||||
message(STATUS "WITH_GNUTLS:.....................${WITH_GNUTLS}")
|
||||
message(STATUS "WITH_TINYDTLS:...................${WITH_TINYDTLS}")
|
||||
message(STATUS "WITH_OPENSSL:....................${WITH_OPENSSL}")
|
||||
message(STATUS "WITH_MBEDTLS:....................${WITH_MBEDTLS}")
|
||||
message(STATUS "HAVE_LIBTINYDTLS:................${HAVE_LIBTINYDTLS}")
|
||||
message(STATUS "HAVE_LIBGNUTLS:..................${HAVE_LIBGNUTLS}")
|
||||
message(STATUS "HAVE_OPENSSL:....................${HAVE_OPENSSL}")
|
||||
message(STATUS "HAVE_MBEDTLS:....................${HAVE_MBEDTLS}")
|
||||
message(STATUS "COAP_EPOLL_SUPPORT:..............${COAP_EPOLL_SUPPORT}")
|
||||
message(STATUS "CMAKE_C_COMPILER:................${CMAKE_C_COMPILER}")
|
||||
message(STATUS "BUILD_SHARED_LIBS:...............${BUILD_SHARED_LIBS}")
|
||||
message(STATUS "CMAKE_BUILD_TYPE:................${CMAKE_BUILD_TYPE}")
|
||||
message(STATUS "CMAKE_SYSTEM_PROCESSOR:..........${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
||||
set(PACKAGE_URL "https://libcoap.net/")
|
||||
set(PACKAGE_NAME "${PROJECT_NAME}")
|
||||
set(PACKAGE_TARNAME "${PROJECT_NAME}")
|
||||
set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
|
||||
set(PACKAGE_VERSION "${PROJECT_VERSION}")
|
||||
set(LIBCOAP_PACKAGE_VERSION "${PROJECT_VERSION}")
|
||||
set(LIBCOAP_PACKAGE_URL "${PACKAGE_URL}")
|
||||
set(LIBCOAP_PACKAGE_NAME "${PROJECT_NAME}")
|
||||
set(LIBCOAP_PACKAGE_STRING "TODO")
|
||||
set(LIBCOAP_PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net")
|
||||
set(PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net")
|
||||
set(top_srcdir "${CMAKE_CURRENT_LIST_DIR}")
|
||||
set(top_builddir "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
if(ENABLE_TCP)
|
||||
set(COAP_DISABLE_TCP 0)
|
||||
else(ENABLE_TCP)
|
||||
set(COAP_DISABLE_TCP 1)
|
||||
endif(ENABLE_TCP)
|
||||
|
||||
# creates config header file in build directory
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/coap${LIBCOAP_API_VERSION}/coap.h)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake_coap_config.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/coap_config.h)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h.in
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h)
|
||||
|
||||
#
|
||||
# sources
|
||||
#
|
||||
|
||||
target_sources(
|
||||
${COAP_LIBRARY_NAME}
|
||||
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/address.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/net.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_debug.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/encode.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/uri.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/subscribe.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/resource.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/str.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/option.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/async.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/block.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_asn1.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_cache.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_debug.c
|
||||
${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_notls.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_prng.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_session.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_tcp.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/coap_time.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/option.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/pdu.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/resource.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/str.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/subscribe.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/uri.c
|
||||
# no need to parse those files if we do not need them
|
||||
$<$<BOOL:${HAVE_OPENSSL}>:${CMAKE_CURRENT_LIST_DIR}/src/coap_openssl.c>
|
||||
$<$<BOOL:${HAVE_LIBTINYDTLS}>:${CMAKE_CURRENT_LIST_DIR}/src/coap_tinydtls.c>
|
||||
$<$<BOOL:${HAVE_LIBGNUTLS}>:${CMAKE_CURRENT_LIST_DIR}/src/coap_gnutls.c>
|
||||
$<$<BOOL:${HAVE_MBEDTLS}>:${CMAKE_CURRENT_LIST_DIR}/src/coap_mbedtls.c>
|
||||
# headers
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/address.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/async.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/block.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_cache.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_debug.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_dtls.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_event.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_hashkey.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap.h.in
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_io.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_session.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_time.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}/option.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/pdu.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_prng.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/resource.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/str.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/subscribe.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/uri.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/uthash.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/utlist.h)
|
||||
target_include_directories(
|
||||
${COAP_LIBRARY_NAME}
|
||||
PUBLIC # config headers are generated during configuration time
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/>
|
||||
$<INSTALL_INTERFACE:include/>
|
||||
$<$<AND:$<BOOL:${HAVE_LIBTINYDTLS}>,$<BOOL:${USE_VENDORED_TINYDTLS}>>:${CMAKE_BINARY_DIR}/include/tinydtls>
|
||||
$<$<BOOL:${HAVE_LIBGNUTLS}>:${GNUTLS_INCLUDE_DIR}>
|
||||
$<$<BOOL:${HAVE_LIBGNUTLS}>:${MBEDTLS_INCLUDE_DIRS}>)
|
||||
target_link_libraries(
|
||||
${COAP_LIBRARY_NAME}
|
||||
PUBLIC $<$<BOOL:${HAVE_OPENSSL}>:OpenSSL::SSL>
|
||||
$<$<BOOL:${HAVE_OPENSSL}>:OpenSSL::Crypto>
|
||||
$<$<BOOL:${HAVE_LIBGNUTLS}>:${GNUTLS_LIBRARIES}>
|
||||
$<$<BOOL:${HAVE_LIBTINYDTLS}>:tinydtls>
|
||||
$<$<BOOL:${HAVE_MBEDTLS}>:${MBEDTLS_LIBRARY}>
|
||||
$<$<BOOL:${HAVE_MBEDTLS}>:${MBEDX509_LIBRARY}>
|
||||
$<$<BOOL:${HAVE_MBEDTLS}>:${MBEDCRYPTO_LIBRARY}>)
|
||||
|
||||
add_library(
|
||||
${PROJECT_NAME}::${COAP_LIBRARY_NAME}
|
||||
ALIAS
|
||||
${COAP_LIBRARY_NAME})
|
||||
|
||||
#
|
||||
# compiler options
|
||||
#
|
||||
|
||||
add_compile_options(
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-pedantic>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wcast-qual>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wextra>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wformat-security>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Winline>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wmissing-declarations>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wmissing-prototypes>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wnested-externs>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wpointer-arith>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wshadow>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wstrict-prototypes>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wswitch-default>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wswitch-enum>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wunused>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wwrite-strings>)
|
||||
|
||||
#
|
||||
# tests
|
||||
#
|
||||
|
||||
if(ENABLE_TESTS)
|
||||
add_executable(
|
||||
testdriver
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/testdriver.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_common.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_encode.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_encode.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_error_response.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_error_response.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_options.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_options.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_pdu.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_pdu.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_sendqueue.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_sendqueue.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_session.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_session.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_tls.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_tls.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_uri.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_uri.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_wellknown.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/test_wellknown.h)
|
||||
# tests require libcunit (e.g. debian libcunit1-dev)
|
||||
target_link_libraries(testdriver PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME}
|
||||
-lcunit)
|
||||
endif()
|
||||
|
||||
#
|
||||
# examples
|
||||
#
|
||||
|
||||
if(ENABLE_EXAMPLES)
|
||||
add_executable(coap-client ${CMAKE_CURRENT_LIST_DIR}/examples/coap-client.c)
|
||||
target_link_libraries(coap-client
|
||||
PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
|
||||
|
||||
add_executable(coap-rd ${CMAKE_CURRENT_LIST_DIR}/examples/coap-rd.c)
|
||||
target_include_directories(coap-rd
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}>)
|
||||
target_link_libraries(coap-rd PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
|
||||
|
||||
add_executable(coap-server ${CMAKE_CURRENT_LIST_DIR}/examples/coap-server.c)
|
||||
target_link_libraries(coap-server
|
||||
PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
|
||||
|
||||
if(NOT WIN32)
|
||||
add_executable(etsi_iot_01 ${CMAKE_CURRENT_LIST_DIR}/examples/etsi_iot_01.c)
|
||||
target_link_libraries(etsi_iot_01
|
||||
PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
|
||||
|
||||
add_executable(tiny ${CMAKE_CURRENT_LIST_DIR}/examples/tiny.c)
|
||||
target_link_libraries(tiny PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#
|
||||
# docs
|
||||
#
|
||||
|
||||
if(ENABLE_DOCS)
|
||||
find_package(Doxygen)
|
||||
|
||||
if(Doxygen_FOUND)
|
||||
# set input and output files
|
||||
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in)
|
||||
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
|
||||
# Make necessary temporary directories
|
||||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/doc/man_tmp)
|
||||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/doc/man_html)
|
||||
|
||||
# request to configure the file
|
||||
configure_file(
|
||||
${DOXYGEN_IN}
|
||||
${DOXYGEN_OUT}
|
||||
@ONLY)
|
||||
|
||||
# note the option ALL which allows to build the docs together with the
|
||||
# application
|
||||
add_custom_target(
|
||||
doc_doxygen ALL
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Doxygen"
|
||||
VERBATIM)
|
||||
|
||||
message(STATUS "Setup up the Doxygen documention build")
|
||||
|
||||
else(Doxygen_FOUND)
|
||||
message(
|
||||
WARNING
|
||||
"Doxygen need to be installed to generate the doxygen documentation")
|
||||
endif(Doxygen_FOUND)
|
||||
|
||||
endif()
|
||||
|
||||
#
|
||||
# install
|
||||
#
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
set(LIBCOAP_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
install(
|
||||
TARGETS ${COAP_LIBRARY_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib)
|
||||
|
||||
install(
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
DESTINATION ${LIBCOAP_CONFIG_INSTALL_DIR}
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
COMPONENT dev)
|
||||
|
||||
configure_package_config_file(
|
||||
cmake/Config.cmake.in
|
||||
${PROJECT_NAME}Config.cmake
|
||||
INSTALL_DESTINATION
|
||||
${LIBCOAP_CONFIG_INSTALL_DIR})
|
||||
write_basic_package_version_file(
|
||||
${PROJECT_NAME}ConfigVersion.cmake
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
DESTINATION ${LIBCOAP_CONFIG_INSTALL_DIR}
|
||||
COMPONENT dev)
|
||||
|
||||
install(
|
||||
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
COMPONENT dev
|
||||
FILES_MATCHING
|
||||
PATTERN "*.h"
|
||||
PATTERN "coap.h" EXCLUDE
|
||||
PATTERN "coap_riot.h" EXCLUDE
|
||||
PATTERN "lwippools.h" EXCLUDE
|
||||
PATTERN "utlist.h" EXCLUDE
|
||||
PATTERN "*_internal.h" EXCLUDE)
|
||||
install(
|
||||
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
COMPONENT dev
|
||||
FILES_MATCHING
|
||||
PATTERN "*.h")
|
||||
+1
-1
@@ -51,7 +51,7 @@ The archive of the list can be found on:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
As written above libcoap is maintained with the Git tools so you should be
|
||||
familiar with the various git commands.
|
||||
The libcoap project is using just two main branches, the 'master' branch is
|
||||
The libcoap project is using just two main branches, the 'main' branch is
|
||||
holding the point releases, all the development process is going on in the
|
||||
'develop' branch.
|
||||
To start any contributing you first have to clone the git tree from the main
|
||||
|
||||
@@ -1,3 +1,69 @@
|
||||
2021-05-04 Olaf Bergmann <bergmann@tzi.org>
|
||||
|
||||
Change summary for version 4.3.0:
|
||||
|
||||
* Include directory updated from include/coap2 to include/coap3 as
|
||||
this is a major version change.
|
||||
* Other code references updated from coap2 to coap3.
|
||||
* Examples now have the underlying (D)TLS library name as a suffix.
|
||||
E.g. coap-server-openssl
|
||||
* Examples and libraries can be installed with default names using
|
||||
./configure --enable-add-default-names
|
||||
* Many call-back handlers have had their parameter lists changed, some
|
||||
variables are made const and other ones removed as they can be easily
|
||||
reconstructed if needed.
|
||||
* Some functions have their parameters changed to const.
|
||||
* Internal structures made opaque to applications, requiring the
|
||||
applications to access the structure information via a new set of
|
||||
functions. The new functions are of the form coap_X_get_Y() or
|
||||
coap_X_set_Y() where X is the structure (e.g. session) and Y is
|
||||
the variable.
|
||||
* coap_async_state_t
|
||||
* coap_attr_t
|
||||
* coap_context_t
|
||||
* coap_packet_t
|
||||
* coap_pdu_t
|
||||
* coap_resource_t
|
||||
* coap_session_t
|
||||
* coap_socket_t
|
||||
* Header files are moved into libcoap space and so are accessed by coap
|
||||
sub-directory - e.g. #include <coap3/coap.h>.
|
||||
* RFC7959 (Block handling) moved into libcoap from application code
|
||||
considerably simplifying application code. See coap_block(3) man page.
|
||||
* CoAP Cache Key support.
|
||||
* Support for cmake builds.
|
||||
* Support for RIOT builds.
|
||||
* Support for Cygwin builds.
|
||||
* Proxy support for coap-server, enhanced coap-client capabilities
|
||||
* Updated async support.
|
||||
* Multicast requests now randomly delayed befor ethe response is
|
||||
sent.
|
||||
* Additional RFC support - RFC8768.
|
||||
* Mbed TLS DTLS library support.
|
||||
* (D)TLS support for RPK and PKCS11.
|
||||
* Additional (D)TLS support for PSK (e.g. Identity Hints).
|
||||
* PKI support consistent across all supported (D)TLS libraries.
|
||||
* Support for disabling TCP for code reduction.
|
||||
* More rigorous checking and appropriate rejection of inbound PDU
|
||||
options.
|
||||
* Additional unit tests.
|
||||
* Reported bugs fixed.
|
||||
* Example applications help reports on (D)TLS library capabilities
|
||||
and versions.
|
||||
* Documentation added and updated (Doxygen and man).
|
||||
|
||||
2019-11-05 Olaf Bergmann <bergmann@tzi.org>
|
||||
|
||||
Change summary for version 4.2.1:
|
||||
|
||||
* Builds now support silent rules
|
||||
* Support building with TinyDTLS as a shared library
|
||||
* Added in EPOLL support
|
||||
* Added in support for constrained stacks
|
||||
* Server sessions hashed for performance lookup
|
||||
* coap_endpoint_t and coap_subscription_t made opaque to applications
|
||||
* Documentation updated
|
||||
|
||||
2019-02-11 Olaf Bergmann <bergmann@tzi.org>
|
||||
|
||||
Change summary for version 4.2.0:
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
############################################################################
|
||||
#
|
||||
# GnuTLS dual versions
|
||||
#
|
||||
# Works with CentOS 7
|
||||
#
|
||||
############################################################################
|
||||
#
|
||||
# Add in alternative GnuTLS support into /usr/local, and put all the
|
||||
# libraries into /usr/local/lib.
|
||||
#
|
||||
# Need the latest of the following packages
|
||||
#
|
||||
# gmp (used 6.2.0) https://gmplib.org/#DOWNLOAD
|
||||
# nettle (used 3.6) https://ftp.gnu.org/gnu/nettle/
|
||||
# gnutls (used 3.6.13) https://www.gnutls.org/download.html
|
||||
#
|
||||
|
||||
GMP_VER=6.2.0
|
||||
NETTLE_VER=3.6
|
||||
GNUTLS_VER=3.6.13
|
||||
|
||||
#
|
||||
# gmp
|
||||
#
|
||||
tar xovf gmp-${GMP_VER}.tar.xz
|
||||
cd gmp-${GMP_VER}
|
||||
./configure
|
||||
make
|
||||
sudo make install
|
||||
cd ..
|
||||
|
||||
#
|
||||
# nettle (by default wants to go into /usr/local/lib64 which gets messy)
|
||||
#
|
||||
tar zxovf nettle-${NETTLE_VER}.tar.gz
|
||||
cd nettle-${NETTLE_VER}
|
||||
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --libdir=/usr/local/lib \
|
||||
LDFLAGS="-L/usr/local/lib"
|
||||
make
|
||||
sudo make install
|
||||
cd ..
|
||||
|
||||
tar xovf gnutls-${GNUTLS_VER}.tar.xz
|
||||
cd gnutls-${GNUTLS_VER}
|
||||
#
|
||||
#
|
||||
# You may need to make the following change if you have an old version of
|
||||
# p11-kit
|
||||
#
|
||||
# $ diff -Nau a/lib/pkcs11_privkey.c b/lib/pkcs11_privkey.c
|
||||
# --- a/lib/pkcs11_privkey.c 2020-05-26 11:49:27.374385645 +0100
|
||||
# +++ b/lib/pkcs11_privkey.c 2020-05-26 11:58:24.300510455 +0100
|
||||
# @@ -265,13 +265,13 @@
|
||||
# # define CKG_MGF1_SHA384 0x00000003UL
|
||||
# # define CKG_MGF1_SHA512 0x00000004UL
|
||||
#
|
||||
# +#endif
|
||||
# struct ck_rsa_pkcs_pss_params {
|
||||
# ck_mechanism_type_t hash_alg;
|
||||
# /* ck_rsa_pkcs_mgf_type_t is not defined in old versions of p11-kit */
|
||||
# unsigned long mgf;
|
||||
# unsigned long s_len;
|
||||
# };
|
||||
# -#endif
|
||||
#
|
||||
# static const struct hash_mappings_st hash_mappings[] =
|
||||
# {
|
||||
#
|
||||
#
|
||||
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --with-included-unistring \
|
||||
--disable-hardware-acceleration --disable-tests --with-included-libtasn1 \
|
||||
--disable-doc LDFLAGS="-L/usr/local/lib"
|
||||
make
|
||||
sudo make install
|
||||
cd ..
|
||||
|
||||
############################################################################
|
||||
#
|
||||
# libcoap build with updated GnuTLS
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Get the latest libcoap
|
||||
git clone https://github.com/obgm/libcoap.git
|
||||
|
||||
# Build code
|
||||
cd libcoap
|
||||
./autogen.sh
|
||||
# Update --enable- / --disable- options as appropriate
|
||||
# libcoap libraries are put into /usr/lib64 for ease of linking
|
||||
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --libdir=/usr/lib64 \
|
||||
--with-gnutls --enable-tests --enable-examples --disable-doxygen \
|
||||
--enable-manpages
|
||||
make
|
||||
sudo make install
|
||||
cd ..
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
############################################################################
|
||||
#
|
||||
# OpenSSL dual versions
|
||||
#
|
||||
# Works with CentOS 7
|
||||
#
|
||||
############################################################################
|
||||
#
|
||||
# Add in alternative OpenSSL support into /opt/openssl. /opt/openssl is
|
||||
# chosen instead of the default of /usr/local so that existing utilities
|
||||
# continue to use the original version of OpenSSL and so only specific
|
||||
# applications that requires the newer version of OpenSSL will pick up the
|
||||
# new code.
|
||||
#
|
||||
# Download latest stable version of openssl.X.Y.Z.tar.gz from
|
||||
# https://www.openssl.org/source/
|
||||
|
||||
tar zxovf openssl.X.Y.Z.tar.gz
|
||||
cd openssl.X.Y.X
|
||||
./config --prefix=/opt/openssl --openssldir=/opt/openssl
|
||||
make
|
||||
sudo make install_sw
|
||||
|
||||
# The following should not clash the existing OpenSSL lib*.so.1.0 usage unless
|
||||
# the previous OpenSSL version is 1.1.0 or later.
|
||||
# It just makes things for running executables a lot simpler.
|
||||
sudo cp /opt/openssl/lib/lib*.so.1.1 /lib64
|
||||
cd ..
|
||||
|
||||
############################################################################
|
||||
#
|
||||
# libcoap build with updated OpenSSL
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Get the latest libcoap
|
||||
git clone https://github.com/obgm/libcoap.git
|
||||
|
||||
# Build code
|
||||
cd libcoap
|
||||
./autogen.sh
|
||||
# Update --enable- / --disable- options as appropriate
|
||||
# libcoap libraries are put into /usr/lib64 for ease of linking
|
||||
PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig ./configure --libdir=/usr/lib64 \
|
||||
--with-openssl --enable-tests --enable-examples --disable-doxygen \
|
||||
--disable-manpages
|
||||
make
|
||||
sudo make install
|
||||
cd ..
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
############################################################################
|
||||
#
|
||||
# SoftHSMv2 dual versions
|
||||
#
|
||||
# Works with CentOS 7
|
||||
#
|
||||
# The opensc package needs to be installed.
|
||||
#
|
||||
############################################################################
|
||||
#
|
||||
# Install a software HSM module for doing the PKCS11 testing of libcoap.
|
||||
# Real hardware can be used if you have the appropriate library module.
|
||||
#
|
||||
# It is assumed that the opensc package is installed.
|
||||
#
|
||||
# When installing SoftHSMv2 from your system's package manager, check that the
|
||||
# OpenSSL version is at least 1.1.0. If not, then you will need to dual
|
||||
# install SoftHSMv2 as below; otherwise you can use the existing SoftHSMv2.
|
||||
#
|
||||
# SoftHSMv2 is built using OpenSSL, but GnuTLS can use the PKCS11 interface.
|
||||
# Note that if the default OpenSSL version is less than 1.1.0, you will need
|
||||
# to install a dual stack version of OpenSSL as per HOWTO.dual.openssl.
|
||||
#
|
||||
# Creates module /usr/local/lib/softhsm/libsofthsm2.so
|
||||
#
|
||||
|
||||
# Add line below to /etc/security/limits.conf to support memory locking
|
||||
|
||||
* - memlock unlimited
|
||||
|
||||
# Get the latest SoftHSM
|
||||
git clone https://github.com/opendnssec/SoftHSMv2.git
|
||||
|
||||
# Build code
|
||||
cd SoftHSMv2/
|
||||
sh autogen.sh
|
||||
PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig ./configure --enable-silent-rules \
|
||||
--with-crypto-backend=openssl --disable-gost LDFLAGS=-L/opt/openssl/lib \
|
||||
CPPFLAGS=-I/opt/openssl/include --with-openssl=/opt/openssl
|
||||
make
|
||||
# You may need to comment out constexpr lines (fixes for gcc10) in
|
||||
# src/lib/crypto/PublicKey.h src/lib/crypto/PrivateKey.h if you get
|
||||
# compile errors.
|
||||
sudo make install
|
||||
cd ..
|
||||
|
||||
# Make sure p11-kit softhsm modules have the correct module: fully qualified
|
||||
# path where the entry is of the form (in particular for GnuTLS) :-
|
||||
# /usr/share/p11-kit/modules/softhsm*
|
||||
#
|
||||
# module: /usr/local/lib/softhsm/libsofthsm2.so
|
||||
|
||||
# The user you are running this as needs to be in the group defined for
|
||||
# /var/lib/softhsm/tokens/. E.g.
|
||||
# $ sudo ls -ld /var/lib/softhsm/tokens/
|
||||
# drwxrws--- 3 root softhsm 4096 May 3 09:52 /var/lib/softhsm/tokens/
|
||||
# which is softhsm in this case (It could be ods). To verify if you are in
|
||||
# the correct group
|
||||
# $ id
|
||||
# To add user to this group
|
||||
# $ sudo usermod -a -G softhsm <user>
|
||||
# and log out and back in again.
|
||||
#
|
||||
|
||||
############################################################################
|
||||
#
|
||||
# libp11 (needed for OpenSSL as it provides the PKCS11 engine)
|
||||
#
|
||||
############################################################################
|
||||
#
|
||||
# Install a pkcs11 library for OpenSSL to use as an engine.
|
||||
# [GnuTLS has this built in]
|
||||
#
|
||||
|
||||
# Get the latest libp11
|
||||
git clone https://github.com/OpenSC/libp11.git
|
||||
|
||||
# Build code
|
||||
cd libp11
|
||||
./bootstrap
|
||||
PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig ./configure \
|
||||
--with-pkcs11-module=/usr/local/lib/softhsm/libsofthsm2.so
|
||||
make
|
||||
sudo make install
|
||||
cd ..
|
||||
|
||||
# Verify that pkcs11 is available
|
||||
|
||||
/opt/openssl/bin/openssl engine pkcs11 -t
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
#
|
||||
# Using PKCS11 with libcoap.
|
||||
#
|
||||
# This HOWTO works for CentOS 7.
|
||||
#
|
||||
# As CentOS 7 uses OpenSSL prior to 1.1.0, dual OpenSSL support needs to be
|
||||
# set up and used for libcoap. See HOWTO.dual.openssl for setting this up.
|
||||
#
|
||||
# It also is possible that you want to use GnuTLS - and want to use a later
|
||||
# version. HOWTO.dual.gnutls for setting this up.
|
||||
#
|
||||
# OpenSSL and GnuTLS are currently supported
|
||||
#
|
||||
|
||||
############################################################################
|
||||
#
|
||||
# Testing examples
|
||||
#
|
||||
############################################################################
|
||||
#
|
||||
# Update PKCS11 token with certificates and keys
|
||||
#
|
||||
# Assumption is that you already have the following PEM files
|
||||
# ca-cert.pem - The certificate of the CA that signed Server and Client
|
||||
# server-cert.pem - Contains the server certificate in PEM format
|
||||
# server-key.pem - Contains the server private key in PEM format
|
||||
# client-cert.pem - Contains the server certificate in PEM format
|
||||
# client-key.pem - Contains the server private key in PEM format
|
||||
#
|
||||
# Tokens will be stored under /var/lib/softhsm/tokens/
|
||||
#
|
||||
# The user you are running this as needs to be in the group defined for
|
||||
# /var/lib/softhsm/tokens/. E.g.
|
||||
# $ sudo ls -ld /var/lib/softhsm/tokens/
|
||||
# drwxrws--- 3 root softhsm 4096 May 3 09:52 /var/lib/softhsm/tokens/
|
||||
# which is softhsm in this case (It could be ods). To verify if you are in
|
||||
# the correct group
|
||||
# $ id
|
||||
# To add user to this group
|
||||
# $ sudo usermod -a -G softhsm <user>
|
||||
# and log out and back in again.
|
||||
#
|
||||
|
||||
# Set libsofthsm2.so to use (may be /usr/lib/softhsm/libsofthsm2.so)
|
||||
LIBSOFTHSM=/usr/local/lib/softhsm/libsofthsm2.so
|
||||
|
||||
# Initialize Soft HSM token
|
||||
# Note: slot 0 is re-allocated to slot XXX. This is presented as a decimal
|
||||
# number, the hex equivalent (leading 0x) can be used for any slot options..
|
||||
# Set SO PIN to 4321, user PIN to 1234
|
||||
softhsm2-util --init-token --slot 0 --label "token-0" --pin 1234 --so-pin 4321
|
||||
|
||||
# CA Certificate (different id to Server/Client Public Certificate)
|
||||
# (GnuTLS requires this to be trusted)
|
||||
p11tool --so-login --load-certificate ca-cert.pem --write --label ca-cert \
|
||||
--set-so-pin 4321 --id cc00 --mark-trusted "pkcs11:token=token-0"
|
||||
|
||||
# Server Private Key
|
||||
openssl pkcs8 -topk8 -inform PEM -outform PEM -in server-key.pem \
|
||||
-out server-key.pk8 -nocrypt
|
||||
softhsm2-util --import server-key.pk8 --label "server-key" --id aa00 \
|
||||
--pin 1234 --token "token-0"
|
||||
|
||||
# Server Public Certificate
|
||||
# (Use different id to private key, but not the same as CA/Client cert)
|
||||
openssl x509 -in server-cert.pem -out server-cert.der -outform DER
|
||||
pkcs11-tool --module $LIBSOFTHSM --pin 1234 \
|
||||
--write-object ./server-cert.der --type cert --id aa01 \
|
||||
--label "server-cert" --token-label "token-0"
|
||||
|
||||
# Client Private Key
|
||||
openssl pkcs8 -topk8 -inform PEM -outform PEM -in client-key.pem \
|
||||
-out client-key.pk8 -nocrypt
|
||||
softhsm2-util --import client-key.pk8 --label "client-key" --id bb00 \
|
||||
--pin 1234 --token "token-0"
|
||||
|
||||
# Client Public Certificate
|
||||
# (Use different id to private key, but not the same as CA/Client cert)
|
||||
openssl x509 -in client-cert.pem -out client-cert.der -outform DER
|
||||
pkcs11-tool --module $LIBSOFTHSM --pin 1234 \
|
||||
--write-object ./client-cert.der --type cert --id bb01 \
|
||||
--label "client-cert" --token-label "token-0"
|
||||
|
||||
# Verify token is correctly populated
|
||||
pkcs11-tool --module=$LIBSOFTHSM -t
|
||||
pkcs11-tool --module=$LIBSOFTHSM --list-objects \
|
||||
--pin 1234 --token-label "token-0"
|
||||
p11tool --list-all pkcs11:model=SoftHSM%20v2
|
||||
|
||||
#
|
||||
# Run coap-server using PKCS11 (-C option may need to be -C cert.der)
|
||||
#
|
||||
coap-server -C 'pkcs11:token=token-0;id=%cc%00?pin-value=1234' \
|
||||
-c 'pkcs11:token=token-0;id=%aa%01?pin-value=1234' \
|
||||
-j 'pkcs11:token=token-0;id=%aa%00?pin-value=1234' -v9
|
||||
|
||||
# or
|
||||
coap-server -C 'pkcs11:token=token-0;id=%cc%00' \
|
||||
-c 'pkcs11:token=token-0;id=%aa%01' \
|
||||
-j 'pkcs11:token=token-0;id=%aa%00' -J 1234 -v9
|
||||
|
||||
# or
|
||||
coap-server -C 'pkcs11:token=token-0;object=ca-cert' \
|
||||
-c 'pkcs11:token=token-0;object=server-cert' \
|
||||
-j 'pkcs11:token=token-0;object=server-key' -J 1234 -v9
|
||||
|
||||
#
|
||||
# Run coap-client using PKCS11 (-C option may need to be -C cert.der)
|
||||
#
|
||||
coap-client -C 'pkcs11:token=token-0;id=%cc%00?pin-value=1234' \
|
||||
-c 'pkcs11:token=token-0;id=%bb%01?pin-value=1234' \
|
||||
-j 'pkcs11:token=token-0;id=%bb%00?pin-value=1234' -v9 coaps://[::1]
|
||||
|
||||
# or
|
||||
coap-client -C 'pkcs11:token=token-0;id=%cc%00' \
|
||||
-c 'pkcs11:token=token-0;id=%bb%01' \
|
||||
-j 'pkcs11:token=token-0;id=%bb%00' -J 1234 -v9 coaps://[::1]
|
||||
|
||||
# or
|
||||
coap-client -C 'pkcs11:token=token-0;object=ca-cert' \
|
||||
-c 'pkcs11:token=token-0;object=client-cert' \
|
||||
-j 'pkcs11:token=token-0;object=client-key' -J 1234 -v9 coaps://[::1]
|
||||
|
||||
#
|
||||
# Client and Server using RPK (GnuTLS only)
|
||||
#
|
||||
coap-server -M 'pkcs11:token=token-0;object=server-key' -J 1234 -v9
|
||||
# and
|
||||
coap-client -M 'pkcs11:token=token-0;object=client-key' -J 1234 -v9 coaps://[::1]
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2010--2019, Olaf Bergmann and others
|
||||
Copyright (c) 2010--2021, Olaf Bergmann and others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,6 +45,14 @@ builds of the executables in the examples folder:
|
||||
* in the public domain.
|
||||
*/
|
||||
|
||||
========================================================================
|
||||
uthash
|
||||
|
||||
libcoap uses uthash.h and utlist.h from Troy D. Hanson
|
||||
(https://troydhanson.github.io/uthash/). These files use the revised
|
||||
BSD license (BSD-1-Clause license) as included in these two source
|
||||
files.
|
||||
|
||||
========================================================================
|
||||
OpenSSL
|
||||
|
||||
@@ -68,3 +76,10 @@ When compiled with tinyDTLS support, this software includes components
|
||||
that are licensed under the terms of the Eclipse Distribution License 1.0
|
||||
(http://www.eclipse.org/org/documents/edl-v10.php).
|
||||
|
||||
========================================================================
|
||||
Mbed TLS
|
||||
|
||||
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).
|
||||
|
||||
|
||||
+68
-49
@@ -1,7 +1,10 @@
|
||||
# Makefile.am for libcoap
|
||||
#
|
||||
# Copyright (C) 2010-2017 Olaf Bergmann <bergmann@tzi.org>
|
||||
# (C) 2015-2017 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
# Copyright (C) 2010-2021,2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
# Copyright (C) 2015-2017 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
# Copyright (C) 2018-2021 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
#
|
||||
# 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.
|
||||
@@ -14,18 +17,44 @@ ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
|
||||
|
||||
## Additional files for the distribution archive
|
||||
EXTRA_DIST = \
|
||||
BUILDING \
|
||||
CONTRIBUTE \
|
||||
TODO \
|
||||
LICENSE \
|
||||
CMakeLists.txt \
|
||||
cmake_coap_config.h.in \
|
||||
cmake/Config.cmake.in \
|
||||
cmake/FindMbedTLS.cmake \
|
||||
cmake/FindTinyDTLS.cmake \
|
||||
coap_config.h.lwip \
|
||||
coap_config.h.riot \
|
||||
coap_config.h.windows \
|
||||
libcoap-$(LIBCOAP_API_VERSION).pc.in \
|
||||
libcoap-$(LIBCOAP_API_VERSION).map \
|
||||
libcoap-$(LIBCOAP_API_VERSION).sym \
|
||||
examples/coap_list.h \
|
||||
examples/getopt.c \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_riot.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_asn1_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_async_internal.h \
|
||||
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_io_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_net_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_pdu_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_resource_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_session_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_subscribe_internal.h \
|
||||
include/coap$(LIBCOAP_API_VERSION)/coap_tcp_internal.h \
|
||||
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 \
|
||||
tests/test_error_response.h \
|
||||
tests/test_encode.h \
|
||||
tests/test_options.h \
|
||||
@@ -48,9 +77,9 @@ EXTRA_DIST = \
|
||||
win32/testdriver/testdriver.vcxproj.filters \
|
||||
win32/testdriver/testdriver.vcxproj.user
|
||||
|
||||
AM_CFLAGS = -I$(top_builddir)/include/coap$(LIBCOAP_API_VERSION) -I$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION) $(WARNING_CFLAGS) $(DTLS_CFLAGS) -std=c99
|
||||
AM_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include $(WARNING_CFLAGS) $(DTLS_CFLAGS) -std=c99 $(EXTRA_CFLAGS)
|
||||
|
||||
SUBDIRS = $(subdirs) . $(MAN_DIR) $(DOC_DIR) tests examples
|
||||
SUBDIRS = $(subdirs) . man doc tests examples
|
||||
|
||||
## Define a libtool archive target "libcoap-@LIBCOAP_NAME_SUFFIX@.la", with
|
||||
## @LIBCOAP_NAME_SUFFIX@ substituted into the generated Makefile at configure
|
||||
@@ -72,14 +101,19 @@ libcoap_@LIBCOAP_NAME_SUFFIX@_la_SOURCES = \
|
||||
src/address.c \
|
||||
src/async.c \
|
||||
src/block.c \
|
||||
src/coap_asn1.c \
|
||||
src/coap_cache.c \
|
||||
src/coap_debug.c \
|
||||
src/coap_event.c \
|
||||
src/coap_hashkey.c \
|
||||
src/coap_gnutls.c \
|
||||
src/coap_io.c \
|
||||
src/coap_mbedtls.c \
|
||||
src/coap_notls.c \
|
||||
src/coap_openssl.c \
|
||||
src/coap_prng.c \
|
||||
src/coap_session.c \
|
||||
src/coap_tcp.c \
|
||||
src/coap_time.c \
|
||||
src/coap_tinydtls.c \
|
||||
src/encode.c \
|
||||
@@ -106,9 +140,9 @@ libcoap_includedir = $(includedir)/coap$(LIBCOAP_API_VERSION)/
|
||||
libcoap_include_HEADERS = \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/address.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/async.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/bits.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/block.h \
|
||||
$(top_builddir)/include/coap$(LIBCOAP_API_VERSION)/coap.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_cache.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_debug.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_dtls.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_event.h \
|
||||
@@ -124,12 +158,11 @@ libcoap_include_HEADERS = \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/net.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/option.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/pdu.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/prng.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_prng.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/resource.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/str.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/subscribe.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/uri.h \
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/uthash.h
|
||||
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/uri.h
|
||||
|
||||
## Instruct libtool to include API version information in the generated shared
|
||||
## library file (.so). The library ABI version will later defined in configure.ac,
|
||||
@@ -143,48 +176,7 @@ libcoap_@LIBCOAP_NAME_SUFFIX@_la_LDFLAGS = \
|
||||
## Collect symbols here we want to ignore while building the helper files
|
||||
## libcoap-$(LIBCOAP_API_VERSION).{map,sym} for the linker.
|
||||
CTAGS_IGNORE=-I " \
|
||||
coap_dtls_context_check_keys_enabled \
|
||||
coap_dtls_context_set_pki \
|
||||
coap_dtls_context_set_pki_root_cas \
|
||||
coap_dtls_context_set_psk \
|
||||
coap_dtls_free_context \
|
||||
coap_dtls_free_session \
|
||||
coap_dtls_get_context_timeout \
|
||||
coap_dtls_get_overhead \
|
||||
coap_dtls_get_timeout \
|
||||
coap_dtls_handle_timeout \
|
||||
coap_dtls_hello \
|
||||
coap_dtls_is_context_timeout \
|
||||
coap_dtls_new_client_session \
|
||||
coap_dtls_new_context \
|
||||
coap_dtls_new_server_session \
|
||||
coap_dtls_receive \
|
||||
coap_dtls_send \
|
||||
coap_dtls_session_update_mtu \
|
||||
coap_dtls_startup \
|
||||
coap_epoll_ctl_mod \
|
||||
coap_io_do_events \
|
||||
coap_mfree_endpoint \
|
||||
coap_packet_extract_pbuf \
|
||||
coap_pdu_from_pbuf \
|
||||
coap_session_mfree \
|
||||
coap_session_new_dtls_session \
|
||||
coap_socket_accept_tcp \
|
||||
coap_socket_bind_tcp \
|
||||
coap_socket_bind_udp \
|
||||
coap_socket_close \
|
||||
coap_socket_connect_tcp1 \
|
||||
coap_socket_connect_tcp2 \
|
||||
coap_socket_connect_udp \
|
||||
coap_socket_read \
|
||||
coap_socket_send \
|
||||
coap_socket_send_pdu \
|
||||
coap_socket_write \
|
||||
coap_tls_free_session \
|
||||
coap_tls_new_client_session \
|
||||
coap_tls_new_server_session \
|
||||
coap_tls_read \
|
||||
coap_tls_write \
|
||||
"
|
||||
|
||||
# This helper is called by libcoap-$(LIBCOAP_API_VERSION).{map,sym} to see if
|
||||
@@ -229,6 +221,33 @@ pkgconfig_DATA = libcoap-$(LIBCOAP_NAME_SUFFIX).pc
|
||||
## the noinst_ prefix.
|
||||
dist_noinst_SCRIPTS = autogen.sh
|
||||
|
||||
## Set up a common library that causes linking against the common library
|
||||
## to link with the actual library with (D)TLS support
|
||||
if BUILD_ADD_DEFAULT_NAMES
|
||||
install-exec-hook:
|
||||
(cd $(DESTDIR)$(libdir) ; \
|
||||
if [ -f libcoap-$(LIBCOAP_NAME_SUFFIX).so ] ; then \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).so ; \
|
||||
$(LN_S) libcoap-$(LIBCOAP_NAME_SUFFIX).so libcoap-$(LIBCOAP_API_VERSION).so ; \
|
||||
fi ; \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).a ; \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).la ; \
|
||||
$(LN_S) libcoap-$(LIBCOAP_NAME_SUFFIX).a libcoap-$(LIBCOAP_API_VERSION).a ; \
|
||||
$(LN_S) libcoap-$(LIBCOAP_NAME_SUFFIX).la libcoap-$(LIBCOAP_API_VERSION).la ; \
|
||||
$(MKDIR_P) $(DESTDIR)$(pkgconfigdir) ; \
|
||||
cd $(DESTDIR)$(pkgconfigdir) ; \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).pc ; \
|
||||
$(LN_S) libcoap-$(LIBCOAP_NAME_SUFFIX).pc libcoap-$(LIBCOAP_API_VERSION).pc)
|
||||
|
||||
uninstall-hook:
|
||||
(cd $(DESTDIR)$(libdir) ; \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).a ; \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).la ; \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).so ; \
|
||||
cd $(DESTDIR)$(pkgconfigdir) ; \
|
||||
rm -f libcoap-$(LIBCOAP_API_VERSION).pc)
|
||||
endif # BUILD_ADD_DEFAULT_NAMES
|
||||
|
||||
## various *-local targets
|
||||
## Remove the helper files for the linker and the pkg-config file if there
|
||||
## is 'make distclean' called. NOTE: To re create the *.{map,sym} files you
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
libcoap_src = pdu.c net.c coap_debug.c encode.c uri.c subscribe.c resource.c str.c option.c async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c address.c
|
||||
libcoap_src = pdu.c net.c coap_cache.c coap_debug.c encode.c uri.c subscribe.c resource.c str.c option.c async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c address.c coap_tcp.c
|
||||
|
||||
libcoap_dir := $(filter %libcoap,$(APPDS))
|
||||
vpath %c $(libcoap_dir)/src
|
||||
|
||||
# set include path for coap sources
|
||||
CFLAGS += -I$(libcoap_dir)/include/coap2
|
||||
CFLAGS += -I$(libcoap_dir)/include
|
||||
|
||||
@@ -61,6 +61,8 @@ Note:If the text contains special characters, please escape them according to th
|
||||
<filteritem type="filename" name="LICENSE" desc="We just use use BSD. getopt.c, OpenSSL, GnuTLS or tinyDTLS are not be used."/>
|
||||
<filteritem type="filename" name="Makefile.am" desc="We not use this automake script file."/>
|
||||
<filteritem type="filename" name="BUILDING" desc="无license头。该文件为构建说明文档。"/>
|
||||
<filteritem type="filename" name="include/coap3/uthash.h" desc="libcoap use this under BSD license"/>
|
||||
<filteritem type="filename" name="include/coap3/utlist.h" desc="libcoap use this under BSD license"/>
|
||||
<filteritem type="filepath" name="m4/ac_check_cryptolibs.m4" desc="We do not need this file to check the version of GNUTLS|OPENSSL. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty."/>
|
||||
<filteritem type="filepath" name="m4/ax_check_a2x_to_man.m4" desc="We do not need this file to check if have installed a2x or not. This file is part of the CoAP library libcoap, following BSD License."/>
|
||||
<filteritem type="filepath" name="m4/ax_check_compile_flag.m4" desc="You need not follow the terms of the GPL when using or distributing Autoconf scripts. Futher more, we not use this Autoconf script file."/>
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# libcoap: A C implementation of the Constrained Application Protocol (RFC 7252)
|
||||
|
||||
[](https://github.com/obgm/libcoap/actions?query=branch:main)
|
||||
[](https://github.com/obgm/libcoap/actions?query=branch:develop)
|
||||
[](https://scan.coverity.com/projects/obgm-libcoap)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:libcoap)
|
||||
|
||||
Copyright (C) 2010—2021 by Olaf Bergmann <bergmann@tzi.org> and others
|
||||
|
||||
ABOUT LIBCOAP
|
||||
=============
|
||||
|
||||
libcoap is a C implementation of a lightweight application-protocol
|
||||
for devices that are constrained their resources such as computing
|
||||
power, RF range, memory, bandwidth, or network packet sizes. This
|
||||
protocol, CoAP, is standardized by the IETF as RFC 7252. For further
|
||||
information related to CoAP, see <http://coap.technology>.
|
||||
|
||||
You might want to check out
|
||||
[libcoap-minimal](https://github.com/obgm/libcoap-minimal) for usage
|
||||
examples.
|
||||
|
||||
DOCUMENTATION
|
||||
=============
|
||||
|
||||
Documentation and further information can be found at
|
||||
<https://libcoap.net>.
|
||||
|
||||
PACKAGE CONTENTS
|
||||
================
|
||||
|
||||
This package contains a protocol parser and basic networking
|
||||
functions for platforms with support for malloc() and BSD-style
|
||||
sockets. In addition, there is support for Contiki, LwIP and
|
||||
Espressif/ESP-IDF hosted environments.
|
||||
|
||||
The following RFCs are supported
|
||||
|
||||
* RFC7252: The Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC7641: Observing Resources in the Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC7959: Block-Wise Transfers in the Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC7967: Constrained Application Protocol (CoAP) Option for No Server Response
|
||||
|
||||
* RFC8132: PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC8323: CoAP (Constrained Application Protocol) over TCP, TLS, and WebSockets
|
||||
[No WebSockets support]
|
||||
|
||||
* RFC8768: Constrained Application Protocol (CoAP) Hop-Limit Option
|
||||
|
||||
There is (D)TLS support for the following libraries
|
||||
|
||||
* OpenSSL (Minimum version 1.1.0) [PKI, PSK and PKCS11]
|
||||
|
||||
* GnuTLS (Minimum version 3.3.0) [PKI, PSK, RPK(3.6.6+) and PKCS11]
|
||||
|
||||
* Mbed TLS (Minimum version 2.7.10) [PKI and PSK] [Currently only DTLS]
|
||||
|
||||
* TinyDTLS [PSK and RPK] [DTLS Only]
|
||||
|
||||
The examples directory contain a CoAP client, CoAP Resource Directory server
|
||||
and a CoAP server to demonstrate the use of this library.
|
||||
|
||||
BUILDING
|
||||
========
|
||||
|
||||
Further information can be found at <https://libcoap.net/install.html>
|
||||
and [BUILDING](https://raw.githubusercontent.com/obgm/libcoap/develop/BUILDING).
|
||||
|
||||
LICENSE INFORMATION
|
||||
===================
|
||||
|
||||
This library is published as open-source software without any warranty
|
||||
of any kind. Use is permitted under the terms of the simplified BSD
|
||||
license. It includes public domain software. libcoap binaries may also
|
||||
include open-source software with their respective licensing terms.
|
||||
Please refer to
|
||||
[LICENSE](https://raw.githubusercontent.com/obgm/libcoap/develop/LICENSE)
|
||||
for further details.
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# libcoap: A C implementation of the Constrained Application Protocol (RFC 7252)
|
||||
|
||||
[](https://travis-ci.org/obgm/libcoap)
|
||||
[](https://github.com/obgm/libcoap/actions?query=branch:main)
|
||||
[](https://github.com/obgm/libcoap/actions?query=branch:develop)
|
||||
[](https://scan.coverity.com/projects/obgm-libcoap)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:libcoap)
|
||||
|
||||
Copyright (C) 2010—2019 by Olaf Bergmann <bergmann@tzi.org> and others
|
||||
Copyright (C) 2010—2021 by Olaf Bergmann <bergmann@tzi.org> and others
|
||||
|
||||
ABOUT LIBCOAP
|
||||
=============
|
||||
@@ -46,14 +47,19 @@ The following RFCs are supported
|
||||
* RFC8132: PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC8323: CoAP (Constrained Application Protocol) over TCP, TLS, and WebSockets
|
||||
[No WebSockets support]
|
||||
|
||||
* RFC8768: Constrained Application Protocol (CoAP) Hop-Limit Option
|
||||
|
||||
There is (D)TLS support for the following libraries
|
||||
|
||||
* OpenSSL (Minimum verion 1.1.0)
|
||||
* OpenSSL (Minimum version 1.1.0) [PKI, PSK and PKCS11]
|
||||
|
||||
* GnuTLS (Minimum version 3.3.0)
|
||||
* GnuTLS (Minimum version 3.3.0) [PKI, PSK, RPK(3.6.6+) and PKCS11]
|
||||
|
||||
* TinyDTLS
|
||||
* Mbed TLS (Minimum version 2.7.10) [PKI and PSK] [Currently only DTLS]
|
||||
|
||||
* TinyDTLS [PSK and RPK] [DTLS Only]
|
||||
|
||||
The examples directory contain a CoAP client, CoAP Resource Directory server
|
||||
and a CoAP server to demonstrate the use of this library.
|
||||
|
||||
@@ -11,8 +11,6 @@ Classification of issues:
|
||||
=================
|
||||
* CRITICAL ISSUES
|
||||
=================
|
||||
-> Proxy functionality
|
||||
-> A coap-server should be able to act as proxy server
|
||||
|
||||
================
|
||||
* SERIOUS ISSUES
|
||||
|
||||
Executable → Regular
+6
-4
@@ -27,14 +27,14 @@ depcomp
|
||||
doc/Doxyfile doc/doxyfile.stamp doc/doxygen_sqlite3.db doc/Makefile doc/Makefile.in
|
||||
examples/*.o examples/coap-client examples/coap-server examples/coap-rd
|
||||
examples/Makefile examples/Makefile.in
|
||||
include/coap2/coap.h
|
||||
include/coap3/coap.h
|
||||
install-sh
|
||||
libcoap-*.pc libtool ltmain.sh
|
||||
man/coap*.[357] man/coap*.txt man/Makefile man/Makefile.in
|
||||
missing
|
||||
Makefile Makefile.in
|
||||
stamp-h1 src/.dirstamp libcoap*.la* src/*.*o
|
||||
tests/*.o tests/Makefile tests/Makefile.in tests/testdriver
|
||||
tests/*.o tests/Makefile tests/Makefile.in tests/testdriver tests/test_common.h
|
||||
tests/oss-fuzz/Makefile.ci
|
||||
m4/libtool.m4 m4/lt~obsolete.m4 m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4
|
||||
"
|
||||
@@ -44,6 +44,8 @@ AUTOGEN_DIRS="
|
||||
.libs autom4te.cache/
|
||||
doc/html/
|
||||
examples/.deps/ examples/.libs
|
||||
man/.deps
|
||||
man/tmp
|
||||
src/.deps/ src/.libs/
|
||||
tests/.deps/
|
||||
"
|
||||
@@ -51,7 +53,7 @@ tests/.deps/
|
||||
# checking for cleaner argument
|
||||
echo
|
||||
if [ "$1" = "--clean" ]; then
|
||||
echo "removing autogerated files ..."
|
||||
echo "removing autogenerated files ..."
|
||||
rm -rf $AUTOGEN_FILES $AUTOGEN_DIRS
|
||||
echo "done"
|
||||
exit
|
||||
@@ -130,6 +132,6 @@ echo "Generating needed autotools files for $PROJECT by running autoreconf ..."
|
||||
autoreconf --force --install --verbose "$srcdir"
|
||||
|
||||
echo
|
||||
echo "You can now run 'configure --help' to see possible configuration options."
|
||||
echo "You can now run './configure --help' to see possible configuration options."
|
||||
echo "Otherwise process the configure script to create the makefiles and generated helper files."
|
||||
echo
|
||||
|
||||
@@ -2,6 +2,6 @@ FROM debian:testing-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y autoconf automake gcc clang \
|
||||
libtool libtool-bin make pkg-config libcunit1-dev libssl-dev \
|
||||
libgnutls28-dev exuberant-ctags git valgrind \
|
||||
libgnutls28-dev libmbedtls-dev exuberant-ctags git valgrind \
|
||||
graphviz doxygen libxml2-utils xsltproc docbook-xml docbook-xsl asciidoc
|
||||
RUN apt-get clean
|
||||
|
||||
@@ -17,11 +17,11 @@ RUN git clone --depth 1 https://github.com/cabo/cn-cbor.git && cd cn-cbor && ./b
|
||||
FROM debian:testing-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y autoconf automake gcc g++ gdb libtool libtool-bin make \
|
||||
pkg-config libssl-dev libgnutls28-dev
|
||||
pkg-config libssl-dev libgnutls28-dev libmbedtls-dev
|
||||
RUN apt-get install -y iproute2 lsof net-tools inetutils-ping netcat-openbsd less vim
|
||||
RUN apt-get clean
|
||||
|
||||
COPY --from=0 /usr/local/include/coap2 /usr/local/include/coap2
|
||||
COPY --from=0 /usr/local/include/coap3 /usr/local/include/coap3
|
||||
COPY --from=0 /usr/local/lib /usr/local/lib
|
||||
COPY --from=0 /usr/local/bin/coap-client /usr/local/bin/
|
||||
COPY --from=0 /usr/local/include/cn-cbor /usr/local/include/cn-cbor
|
||||
|
||||
Executable → Regular
-30
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"name": "@ohos/libcoap",
|
||||
"description": "libcoap is a C implementation of a lightweight application-protocol for devices that are constrained their resources such as computing power, RF range, memory, bandwidth, or network packet sizes. This protocol, CoAP, is standardized by the IETF as RFC 7252. For further information related to CoAP, see http://coap.technology.",
|
||||
"version": "3.1",
|
||||
"license": "BSD 3-Clause",
|
||||
"publishAs": "code-segment",
|
||||
"segment": {
|
||||
"destPath": "third_party/libcoap"
|
||||
},
|
||||
"dirs": {},
|
||||
"scripts": {},
|
||||
"component": {
|
||||
"name": "thirdparty_libcoap",
|
||||
"subsystem": "",
|
||||
"syscap": [],
|
||||
"features": [],
|
||||
"adapted_system_type": [],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [],
|
||||
"inner_kits": [],
|
||||
"test": []
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
# to format cmake files we use cmake-format:
|
||||
# pip install cmake-format --upgrade
|
||||
# information about the configuration here:
|
||||
# https://github.com/cheshirekow/cmake_format
|
||||
|
||||
# How wide to allow formatted cmake files
|
||||
line_width: 80
|
||||
|
||||
# How many spaces to tab for indent
|
||||
tab_size: 2
|
||||
|
||||
# Format command names consistently as 'lower' or 'upper' case
|
||||
command_case: "lower"
|
||||
|
||||
first_comment_is_literal: False
|
||||
|
||||
# enable comment markup parsing and reflow
|
||||
enable_markup: False
|
||||
|
||||
# If arglists are longer than this, break them always
|
||||
max_subargs_per_line: 1
|
||||
|
||||
max_subgroups_hwrap: 2
|
||||
|
||||
max_pargs_hwrap: 2
|
||||
@@ -0,0 +1,4 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
check_required_components("@PROJECT_NAME@")
|
||||
@@ -0,0 +1,35 @@
|
||||
find_path(MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)
|
||||
|
||||
find_library(MBEDTLS_LIBRARY mbedtls)
|
||||
find_library(MBEDX509_LIBRARY mbedx509)
|
||||
find_library(MBEDCRYPTO_LIBRARY mbedcrypto)
|
||||
|
||||
set(MBEDTLS_LIBRARIES
|
||||
"${MBEDTLS_LIBRARY}"
|
||||
"${MBEDX509_LIBRARY}"
|
||||
"${MBEDCRYPTO_LIBRARY}")
|
||||
|
||||
if(MBEDTLS_LIBRARY)
|
||||
set(MbedTLS_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
MBEDTLS
|
||||
DEFAULT_MSG
|
||||
MBEDTLS_INCLUDE_DIRS
|
||||
MBEDTLS_LIBRARY
|
||||
MBEDX509_LIBRARY
|
||||
MBEDCRYPTO_LIBRARY)
|
||||
|
||||
mark_as_advanced(
|
||||
MBEDTLS_INCLUDE_DIRS
|
||||
MBEDTLS_LIBRARY
|
||||
MBEDX509_LIBRARY
|
||||
MBEDCRYPTO_LIBRARY)
|
||||
|
||||
message(STATUS "MBEDTLS_INCLUDE_DIRS: ${MBEDTLS_INCLUDE_DIRS}")
|
||||
message(STATUS "MBEDTLS_LIBRARY: ${MBEDTLS_LIBRARY}")
|
||||
message(STATUS "MBEDX509_LIBRARY: ${MBEDX509_LIBRARY}")
|
||||
message(STATUS "MBEDCRYPTO_LIBRARY: ${MBEDCRYPTO_LIBRARY}")
|
||||
message(STATUS "MBEDTLS_LIBRARIES: ${MBEDTLS_LIBRARIES}")
|
||||
@@ -0,0 +1,88 @@
|
||||
# FindTinyDTLS
|
||||
# -----------
|
||||
#
|
||||
# Find the tinyDTLS encryption library.
|
||||
#
|
||||
# Imported Targets
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
#
|
||||
# This module defines the following :prop_tgt:`IMPORTED` targets:
|
||||
#
|
||||
# ``tinydtls``
|
||||
# The tinyDTLS ``tinydtls`` library, if found.
|
||||
#
|
||||
# Result Variables
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
#
|
||||
# This module will set the following variables in your project:
|
||||
#
|
||||
# ``TINYDTLS_FOUND``
|
||||
# System has the tinyDTLS library.
|
||||
# ``TINYDTLS_INCLUDE_DIR``
|
||||
# The tinyDTLS include directory.
|
||||
# ``TINYDTLS_LIBRARIES``
|
||||
# All tinyDTLS libraries.
|
||||
#
|
||||
# Hints
|
||||
# ^^^^^
|
||||
#
|
||||
# Set ``TINYDTLS_ROOT_DIR`` to the root directory of an tinyDTLS installation.
|
||||
|
||||
if(TINYDTLS_ROOT_DIR)
|
||||
set(_EXTRA_FIND_ARGS "NO_CMAKE_FIND_ROOT_PATH")
|
||||
endif()
|
||||
|
||||
find_path(
|
||||
TINYDTLS_INCLUDE_DIR
|
||||
NAMES tinydtls/dtls.h
|
||||
PATH_SUFFIXES include
|
||||
HINTS ${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${TINYDTLS_ROOT_DIR}
|
||||
${_EXTRA_FIND_ARGS})
|
||||
|
||||
find_library(
|
||||
TINYDTLS_LIBRARIES
|
||||
NAMES tinydtls
|
||||
PATH_SUFFIXES lib
|
||||
HINTS ${PROJECT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${TINYDTLS_ROOT_DIR}
|
||||
${_EXTRA_FIND_ARGS})
|
||||
|
||||
if(TINYDTLS_LIBRARIES)
|
||||
set(TINYDTLS_FOUND TRUE)
|
||||
else()
|
||||
set(TINYDTLS_FOUND FALSE)
|
||||
if(TinyDTLS_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Tinydtls could not be found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
tinyDTLS
|
||||
FOUND_VAR
|
||||
TINYDTLS_FOUND
|
||||
REQUIRED_VARS
|
||||
TINYDTLS_INCLUDE_DIR
|
||||
TINYDTLS_LIBRARIES
|
||||
VERSION_VAR)
|
||||
|
||||
if(NOT
|
||||
TARGET
|
||||
tinydtls)
|
||||
add_library(
|
||||
tinydtls
|
||||
UNKNOWN
|
||||
IMPORTED)
|
||||
set_target_properties(
|
||||
tinydtls
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${TINYDTLS_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${TINYDTLS_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
message(STATUS "TINYDTLS_INCLUDE_DIR: ${TINYDTLS_INCLUDE_DIR}")
|
||||
message(STATUS "TINYDTLS_LIBRARIES: ${TINYDTLS_LIBRARIES}")
|
||||
message(STATUS "TINYDTLS_ROOT_DIR: ${TINYDTLS_ROOT_DIR}")
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* cmake_coap_config.h -- cmake configuration for libcoap
|
||||
*
|
||||
* Copyright (C) 2020 Carlos Gomes Martinho <carlos.gomes_martinho@siemens.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_CONFIG_H_
|
||||
#define COAP_CONFIG_H_
|
||||
|
||||
/* Define to 1 if you have <ws2tcpip.h> header file. */
|
||||
#cmakedefine HAVE_WS2TCPIP_H "@HAVE_WS2TCPIP_H@"
|
||||
|
||||
/* Define if the system has small stack size */
|
||||
#cmakedefine COAP_CONSTRAINED_STACK "@COAP_CONSTRAINED_STACK@"
|
||||
|
||||
/* Define to 1 if you have <winsock2.h> header file. */
|
||||
#cmakedefine HAVE_WINSOCK2_H "@HAVE_WINSOCK2_H@"
|
||||
|
||||
/* Define if the system has epoll support */
|
||||
#cmakedefine COAP_EPOLL_SUPPORT "@COAP_EPOLL_SUPPORT@"
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#cmakedefine HAVE_ARPA_INET_H "@HAVE_ARPA_INET_H@"
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#cmakedefine HAVE_ASSERT_H "@HAVE_ASSERT_H@"
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#cmakedefine HAVE_DLFCN_H "@HAVE_DLFCN_H@"
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#cmakedefine HAVE_GETADDRINFO "@HAVE_GETADDRINFO@"
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#cmakedefine HAVE_INTTYPES_H "@HAVE_INTTYPES_H@"
|
||||
|
||||
/* Define if the system has openssl */
|
||||
#cmakedefine HAVE_OPENSSL "@HAVE_OPENSSL@"
|
||||
|
||||
/* Define if the system has libgnutls28 */
|
||||
#cmakedefine HAVE_LIBGNUTLS "@HAVE_LIBGNUTLS@"
|
||||
|
||||
/* Define if the system has libtinydtls */
|
||||
#cmakedefine HAVE_LIBTINYDTLS "@HAVE_LIBTINYDTLS@"
|
||||
|
||||
/* Define if the system has libmbedtls */
|
||||
#cmakedefine HAVE_MBEDTLS "@HAVE_MBEDTLS@"
|
||||
|
||||
/* Define to 1 to build without TCP support. */
|
||||
#cmakedefine01 COAP_DISABLE_TCP
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#cmakedefine HAVE_LIMITS_H "@HAVE_LIMITS_H@"
|
||||
|
||||
/* Define to 1 if you have the `malloc' function. */
|
||||
#cmakedefine HAVE_MALLOC "@HAVE_MALLOC@"
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#cmakedefine HAVE_MEMORY_H "@HAVE_MEMORY_H@"
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#cmakedefine HAVE_MEMSET "@HAVE_MEMSET@"
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#cmakedefine HAVE_NETDB_H "@HAVE_NETDB_H@"
|
||||
|
||||
/* Define to 1 if you have the <net/if.h> header file. */
|
||||
#cmakedefine HAVE_NET_IF_H "@HAVE_NET_IF_H@"
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#cmakedefine HAVE_NETINET_IN_H "@HAVE_NETINET_IN_H@"
|
||||
|
||||
/* Define to 1 if you have the <pthread.h> header file. */
|
||||
#cmakedefine HAVE_PTHREAD_H "@HAVE_PTHREAD_H@"
|
||||
|
||||
/* Define to 1 if you have the `pthread_mutex_lock' function. */
|
||||
#cmakedefine HAVE_PTHREAD_MUTEX_LOCK "@HAVE_PTHREAD_MUTEX_LOCK@"
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#cmakedefine HAVE_SELECT "@HAVE_SELECT@"
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#cmakedefine HAVE_SOCKET "@HAVE_SOCKET@"
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#cmakedefine HAVE_STDINT_H "@HAVE_STDINT_H@"
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#cmakedefine HAVE_STDLIB_H "@HAVE_STDLIB_H@"
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#cmakedefine HAVE_STRCASECMP "@HAVE_STRCASECMP@"
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#cmakedefine HAVE_STRINGS_H "@HAVE_STRINGS_H@"
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#cmakedefine HAVE_STRING_H "@HAVE_STRING_H@"
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
#cmakedefine HAVE_STRNLEN "@HAVE_STRNLEN@"
|
||||
|
||||
/* Define to 1 if you have the `strrchr' function. */
|
||||
#cmakedefine HAVE_STRRCHR "@HAVE_STRRCHR@"
|
||||
|
||||
/* Define to 1 if the system has the type `struct cmsghdr'. */
|
||||
#cmakedefine HAVE_STRUCT_CMSGHDR "@HAVE_STRUCT_CMSGHDR@"
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#cmakedefine HAVE_SYSLOG_H "@HAVE_SYSLOG_H@"
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#cmakedefine HAVE_SYS_IOCTL_H "@HAVE_SYS_IOCTL_H@"
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#cmakedefine HAVE_SYS_SOCKET_H "@HAVE_SYS_SOCKET_H@"
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#cmakedefine HAVE_SYS_STAT_H "@HAVE_SYS_STAT_H@"
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TIME_H "@HAVE_SYS_TIME_H@"
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TYPES_H "@HAVE_SYS_TYPES_H@"
|
||||
|
||||
/* Define to 1 if you have the <sys/unistd.h> header file. */
|
||||
#cmakedefine HAVE_SYS_UNISTD_H "@HAVE_SYS_UNISTD_H@"
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#cmakedefine HAVE_TIME_H "@HAVE_TIME_H@"
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#cmakedefine HAVE_UNISTD_H "@HAVE_UNISTD_H@"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#cmakedefine PACKAGE_URL "@PACKAGE_URL@"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(snprintf)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#endif /* COAP_CONFIG_H_ */
|
||||
@@ -11,6 +11,10 @@
|
||||
#define COAP_CONSTRAINED_STACK 1
|
||||
#endif
|
||||
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 1
|
||||
#endif
|
||||
|
||||
#define PACKAGE_STRING "libcoap"
|
||||
#define PACKAGE_NAME "libcoap"
|
||||
|
||||
@@ -59,6 +63,43 @@
|
||||
#define COAP_MAX_SUBSCRIBERS 3
|
||||
#endif /* COAP_MAX_SUBSCRIBERS */
|
||||
|
||||
/**
|
||||
* The maximum number of cache-key entries that allocate
|
||||
* fixed-size memory blocks.
|
||||
*/
|
||||
#ifndef COAP_MAX_CACHE_KEYS
|
||||
#define COAP_MAX_CACHE_KEYS (2U)
|
||||
#endif /* COAP_MAX_CACHE_KEYS */
|
||||
|
||||
/**
|
||||
* The maximum number of cache-entry entries that allocate
|
||||
* fixed-size memory blocks.
|
||||
*/
|
||||
#ifndef COAP_MAX_CACHE_ENTRIES
|
||||
#define COAP_MAX_CACHE_ENTRIES (2U)
|
||||
#endif /* COAP_MAX_CACHE_ENTRIES */
|
||||
|
||||
/**
|
||||
* Maximum number of large body transmissions.
|
||||
*/
|
||||
#ifndef COAP_MAX_LG_XMIT
|
||||
#define COAP_MAX_LG_XMIT 2
|
||||
#endif /* COAP_MAX_LG_XMIT */
|
||||
|
||||
/**
|
||||
* Maximum number of large body client receives.
|
||||
*/
|
||||
#ifndef COAP_MAX_LG_CRCV
|
||||
#define COAP_MAX_LG_CRCV 2
|
||||
#endif /* COAP_MAX_LG_CRCV */
|
||||
|
||||
/**
|
||||
* Maximum number of large body server receives.
|
||||
*/
|
||||
#ifndef COAP_MAX_LG_SRCV
|
||||
#define COAP_MAX_LG_SRCV 2
|
||||
#endif /* COAP_MAX_LG_SRCV */
|
||||
|
||||
/**
|
||||
* Number of notifications that may be sent non-confirmable before a
|
||||
* confirmable message is sent to detect if observers are alive. The
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/* coap_config.h. Generated from coap_config.h.in by configure. */
|
||||
/* coap_config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
/* #undef AC_APPLE_UNIVERSAL_BUILD */
|
||||
|
||||
/* Define if the system has small stack size */
|
||||
/* #undef COAP_CONSTRAINED_STACK */
|
||||
|
||||
/* Define to 1 to build without TCP support. */
|
||||
#define COAP_DISABLE_TCP 1
|
||||
|
||||
/* Define if the system has epoll support */
|
||||
/* #undef COAP_EPOLL_SUPPORT */
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#define HAVE_ARPA_INET_H 1
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#define HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the `getrandom' function. */
|
||||
/* #undef HAVE_GETRANDOM 1 */
|
||||
|
||||
/* Define to 1 if you have the `if_nametoindex' function. */
|
||||
#define HAVE_IF_NAMETOINDEX 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define if the system has libcunit */
|
||||
/* #undef HAVE_LIBCUNIT */
|
||||
|
||||
/* Define if the system has libgnutls28 */
|
||||
/* #undef HAVE_LIBGNUTLS */
|
||||
|
||||
/* Define if the system has libtinydtls */
|
||||
/* #undef HAVE_LIBTINYDTLS */
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define to 1 if you have the `malloc' function. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define if the system has libmbedtls2.7.10 */
|
||||
/* #undef HAVE_MBEDTLS */
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#define HAVE_NETDB_H 1
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#define HAVE_NETINET_IN_H 1
|
||||
|
||||
/* Define to 1 if you have the <net/if.h> header file. */
|
||||
#define HAVE_NET_IF_H 1
|
||||
|
||||
/* Define if the system has libssl1.1 */
|
||||
/* #undef HAVE_OPENSSL */
|
||||
|
||||
/* Define to 1 if you have the <pthread.h> header file. */
|
||||
#define HAVE_PTHREAD_H 1
|
||||
|
||||
/* Define to 1 if you have the `pthread_mutex_lock' function. */
|
||||
#define HAVE_PTHREAD_MUTEX_LOCK 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#define HAVE_SELECT 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#define HAVE_STRCASECMP 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
#define HAVE_STRNLEN 1
|
||||
|
||||
/* Define to 1 if you have the `strrchr' function. */
|
||||
#define HAVE_STRRCHR 1
|
||||
|
||||
/* Define to 1 if the system has the type `struct cmsghdr'. */
|
||||
// #define HAVE_STRUCT_CMSGHDR 1
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#define HAVE_SYSLOG_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#define HAVE_SYS_IOCTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/unistd.h> header file. */
|
||||
#define HAVE_SYS_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#define HAVE_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
||||
/* Define to 1 if assertions should be disabled. */
|
||||
#define NDEBUG 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libcoap"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libcoap 4.3.0"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libcoap"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL "https://libcoap.net/"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "4.3.0"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to build without support for separate responses. */
|
||||
/* #undef WITHOUT_ASYNC */
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
/* # undef WORDS_BIGENDIAN */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define this to 1 for ancillary data on MacOS */
|
||||
/* #undef __APPLE_USE_RFC_3542 */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
+18
-3
@@ -1,3 +1,14 @@
|
||||
/*
|
||||
* coap_config.h.lwip -- LwIP configuration for libcoap
|
||||
*
|
||||
* Copyright (C) 2021 Olaf Bergmann <bergmann@tzi.org> and others
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_CONFIG_H_
|
||||
#define COAP_CONFIG_H_
|
||||
|
||||
@@ -11,9 +22,13 @@
|
||||
#define COAP_CONSTRAINED_STACK 1
|
||||
#endif
|
||||
|
||||
#define PACKAGE_NAME "libcoap-lwip"
|
||||
#define PACKAGE_VERSION "?"
|
||||
#define PACKAGE_STRING PACKAGE_NAME PACKAGE_VERSION
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 1
|
||||
#endif
|
||||
|
||||
#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)
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* coap_config.h.lwip -- LwIP configuration for libcoap
|
||||
*
|
||||
* Copyright (C) 2021 Olaf Bergmann <bergmann@tzi.org> and others
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_CONFIG_H_
|
||||
#define COAP_CONFIG_H_
|
||||
|
||||
#include <lwip/opt.h>
|
||||
#include <lwip/debug.h>
|
||||
#include <lwip/def.h> /* provide ntohs, htons */
|
||||
|
||||
#define WITH_LWIP 1
|
||||
|
||||
#ifndef COAP_CONSTRAINED_STACK
|
||||
#define COAP_CONSTRAINED_STACK 1
|
||||
#endif
|
||||
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 1
|
||||
#endif
|
||||
|
||||
#define PACKAGE_NAME "@PACKAGE_NAME@"
|
||||
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
#define PACKAGE_STRING "@PACKAGE_STRING@"
|
||||
|
||||
#define assert(x) LWIP_ASSERT("CoAP assert failed", x)
|
||||
|
||||
/* 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
|
||||
|
||||
#endif /* COAP_CONFIG_H_ */
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* coap_config.h.riot -- RIOT configuration for libcoap
|
||||
*
|
||||
* Copyright (C) 2021 Olaf Bergmann <bergmann@tzi.org> and others
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_CONFIG_H_RIOT_
|
||||
#define COAP_CONFIG_H_RIOT_
|
||||
|
||||
#define WITH_POSIX 1
|
||||
|
||||
#ifndef COAP_CONSTRAINED_STACK
|
||||
#define COAP_CONSTRAINED_STACK 1
|
||||
#endif
|
||||
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 1
|
||||
#endif
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
/* #undef AC_APPLE_UNIVERSAL_BUILD */
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#define HAVE_ARPA_INET_H 1
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
/* #undef HAVE_GETADDRINFO */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
/* #undef HAVE_LIMITS_H */
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#undef HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
/* #undef HAVE_MEMORY_H */
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
/* #undef HAVE_NETDB_H */
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#define HAVE_NETINET_IN_H 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
/* #undef HAVE_SELECT */
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#define HAVE_STRCASECMP 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
/* #undef HAVE_STRNLEN */
|
||||
|
||||
/* Define to 1 if you have the `strrchr' function. */
|
||||
#define HAVE_STRRCHR 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
/* #undef HAVE_SYS_STAT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/unistd.h> header file. */
|
||||
#define HAVE_SYS_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#define HAVE_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libcoap"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "4.3.0"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libcoap 4.3.0"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
/* # undef WORDS_BIGENDIAN */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
#endif /* COAP_CONFIG_H_RIOT_ */
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* coap_config.h.riot -- RIOT configuration for libcoap
|
||||
*
|
||||
* Copyright (C) 2021 Olaf Bergmann <bergmann@tzi.org> and others
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_CONFIG_H_RIOT_
|
||||
#define COAP_CONFIG_H_RIOT_
|
||||
|
||||
#define WITH_POSIX 1
|
||||
|
||||
#ifndef COAP_CONSTRAINED_STACK
|
||||
#define COAP_CONSTRAINED_STACK 1
|
||||
#endif
|
||||
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 1
|
||||
#endif
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
/* #undef AC_APPLE_UNIVERSAL_BUILD */
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#define HAVE_ARPA_INET_H 1
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
/* #undef HAVE_GETADDRINFO */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
/* #undef HAVE_LIMITS_H */
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#undef HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
/* #undef HAVE_MEMORY_H */
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
/* #undef HAVE_NETDB_H */
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#define HAVE_NETINET_IN_H 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
/* #undef HAVE_SELECT */
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#define HAVE_STRCASECMP 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
/* #undef HAVE_STRNLEN */
|
||||
|
||||
/* Define to 1 if you have the `strrchr' function. */
|
||||
#define HAVE_STRRCHR 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
/* #undef HAVE_SYS_STAT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/unistd.h> header file. */
|
||||
#define HAVE_SYS_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#define HAVE_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "@PACKAGE_NAME@"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "@PACKAGE_STRING@"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
/* # undef WORDS_BIGENDIAN */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
#endif /* COAP_CONFIG_H_RIOT_ */
|
||||
@@ -67,7 +67,9 @@
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#define HAVE_OPENSSL 1
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 0
|
||||
#endif
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net"
|
||||
@@ -76,7 +78,7 @@
|
||||
#define PACKAGE_NAME "libcoap"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libcoap 4.2.0"
|
||||
#define PACKAGE_STRING "libcoap 4.3.0"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libcoap"
|
||||
@@ -85,7 +87,7 @@
|
||||
#define PACKAGE_URL "https://libcoap.net/"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "4.2.0"
|
||||
#define PACKAGE_VERSION "4.3.0"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
#ifndef COAP_CONFIG_H_
|
||||
#define COAP_CONFIG_H_
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
/* Define to 1 if you have <ws2tcpip.h> header file. */
|
||||
#define HAVE_WS2TCPIP_H 1
|
||||
|
||||
/* Define to 1 if you have <winsock2.h> header file. */
|
||||
#define HAVE_WINSOCK2_H 1
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#define HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define to 1 if you have the `malloc' function. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#define HAVE_SELECT 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
#define HAVE_STRNLEN 1
|
||||
|
||||
/* Define to 1 if you have the `strrchr' function. */
|
||||
#define HAVE_STRRCHR 1
|
||||
|
||||
/* Define to 1 if the system has the type `struct cmsghdr'. */
|
||||
#define HAVE_STRUCT_CMSGHDR 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#define HAVE_TIME_H 1
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(snprintf)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 0
|
||||
#endif
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "@PACKAGE_NAME@"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "@PACKAGE_STRING@"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "@PACKAGE_TARNAME@"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL "@PACKAGE_URL@"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
/* # undef WORDS_BIGENDIAN */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define this to 1 for ancillary data on MacOS */
|
||||
/* #undef __APPLE_USE_RFC_3542 */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* COAP_CONFIG_H_ */
|
||||
+306
-90
@@ -1,15 +1,21 @@
|
||||
# configure.ac for the libcoap package
|
||||
#
|
||||
# Copyright (C) 2010-2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
# (C) 2015-2018 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
# Copyright (C) 2010-2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
# Copyright (C) 2015-2018 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
# Copyright (C) 2018-2021 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# This file is part of the CoAP library libcoap. Please see README for terms
|
||||
# of use.
|
||||
#
|
||||
# Please run 'autogen.sh' to let autoconf produce a configure script.
|
||||
|
||||
# Define the libcoap software version here. Note! The libtool versions are
|
||||
# defined later.
|
||||
m4_define([libcoap_major_version], [4])
|
||||
m4_define([libcoap_minor_version], [2])
|
||||
m4_define([libcoap_micro_version], [1])
|
||||
m4_define([libcoap_minor_version], [3])
|
||||
m4_define([libcoap_micro_version], [0])
|
||||
|
||||
# define an appending release state if needed, for example for pre-releases
|
||||
# like 'alpha' or 'rc1', for a full release keep the value empty!
|
||||
@@ -26,8 +32,8 @@ AM_SILENT_RULES([yes])
|
||||
AC_HEADER_ASSERT
|
||||
|
||||
# Generate one configuration header file for building the library itself with
|
||||
# an auto generated template. We need later a second one (include/libcoap.h)
|
||||
# that will be installed alongside the library.
|
||||
# an auto generated template. We need later a second one
|
||||
# (include/coap$LIBCOAP_API_VERSION/libcoap.h) that will be installed alongside the library.
|
||||
AC_CONFIG_HEADERS([coap_config.h])
|
||||
|
||||
AC_PROG_CC
|
||||
@@ -36,6 +42,8 @@ AC_PROG_SED
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
m4_pattern_allow([AM_PROG_AR])
|
||||
AM_PROG_AR
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_MKDIR_P
|
||||
|
||||
AC_C_BIGENDIAN
|
||||
|
||||
@@ -105,8 +113,8 @@ LT_INIT([shared static])
|
||||
#
|
||||
# --> Set 'LT_LIBCOAP_AGE' to 0.
|
||||
|
||||
LT_LIBCOAP_CURRENT=2
|
||||
LT_LIBCOAP_REVISION=1
|
||||
LT_LIBCOAP_CURRENT=3
|
||||
LT_LIBCOAP_REVISION=0
|
||||
LT_LIBCOAP_AGE=0
|
||||
LIBCOAP_SO_VERSION=$LT_LIBCOAP_CURRENT.$LT_LIBCOAP_REVISION.$LT_LIBCOAP_AGE
|
||||
|
||||
@@ -117,9 +125,18 @@ AC_SUBST(LT_LIBCOAP_AGE)
|
||||
AC_SUBST(LIBCOAP_SO_VERSION)
|
||||
|
||||
# Defining the API Version
|
||||
LIBCOAP_API_VERSION=2
|
||||
LIBCOAP_API_VERSION=3
|
||||
AC_SUBST(LIBCOAP_API_VERSION)
|
||||
|
||||
# Define a numeric version string
|
||||
m4_define([version_number],
|
||||
[m4_format([%u%03u%03u],
|
||||
libcoap_major_version,
|
||||
libcoap_minor_version,
|
||||
libcoap_micro_version)])
|
||||
LIBCOAP_VERSION=version_number
|
||||
AC_SUBST(LIBCOAP_VERSION)
|
||||
|
||||
# Adding some default warning options for code QS
|
||||
# see https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
|
||||
# and http://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html
|
||||
@@ -203,8 +220,6 @@ if test "x$build_doxygen" = "xyes"; then
|
||||
AC_MSG_ERROR([==> Install required doxygen version or disable the doxygen documentation using '--disable-doxygen'.])
|
||||
else
|
||||
# we found doxygen and the version is valid
|
||||
DOC_DIR=doc
|
||||
AC_SUBST(DOC_DIR)
|
||||
# now checking dot (needed for graphics)
|
||||
AC_PATH_PROG([DOT], [dot])
|
||||
if test "x$DOT" = "x"; then
|
||||
@@ -286,8 +301,6 @@ if test "x$build_manpages" = "xyes"; then
|
||||
AC_MSG_ERROR([==> Install the packages that contains the docbook DTD and XSL stylesheets (presumably docbook, docbook-xml) or disable the build of the manpages using '--disable-manpages'.])
|
||||
build_manpages="no"
|
||||
])
|
||||
MAN_DIR=man
|
||||
AC_SUBST(MAN_DIR)
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(BUILD_MANPAGES, [test "x$build_manpages" = "xyes"])
|
||||
@@ -304,6 +317,7 @@ AM_CONDITIONAL(BUILD_MANPAGES, [test "x$build_manpages" = "xyes"])
|
||||
|
||||
gnutls_version_required=3.3.0
|
||||
openssl_version_required=1.1.0
|
||||
mbedtls_version_required=2.7.10
|
||||
|
||||
AC_ARG_ENABLE([dtls],
|
||||
[AS_HELP_STRING([--enable-dtls],
|
||||
@@ -323,25 +337,44 @@ AC_ARG_WITH([openssl],
|
||||
[with_openssl="$withval"],
|
||||
[with_openssl="no"])
|
||||
|
||||
AC_ARG_WITH([mbedtls],
|
||||
[AS_HELP_STRING([--with-mbedtls],
|
||||
[Use Mbed TLS for DTLS functions])],
|
||||
[with_mbedtls="$withval"],
|
||||
[with_mbedtls="no"])
|
||||
|
||||
AC_ARG_WITH([tinydtls],
|
||||
[AS_HELP_STRING([--with-tinydtls],
|
||||
[Use TinyDTLS for DTLS functions])],
|
||||
[with_tinydtls="$withval"],
|
||||
[with_tinydtls="no"])
|
||||
|
||||
if test "x$with_gnutls" = "xyes" -o "x$with_openssl" = "xyes"; then
|
||||
if test "x$with_gnutls" = "xyes" -o "x$with_openssl" = "xyes" -o "x$with_mbedtls" = "xyes" -o "x$with_tinydtls" = "xyes"; then
|
||||
if test "x$build_dtls" = "x"; then
|
||||
# Give an advice that '--with_gnutls' or '--with_openssl' was used but
|
||||
# Give an advice that '--with_gnutls', '--with_openssl', '--with-mbedtls' or '--with-tinydtls' was used but
|
||||
# DTLS support isn't configured.
|
||||
AC_MSG_NOTICE([==> Using the configure options '--with-gnutls' or '--with-openssl' without '--enable-dtls' is useles and will be ignored.])
|
||||
AC_MSG_NOTICE([==> Using the configure options '--with-gnutls', '--with-openssl', '--with-mbedtls' or '--with-tinydtls' without '--enable-dtls' is useles and will be ignored.])
|
||||
fi
|
||||
fi
|
||||
|
||||
# O.K. the user hasn't de-selected DTLS
|
||||
if test "x$build_dtls" = "xyes"; then
|
||||
# The user can't select multiple crypto libraries.
|
||||
if test "x$with_gnutls" = "xyes" -a "x$with_openssl" = "xyes"; then
|
||||
AC_MSG_ERROR([==> You can't use the options '--with-gnutls' and '--with-openssl' at the same time while '--enable-dtls' is selected!
|
||||
TLSCOUNT=0
|
||||
if test "x$with_gnutls" = "xyes"; then
|
||||
TLSCOUNT=`expr $TLSCOUNT + 1`
|
||||
fi
|
||||
if test "x$with_openssl" = "xyes"; then
|
||||
TLSCOUNT=`expr $TLSCOUNT + 1`
|
||||
fi
|
||||
if test "x$with_mbedtls" = "xyes"; then
|
||||
TLSCOUNT=`expr $TLSCOUNT + 1`
|
||||
fi
|
||||
if test "x$with_tinydtls" = "xyes"; then
|
||||
TLSCOUNT=`expr $TLSCOUNT + 1`
|
||||
fi
|
||||
if test "$TLSCOUNT" -gt 1; then
|
||||
AC_MSG_ERROR([==> You can't use more than 1 of the options '--with-gnutls', '--with-openssl', '--with-mbedtls' or '--with-tinydtls' at the same time while '--enable-dtls' is selected!
|
||||
==> Please note, the option '--enable-dtls' is turned on by default if not explicitly disabled!])
|
||||
fi
|
||||
|
||||
@@ -358,6 +391,36 @@ if test "x$build_dtls" = "xyes"; then
|
||||
[have_openssl="yes"],
|
||||
[have_openssl="no"])
|
||||
|
||||
# Mbed TLS [does not have mbedtls.pc pkg-config file]
|
||||
AC_CHECK_LIB(mbedtls, mbedtls_version_get_string,
|
||||
[have_mbedtls="yes"; MbedTLS_CFLAGS="" ; MbedTLS_LIBS="-lmbedtls -lmbedcrypto -lmbedx509"],
|
||||
[have_mbedtls="no"], -lmbedx509 -lmbedcrypto)
|
||||
if test "x$have_mbedtls" = "xyes"; then
|
||||
if test "x$cross_compiling" = "xyes" ; then
|
||||
# Have no option but to do this
|
||||
mbedtls_version=$mbedtls_version_required
|
||||
else
|
||||
# Get actual library version
|
||||
AC_LANG_PUSH(C)
|
||||
local_MbedTLS_save_LIBS=$LIBS
|
||||
LIBS="$MbedTLS_LIBS $LIBS"
|
||||
AC_LINK_IFELSE([dnl
|
||||
AC_LANG_SOURCE(
|
||||
[[#include <stdio.h>
|
||||
#include <mbedtls/version.h>
|
||||
int main () {
|
||||
char str[20];
|
||||
mbedtls_version_get_string(str);
|
||||
fprintf(stdout,"%s\n",str);
|
||||
return 0;
|
||||
}]])],
|
||||
[mbedtls_version=$(./conftest$EXEEXT)],
|
||||
[AC_MSG_ERROR(Failed to determine Mbed TLS version)])
|
||||
LIBS=$local_MbedTLS_save_LIBS
|
||||
AC_LANG_POP(C)
|
||||
fi
|
||||
fi
|
||||
|
||||
# TinyDTLS ?
|
||||
# TBD ?
|
||||
|
||||
@@ -367,14 +430,16 @@ if test "x$build_dtls" = "xyes"; then
|
||||
if test "x$have_gnutls" != "xyes"; then
|
||||
AC_MSG_ERROR([==> You want to build libcoap with DTLS support by the GnuTLS library but pkg-config file 'gnutls.pc' could not be found!
|
||||
Install the package(s) that contains the development files for GnuTLS,
|
||||
or use '--with-openssl' or disable the DTLS support using '--disable-dtls'.])
|
||||
or select a different TLS library or disable the DTLS support using '--disable-dtls'.])
|
||||
fi
|
||||
AC_MSG_NOTICE([The use of GnuTLS was explicit requested due configure option '--with-gnutls'!])
|
||||
AC_MSG_NOTICE([The use of GnuTLS was explicitly requested with configure option '--with-gnutls'!])
|
||||
|
||||
# check for valid GnuTLS version
|
||||
gnutls_version=`pkg-config --modversion gnutls`
|
||||
AX_CHECK_GNUTLS_VERSION
|
||||
have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
fi
|
||||
|
||||
# The user wants to use explicit OpenSSL if '--with-openssl was set'.
|
||||
@@ -383,52 +448,89 @@ if test "x$build_dtls" = "xyes"; then
|
||||
if test "x$have_openssl" != "xyes"; then
|
||||
AC_MSG_ERROR([==> You want to build libcoap with DTLS support by the OpenSSL library but pkg-config file 'openssl.pc' could not be found!
|
||||
Install the package(s) that contains the development files for OpenSSL,
|
||||
or use '--with-gnutls' or disable the DTLS support using '--disable-dtls'.])
|
||||
or select a different TLS library or disable the DTLS support using '--disable-dtls'.])
|
||||
fi
|
||||
AC_MSG_NOTICE([The use of OpenSSL was explicit requested due configure option '--with-openssl'!])
|
||||
AC_MSG_NOTICE([The use of OpenSSL was explicitly requested with configure option '--with-openssl'!])
|
||||
|
||||
# check for valid OpenSSL version
|
||||
openssl_version=`pkg-config --modversion openssl`
|
||||
AX_CHECK_OPENSSL_VERSION
|
||||
have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
fi
|
||||
|
||||
# The user wants to use explicit OpenSSL if '--with-tinydtls was set'.
|
||||
# The user wants to use explicit Mbed TLS if '--with-mbedtls was set'.
|
||||
if test "x$with_mbedtls" = "xyes"; then
|
||||
# Some more sanity checking.
|
||||
if test "x$have_mbedtls" != "xyes"; then
|
||||
AC_MSG_ERROR([==> You want to build libcoap with DTLS support by the Mbed TLS library but library 'mbedtls' could not be found!
|
||||
Install the package(s) that contains the development files for Mbed TLS,
|
||||
or select a different TLS library or disable the DTLS support using '--disable-dtls'.])
|
||||
fi
|
||||
AC_MSG_NOTICE([The use of Mbed TLS was explicitly requested with configure option '--with-mbedtls'!])
|
||||
|
||||
# check for valid Mbed TLS version (mbedtls.pc does not exist - hmm)
|
||||
# mbedtls_version determined previously
|
||||
AX_CHECK_MBEDTLS_VERSION
|
||||
have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
fi
|
||||
|
||||
# The user wants to use explicit TinyDTLS if '--with-tinydtls was set'.
|
||||
if test "x$with_tinydtls" = "xyes" ; then
|
||||
if test -d "$srcdir/ext/tinydtls"; then
|
||||
AC_CONFIG_SUBDIRS([ext/tinydtls])
|
||||
have_tinydtls="yes"
|
||||
else
|
||||
have_tinydtls="no"
|
||||
have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
fi
|
||||
have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
fi
|
||||
|
||||
# The user hasn't requested the use of a specific cryptography library
|
||||
# we try first GnuTLS for usability ...
|
||||
if test "x$have_gnutls" = "xyes" -a "x$with_gnutls" = "xno" -a "x$with_tinydtls" = "xno"; then
|
||||
gnutls_version=`pkg-config --modversion gnutls`
|
||||
AX_CHECK_GNUTLS_VERSION
|
||||
AC_MSG_NOTICE([Using auto selected library GnuTLS for DTLS support!])
|
||||
with_gnutls_auto="yes"
|
||||
have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
fi
|
||||
if test "$TLSCOUNT" -eq 0; then
|
||||
# The user hasn't requested the use of a specific cryptography library
|
||||
# we try first GnuTLS for usability ...
|
||||
if test "x$have_gnutls" = "xyes"; then
|
||||
gnutls_version=`pkg-config --modversion gnutls`
|
||||
AX_CHECK_GNUTLS_VERSION
|
||||
AC_MSG_NOTICE([Using auto selected library GnuTLS for DTLS support!])
|
||||
with_gnutls_auto="yes"
|
||||
have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
|
||||
# ... and if not found check OpenSSL is suitable.
|
||||
if test "x$have_openssl" = "xyes" -a "x$with_openssl" = "xno" -a "x$with_gnutls_auto" = "x" -a "x$with_tinydtls" = "xno"; then
|
||||
openssl_version=`pkg-config --modversion openssl`
|
||||
AX_CHECK_OPENSSL_VERSION
|
||||
AC_MSG_NOTICE([Using auto selected library OpenSSL for DTLS support!])
|
||||
with_openssl_auto="yes"
|
||||
have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
fi
|
||||
# ... and if not found check OpenSSL is suitable.
|
||||
elif test "x$have_openssl" = "xyes"; then
|
||||
openssl_version=`pkg-config --modversion openssl`
|
||||
AX_CHECK_OPENSSL_VERSION
|
||||
AC_MSG_NOTICE([Using auto selected library OpenSSL for DTLS support!])
|
||||
with_openssl_auto="yes"
|
||||
have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
|
||||
# Note that tinyDTLS is used only when explicitly requested.
|
||||
# ... and if not found check Mbed TLS is suitable.
|
||||
elif test "x$have_mbedtls" = "xyes"; then
|
||||
# Mbed TLS [does not have mbedtls.pc pkg-config file]
|
||||
# mbedtls_version determined previously
|
||||
AX_CHECK_MBEDTLS_VERSION
|
||||
AC_MSG_NOTICE([Using auto selected library Mbed TLS for DTLS support!])
|
||||
with_mbedtls_auto="yes"
|
||||
have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
|
||||
|
||||
# Giving out an error message if we haven't found at least one crypto library.
|
||||
if test "x$have_gnutls" = "xno" -a "x$have_openssl" = "xno" -a "x$have_tinydtls" = "xno"; then
|
||||
AC_MSG_ERROR([==> Option '--enable-dtls' is set but one of the needed cryptography library GnuTLS nor OpenSSL nor tinyDTLS could be found!
|
||||
Install at least one of the package(s) that contains the development files for GnuTLS (>= $gnutls_version_required) or OpenSSL(>= $openssl_version_required)
|
||||
or disable the DTLS support using '--disable-dtls'.])
|
||||
# Note that tinyDTLS is used only when explicitly requested.
|
||||
# Giving out an error message if we haven't found at least one crypto library.
|
||||
else
|
||||
AC_MSG_ERROR([==> Option '--enable-dtls' is set but none of the needed cryptography libraries GnuTLS, OpenSSL or Mbed TLS could be found!
|
||||
Install at least one of the package(s) that contains the development files for GnuTLS (>= $gnutls_version_required), OpenSSL(>= $openssl_version_required), or Mbed TLS(>= $mbedtls_version_required)
|
||||
or disable the DTLS support using '--disable-dtls'.])
|
||||
fi
|
||||
fi
|
||||
|
||||
# Saving the DTLS related Compiler flags.
|
||||
@@ -442,6 +544,11 @@ if test "x$build_dtls" = "xyes"; then
|
||||
DTLS_LIBS="$OpenSSL_LIBS"
|
||||
AC_DEFINE(HAVE_OPENSSL, [1], [Define if the system has libssl1.1])
|
||||
fi
|
||||
if test "x$with_mbedtls" = "xyes" -o "x$with_mbedtls_auto" = "xyes"; then
|
||||
DTLS_CFLAGS="$MbedTLS_CFLAGS"
|
||||
DTLS_LIBS="$MbedTLS_LIBS"
|
||||
AC_DEFINE(HAVE_MBEDTLS, [1], [Define if the system has libmbedtls2.7.10])
|
||||
fi
|
||||
if test "x$with_tinydtls" = "xyes"; then
|
||||
DTLS_CFLAGS="-I \$(top_srcdir)/ext/tinydtls"
|
||||
if test "x$enable_shared" = "xyes"; then
|
||||
@@ -462,17 +569,15 @@ if test "x$with_openssl" = "xyes" -o "x$with_openssl_auto" = "xyes"; then
|
||||
LIBCOAP_DTLS_LIB_EXTENSION_NAME=-openssl
|
||||
elif test "x$with_gnutls" = "xyes" -o "x$with_gnutls_auto" = "xyes"; then
|
||||
LIBCOAP_DTLS_LIB_EXTENSION_NAME=-gnutls
|
||||
elif test "x$with_mbedtls" = "xyes" -o "x$with_mbedtls_auto" = "xyes"; then
|
||||
LIBCOAP_DTLS_LIB_EXTENSION_NAME=-mbedtls
|
||||
elif test "x$with_tinydtls" = "xyes"; then
|
||||
LIBCOAP_DTLS_LIB_EXTENSION_NAME=-tinydtls
|
||||
else
|
||||
LIBCOAP_DTLS_LIB_EXTENSION_NAME=
|
||||
LIBCOAP_DTLS_LIB_EXTENSION_NAME=-notls
|
||||
fi
|
||||
|
||||
if test "x$LIBCOAP_DTLS_LIB_EXTENSION_NAME" != "x"; then
|
||||
LIBCOAP_NAME_SUFFIX="$LIBCOAP_API_VERSION$LIBCOAP_DTLS_LIB_EXTENSION_NAME"
|
||||
else
|
||||
LIBCOAP_NAME_SUFFIX="$LIBCOAP_API_VERSION"
|
||||
fi
|
||||
LIBCOAP_NAME_SUFFIX="$LIBCOAP_API_VERSION$LIBCOAP_DTLS_LIB_EXTENSION_NAME"
|
||||
|
||||
AC_SUBST(LIBCOAP_NAME_SUFFIX)
|
||||
AC_SUBST(LIBCOAP_DTLS_LIB_EXTENSION_NAME)
|
||||
@@ -482,7 +587,7 @@ AC_SUBST([DOLLAR_SIGN],[$])
|
||||
# __tests__
|
||||
AC_ARG_ENABLE([tests],
|
||||
[AS_HELP_STRING([--enable-tests],
|
||||
[Enable building the binary testsuite [default=no]])],
|
||||
[Enable building the binary testsuite. Requires --enable-static [default=no]])],
|
||||
[build_tests="$enableval"],
|
||||
[build_tests="no"])
|
||||
|
||||
@@ -495,6 +600,10 @@ if test "x$build_tests" = "xyes"; then
|
||||
AC_MSG_WARN([==> You want to build the testing binary but the pkg-config file cunit.pc could not be found or installed CUnit version is too old!])
|
||||
AC_MSG_ERROR([==> Install the package(s) that contains the development files for CUnit or disable the testing binary using '--disable-tests'.])
|
||||
])
|
||||
if test "x$enable_static" = "xno"; then
|
||||
enable_static=yes
|
||||
AC_MSG_WARN([--enable-tests requires --enable-static which is now enabled.])
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_CUNIT, [test "x$CUNIT_LIBS" != "x"])
|
||||
|
||||
@@ -508,6 +617,16 @@ AC_ARG_ENABLE([examples],
|
||||
|
||||
AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$build_examples" = "xyes"])
|
||||
|
||||
# configure options
|
||||
# __examples-source
|
||||
AC_ARG_ENABLE([examples-source],
|
||||
[AS_HELP_STRING([--enable-examples-source],
|
||||
[Enable installing example source to DATAROOTDIR/libcoap/examples [default=yes]])],
|
||||
[build_examples_source="$enableval"],
|
||||
[build_examples_source="yes"])
|
||||
|
||||
AM_CONDITIONAL(BUILD_EXAMPLES_SOURCE, [test "x$build_examples_source" = "xyes"])
|
||||
|
||||
# configure options
|
||||
# __gcov__
|
||||
AC_ARG_ENABLE([gcov],
|
||||
@@ -529,6 +648,49 @@ if test "x$build_gcov" = "xyes"; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# configure options
|
||||
# __license-install__
|
||||
AC_ARG_ENABLE([license-install],
|
||||
[AS_HELP_STRING([--enable-license-install],
|
||||
[Enable installing LICENSE to DOCDIR [default=yes]])],
|
||||
[build_license_install="$enableval"],
|
||||
[build_license_install="yes"])
|
||||
|
||||
AM_CONDITIONAL(BUILD_LICENSE_INSTALL, [test "x$build_license_install" = "xyes"])
|
||||
|
||||
# configure options
|
||||
# __tcp__
|
||||
AC_ARG_ENABLE([tcp],
|
||||
[AS_HELP_STRING([--enable-tcp],
|
||||
[Enable building with TCP support [default=yes]])],
|
||||
[build_tcp="$enableval"],
|
||||
[build_tcp="yes"])
|
||||
|
||||
AC_DEFINE(COAP_DISABLE_TCP, [0], [Define to 1 to build without TCP support.])
|
||||
AS_IF([test "x$build_tcp" != "xyes"], [AC_DEFINE(COAP_DISABLE_TCP, [1])])
|
||||
AC_SUBST(COAP_DISABLE_TCP)
|
||||
|
||||
# configure options
|
||||
# __async__
|
||||
AC_ARG_ENABLE([async],
|
||||
[AS_HELP_STRING([--enable-async],
|
||||
[Enable building with support for separate responses [default=yes]])],
|
||||
[build_async="$enableval"],
|
||||
[build_async="yes"])
|
||||
|
||||
AS_IF([test "x$build_async" != "xyes"],
|
||||
[AC_DEFINE(WITHOUT_ASYNC, [1], [Define to build without support for separate responses.])])
|
||||
|
||||
# configure options
|
||||
# __add_default_names__
|
||||
AC_ARG_ENABLE([add-default-names],
|
||||
[AS_HELP_STRING([--enable-add-default-names],
|
||||
[Enable adding libraries / examples with default names [default=yes]])],
|
||||
[build_add_default_names="$enableval"],
|
||||
[build_add_default_names="yes"])
|
||||
|
||||
AM_CONDITIONAL(BUILD_ADD_DEFAULT_NAMES, [test "x$build_add_default_names" = "xyes"])
|
||||
|
||||
# end configure options
|
||||
#######################
|
||||
|
||||
@@ -570,7 +732,7 @@ fi
|
||||
AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h \
|
||||
pthread.h \
|
||||
stdlib.h string.h strings.h sys/socket.h sys/time.h \
|
||||
time.h unistd.h sys/unistd.h syslog.h sys/ioctl.h])
|
||||
time.h unistd.h sys/unistd.h syslog.h sys/ioctl.h net/if.h])
|
||||
|
||||
# For epoll, need two headers (sys/epoll.h sys/timerfd.h), but set up one #define
|
||||
AC_CHECK_HEADER([sys/epoll.h])
|
||||
@@ -610,7 +772,7 @@ AC_TYPE_SSIZE_T
|
||||
|
||||
# Checks for library functions.
|
||||
AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo \
|
||||
strnlen malloc pthread_mutex_lock])
|
||||
strnlen malloc pthread_mutex_lock getrandom if_nametoindex])
|
||||
|
||||
# Check if -lsocket -lnsl is required (specifically Solaris)
|
||||
AC_SEARCH_LIBS([socket], [socket])
|
||||
@@ -639,6 +801,12 @@ case $host in
|
||||
#AC_SUBST(OS_LINUX)
|
||||
;;
|
||||
|
||||
*-cygwin*)
|
||||
AC_MSG_RESULT([Cygwin])
|
||||
ADDITIONAL_CFLAGS="-D_GNU_SOURCE -D_CYGWIN_ENV"
|
||||
LDFLAGS="-no-undefined $LDFLAGS"
|
||||
;;
|
||||
|
||||
*-solaris*)
|
||||
AC_MSG_RESULT([Solaris])
|
||||
# set _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED to enable XPG4v2 (POSIX 2004)
|
||||
@@ -689,27 +857,39 @@ CFLAGS="$CFLAGS $ADDITIONAL_CFLAGS"
|
||||
#
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
coap_config.h.lwip
|
||||
coap_config.h.riot
|
||||
coap_config.h.windows
|
||||
doc/Makefile
|
||||
examples/Makefile
|
||||
include/coap2/coap.h
|
||||
include/coap$LIBCOAP_API_VERSION/coap.h
|
||||
include/coap$LIBCOAP_API_VERSION/coap.h.windows
|
||||
man/coap.txt
|
||||
man/coap_async.txt
|
||||
man/coap_attribute.txt
|
||||
man/coap_block.txt
|
||||
man/coap_cache.txt
|
||||
man/coap_context.txt
|
||||
man/coap_encryption.txt
|
||||
man/coap_endpoint_client.txt
|
||||
man/coap_endpoint_server.txt
|
||||
man/coap_handler.txt
|
||||
man/coap_io.txt
|
||||
man/coap_keepalive.txt
|
||||
man/coap_logging.txt
|
||||
man/coap_observe.txt
|
||||
man/coap_pdu_access.txt
|
||||
man/coap_pdu_setup.txt
|
||||
man/coap_recovery.txt
|
||||
man/coap_resource.txt
|
||||
man/coap_session.txt
|
||||
man/coap_string.txt
|
||||
man/coap_tls_library.txt
|
||||
man/coap-client.txt
|
||||
man/coap-server.txt
|
||||
man/coap-rd.txt
|
||||
man/Makefile
|
||||
tests/test_common.h
|
||||
tests/Makefile
|
||||
tests/oss-fuzz/Makefile.ci
|
||||
libcoap-$LIBCOAP_NAME_SUFFIX.pc:libcoap-$LIBCOAP_API_VERSION.pc.in
|
||||
@@ -719,66 +899,102 @@ AC_OUTPUT
|
||||
|
||||
AC_MSG_RESULT([
|
||||
libcoap configuration summary:
|
||||
libcoap package version : "$PACKAGE_VERSION"
|
||||
libcoap library version : "$LIBCOAP_SO_VERSION"
|
||||
libcoap API version : "$LIBCOAP_API_VERSION"
|
||||
libcoap DTLS lib extn : "$LIBCOAP_DTLS_LIB_EXTENSION_NAME"
|
||||
host system : "$host"]);
|
||||
libcoap package version : "$PACKAGE_VERSION"
|
||||
libcoap library version : "$LIBCOAP_SO_VERSION"
|
||||
libcoap API version : "$LIBCOAP_API_VERSION"
|
||||
libcoap DTLS lib extn : "$LIBCOAP_DTLS_LIB_EXTENSION_NAME"
|
||||
host system : "$host"]);
|
||||
if test "x$build_tcp" != "xno"; then
|
||||
AC_MSG_RESULT([ build with TCP support : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ build with TCP support : "no"])
|
||||
fi
|
||||
if test "x$with_gnutls" = "xyes" -o "x$with_gnutls_auto" = "xyes"; then
|
||||
AC_MSG_RESULT([ build DTLS support : "yes"])
|
||||
AC_MSG_RESULT([ --> GnuTLS around : "yes" (found GnuTLS $gnutls_version)])
|
||||
AC_MSG_RESULT([ GNUTLS_CFLAGS : "$GnuTLS_CFLAGS"])
|
||||
AC_MSG_RESULT([ GNUTLS_LIBS : "$GnuTLS_LIBS"])
|
||||
AC_MSG_RESULT([ build DTLS support : "yes"])
|
||||
AC_MSG_RESULT([ --> GnuTLS around : "yes" (found GnuTLS $gnutls_version)])
|
||||
AC_MSG_RESULT([ GNUTLS_CFLAGS : "$GnuTLS_CFLAGS"])
|
||||
AC_MSG_RESULT([ GNUTLS_LIBS : "$GnuTLS_LIBS"])
|
||||
fi
|
||||
if test "x$with_openssl" = "xyes" -o "x$with_openssl_auto" = "xyes"; then
|
||||
AC_MSG_RESULT([ build DTLS support : "yes"])
|
||||
AC_MSG_RESULT([ --> OpenSSL around : "yes" (found OpenSSL $openssl_version)])
|
||||
AC_MSG_RESULT([ OPENSSL_CFLAGS : "$OpenSSL_CFLAGS"])
|
||||
AC_MSG_RESULT([ OPENSSL_LIBS : "$OpenSSL_LIBS"])
|
||||
AC_MSG_RESULT([ build DTLS support : "yes"])
|
||||
AC_MSG_RESULT([ --> OpenSSL around : "yes" (found OpenSSL $openssl_version)])
|
||||
AC_MSG_RESULT([ OPENSSL_CFLAGS : "$OpenSSL_CFLAGS"])
|
||||
AC_MSG_RESULT([ OPENSSL_LIBS : "$OpenSSL_LIBS"])
|
||||
fi
|
||||
if test "x$with_mbedtls" = "xyes" -o "x$with_mbedtls_auto" = "xyes"; then
|
||||
AC_MSG_RESULT([ build DTLS support : "yes"])
|
||||
AC_MSG_RESULT([ --> Mbed TLS around : "yes" (found Mbed TLS $mbedtls_version)])
|
||||
AC_MSG_RESULT([ MBEDTLS_CFLAGS : "$MbedTLS_CFLAGS"])
|
||||
AC_MSG_RESULT([ MBEDTLS_LIBS : "$MbedTLS_LIBS"])
|
||||
fi
|
||||
if test "x$with_tinydtls" = "xyes"; then
|
||||
AC_MSG_RESULT([ build DTLS support : "yes"])
|
||||
AC_MSG_RESULT([ --> tinyDTLS around : "yes"])
|
||||
AC_MSG_RESULT([ TINYDTLS_CFLAGS : "$DTLS_CFLAGS"])
|
||||
AC_MSG_RESULT([ TINYDTLS_LIBS : "$DTLS_LIBS"])
|
||||
AC_MSG_RESULT([ build DTLS support : "yes"])
|
||||
AC_MSG_RESULT([ --> tinyDTLS around : "yes"])
|
||||
AC_MSG_RESULT([ TINYDTLS_CFLAGS : "$DTLS_CFLAGS"])
|
||||
AC_MSG_RESULT([ TINYDTLS_LIBS : "$DTLS_LIBS"])
|
||||
fi
|
||||
if test "x$build_dtls" != "xyes"; then
|
||||
AC_MSG_RESULT([ build DTLS support : "no"])
|
||||
AC_MSG_RESULT([ build DTLS support : "no"])
|
||||
fi
|
||||
if test "x$build_add_default_names" = "xyes"; then
|
||||
AC_MSG_RESULT([ add default names : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ add default names : "no"])
|
||||
fi
|
||||
if test "x$have_epoll" = "xyes"; then
|
||||
AC_MSG_RESULT([ build using epoll : "$with_epoll"])
|
||||
AC_MSG_RESULT([ build using epoll : "$with_epoll"])
|
||||
fi
|
||||
AC_MSG_RESULT([ enable small stack size : "$enable_small_stack"])
|
||||
if test "x$build_async" != "xno"; then
|
||||
AC_MSG_RESULT([ enable separate responses: "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ enable separate responses: "no"])
|
||||
fi
|
||||
AC_MSG_RESULT([ enable small stack size : "$enable_small_stack"])
|
||||
if test "x$build_doxygen" = "xyes"; then
|
||||
AC_MSG_RESULT([ build doxygen pages : "yes"])
|
||||
AC_MSG_RESULT([ --> Doxygen around : "yes" ($DOXYGEN $doxygen_version)])
|
||||
AC_MSG_RESULT([ build doxygen pages : "yes"])
|
||||
AC_MSG_RESULT([ --> Doxygen around : "yes" ($DOXYGEN $doxygen_version)])
|
||||
if test "x$DOT" = "x"; then
|
||||
AC_MSG_RESULT([ --> dot around : "no" (DOT not found!)])
|
||||
AC_MSG_RESULT([ --> dot around : "no" (DOT not found!)])
|
||||
else
|
||||
AC_MSG_RESULT([ --> dot around : "yes" ($DOT $dot_version)])
|
||||
AC_MSG_RESULT([ --> dot around : "yes" ($DOT $dot_version)])
|
||||
fi
|
||||
else
|
||||
if test "x$build_doxygen" = "xno"; then
|
||||
AC_MSG_RESULT([ build doxygen pages : "no"])
|
||||
AC_MSG_RESULT([ build doxygen pages : "no"])
|
||||
fi
|
||||
fi
|
||||
if test "x$build_manpages" = "xyes"; then
|
||||
AC_MSG_RESULT([ build man pages : "yes"])
|
||||
AC_MSG_RESULT([ build man pages : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ build man pages : "no"])
|
||||
AC_MSG_RESULT([ build man pages : "no"])
|
||||
fi
|
||||
if test "x$build_tests" = "xyes"; then
|
||||
AC_MSG_RESULT([ build unit test binary : "yes"])
|
||||
AC_MSG_RESULT([ build unit test binary : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ build unit test binary : "no"])
|
||||
AC_MSG_RESULT([ build unit test binary : "no"])
|
||||
fi
|
||||
if test "x$build_examples" = "xyes"; then
|
||||
AC_MSG_RESULT([ build examples : "yes"])
|
||||
AC_MSG_RESULT([ build examples : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ build examples : "no"])
|
||||
AC_MSG_RESULT([ build examples : "no"])
|
||||
fi
|
||||
if test "x$build_examples_source" = "xyes"; then
|
||||
AC_MSG_RESULT([ install examples source : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ install examples source : "no"])
|
||||
fi
|
||||
if test "x$build_gcov" = "xyes"; then
|
||||
AC_MSG_RESULT([ build with gcov support : "yes"])
|
||||
AC_MSG_RESULT([ build with gcov support : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ build with gcov support : "no"])
|
||||
AC_MSG_RESULT([ build with gcov support : "no"])
|
||||
fi
|
||||
if test "x$enable_shared" = "xyes"; then
|
||||
AC_MSG_RESULT([ build shared library : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ build shared library : "no"])
|
||||
fi
|
||||
if test "x$enable_static" = "xyes"; then
|
||||
AC_MSG_RESULT([ build static library : "yes"])
|
||||
else
|
||||
AC_MSG_RESULT([ build static library : "no"])
|
||||
fi
|
||||
|
||||
+480
-225
File diff suppressed because it is too large
Load Diff
+92
-28
@@ -3,37 +3,47 @@
|
||||
# Copyright (C) 2015-2018 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
# 2018 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
# We can only perfom the targets in this directory if doxygen is present.
|
||||
|
||||
if HAVE_DOXYGEN
|
||||
|
||||
CLEANFILES = \
|
||||
doxygen_sqlite3.db
|
||||
|
||||
EXTRA_DIST = \
|
||||
docbook.local.css \
|
||||
upgrade_4.2.1_4.3.0.txt \
|
||||
main.md
|
||||
|
||||
if HAVE_DOXYGEN
|
||||
|
||||
man-page-cleanup:
|
||||
rm -f $(top_builddir)/doc/DoxygenLayout.xml
|
||||
rm -rf $(top_builddir)/doc/man_tmp
|
||||
rm -rf $(top_builddir)/doc/man_html
|
||||
@rm -f $(top_builddir)/doc/DoxygenLayout.xml
|
||||
@rm -rf $(top_builddir)/doc/man_tmp
|
||||
@rm -rf $(top_builddir)/doc/man_html
|
||||
|
||||
man-page-prepare: man-page-cleanup
|
||||
$(MKDIR_P) $(top_builddir)/doc/man_tmp
|
||||
$(MKDIR_P) $(top_builddir)/doc/man_html
|
||||
@$(MKDIR_P) $(top_builddir)/doc/man_tmp
|
||||
@$(MKDIR_P) $(top_builddir)/doc/man_html
|
||||
|
||||
man-page-start: man-page-prepare
|
||||
@echo ' <tab type="usergroup" visible="yes" url="@ref manpage" title="Manual Pages" intro="">' > $(top_builddir)/doc/insert_file
|
||||
## Setup the man page tab
|
||||
@echo ' <tab type="usergroup" visible="yes" url="@ref manpage" title="Manual Pages">' > $(top_builddir)/doc/insert_file
|
||||
@echo '/** @page manpage Manual Pages' > $(top_builddir)/doc/man_tmp/manpage.dox
|
||||
@echo ' Here is a list of libcoap API manual pages, some of which have code examples:' >> $(top_builddir)/doc/man_tmp/manpage.dox
|
||||
@echo ' <table class="directory">' >> $(top_builddir)/doc/man_tmp/manpage.dox
|
||||
## Setup the upgrading tab
|
||||
@echo '/** @page upgrading Upgrading' > $(top_builddir)/doc/man_tmp/upgrading.dox
|
||||
@echo ' Upgrading between libcoap versions:' >> $(top_builddir)/doc/man_tmp/upgrading.dox
|
||||
@echo ' <table class="directory">' >> $(top_builddir)/doc/man_tmp/upgrading.dox
|
||||
|
||||
man-page-build: man-page-start
|
||||
man-page-build: upg-page-build man-page-start
|
||||
@MAN_FILES=`find $(top_srcdir)/man/ -type f -name "coap.txt.in" ; find $(top_srcdir)/man/ -type f -name "coap_*.in" | ALL=C sort ; find $(top_srcdir)/man/ -type f -name "coap-*.in" | LC_ALL=C sort` ;\
|
||||
UPG_FILES=`find $(top_srcdir)/doc/ -type f -name "upgrade_*.txt" | ALL=C sort` ;\
|
||||
HTML_FILES=`find $(top_builddir)/man/ -type f -name "*.html"` ;\
|
||||
COUNT_MAN_FILES=`echo $${MAN_FILES} | wc -w` ;\
|
||||
COUNT_HTML_FILES=`echo $${HTML_FILES} | wc -w` ;\
|
||||
@@ -63,9 +73,43 @@ man-page-build: man-page-start
|
||||
## Close off the man page file
|
||||
echo ' </table>' >> $(top_builddir)/doc/man_tmp/manpage.dox ;\
|
||||
echo ' */' >> $(top_builddir)/doc/man_tmp/manpage.dox ;\
|
||||
## Close off the insert_file
|
||||
echo ' </tab>' >> $(top_builddir)/doc/insert_file ;\
|
||||
## Add in the deprecated tab
|
||||
echo ' <tab type="user" visible="yes" url="@ref deprecated" title="Deprecated Items" intro=""/>' >> $(top_builddir)/doc/insert_file ;\
|
||||
## Start the upgrade tab
|
||||
echo ' <tab type="usergroup" visible="yes" url="@ref upgrading" title="Upgrading">' >> $(top_builddir)/doc/insert_file ;\
|
||||
for FILE in $${UPG_FILES} ; do \
|
||||
BASE=`basename $${FILE} | $(SED) "s/\.txt$$//g"`; \
|
||||
UPGRADE=`echo $${BASE} | $(SED) "s/^upgrade_//g"`; \
|
||||
CUPGRADE=`echo $${UPGRADE} | $(SED) "s/\./-/g"`; \
|
||||
SUMMARY=`head -1 $${FILE} | sed 's/^= //g'` ;\
|
||||
## Build the upgrade insert page
|
||||
echo "/// @page upg_$${CUPGRADE} $${UPGRADE}" > $(top_builddir)/doc/man_tmp/$${UPGRADE}.dox ;\
|
||||
echo "/// @htmlinclude $${BASE}.html $${UPGRADE}" >> $(top_builddir)/doc/man_tmp/$${UPGRADE}.dox ;\
|
||||
## Update insert_file
|
||||
echo " <tab type=\"user\" visible=\"yes\" url=\"@ref upg_$${CUPGRADE}\" title=\"$${SUMMARY}\" intro=\"\"/>" >> $(top_builddir)/doc/insert_file ;\
|
||||
## Update the upgrading page
|
||||
echo " <tr id=\"row_$${ID}_\"$${ROW_EVEN}>" >> $(top_builddir)/doc/man_tmp/upgrading.dox ;\
|
||||
echo " <td class=\"entry\" align=\"left\"> @ref upg_$${CUPGRADE} </td><td class=\"desc\" align=\"left\">$${SUMMARY}</td>" >> $(top_builddir)/doc/man_tmp/upgrading.dox ;\
|
||||
echo " </tr>" >> $(top_builddir)/doc/man_tmp/upgrading.dox ;\
|
||||
if [ -z $${ROW_EVEN} ] ; then \
|
||||
ROW_EVEN=" class=\"even\"" ;\
|
||||
else \
|
||||
ROW_EVEN= ;\
|
||||
fi ;\
|
||||
if [ -f $(top_builddir)/doc/$${BASE}.html ]; then \
|
||||
cp -f $(top_builddir)/doc/$${BASE}.html $(top_builddir)/doc/man_html/$${BASE}.html ;\
|
||||
## Correct case sensitive Name and Synopsis
|
||||
$(SED) -i 's^<div class="toc"><p><strong>^<div class="section"><p><strong>^' $(top_builddir)/doc/man_html/$${BASE}.html ;\
|
||||
else \
|
||||
echo "ERROR: $(top_builddir)/doc/$${BASE}.html not found!";\
|
||||
exit 1 ;\
|
||||
fi \
|
||||
done ;\
|
||||
## Close off the upgrading tab
|
||||
echo ' </table>' >> $(top_builddir)/doc/man_tmp/upgrading.dox ;\
|
||||
echo ' */' >> $(top_builddir)/doc/man_tmp/upgrading.dox ;\
|
||||
echo ' </tab>' >> $(top_builddir)/doc/insert_file ;\
|
||||
## Create and Update the DoxygenLayout.xml file
|
||||
$(DOXYGEN) -l ;\
|
||||
$(SED) -i 's/<tab type="pages" visible="yes" /<tab type="pages" visible="no" /g' $(top_builddir)/doc/DoxygenLayout.xml ;\
|
||||
@@ -92,26 +136,17 @@ man-page-build: man-page-start
|
||||
echo "finalized addition $${BASE}.html" ;\
|
||||
done
|
||||
|
||||
# This target has no check for automated install data! It's simply assumed that
|
||||
# that the 'all' target is running before, in short: the user has to run first
|
||||
# 'make' before running 'make install'!
|
||||
install-data-am:
|
||||
@if [ ! -d $(top_builddir)/doc/html ]; then \
|
||||
echo ;\
|
||||
echo " No install data in '$(top_builddir)/doc/html'found! Please run 'make all' first." ;\
|
||||
echo ;\
|
||||
exit 1 ;\
|
||||
fi
|
||||
$(MKDIR_P) $(DESTDIR)$(htmldir)/html || exit 1
|
||||
cp -a -f $(top_builddir)/doc/html $(DESTDIR)$(htmldir)
|
||||
find $(DESTDIR)$(htmldir) -type f -name "*.md5" -exec rm {} \;
|
||||
|
||||
uninstall-am:
|
||||
-rm -rf $(DESTDIR)$(htmldir)/html
|
||||
|
||||
if BUILD_MANPAGES
|
||||
UPG_LIST = upgrade_4.2.1_4.3.0.txt
|
||||
|
||||
upg-page-build:
|
||||
@for FILE in $(UPG_LIST) ; do \
|
||||
$(A2X) -d article --format xhtml -D $(top_builddir)/doc/ $(top_srcdir)/doc/$${FILE} ;\
|
||||
done
|
||||
|
||||
all: man-page-build
|
||||
$(DOXYGEN) Doxyfile
|
||||
@cp -f $(top_srcdir)/doc/docbook.local.css $(top_builddir)/doc/html/docbook-xsl.css
|
||||
|
||||
else
|
||||
#
|
||||
@@ -121,10 +156,39 @@ all: man-page-prepare
|
||||
endif # BUILD_MANPAGES
|
||||
|
||||
clean-local:
|
||||
-rm -rf $(top_builddir)/doc/html $(top_builddir)/doc/man_tmp $(top_builddir)/doc/man_html $(top_builddir)/doc/DoxygenLayout.xml
|
||||
-rm -rf $(top_builddir)/doc/html $(top_builddir)/doc/man_tmp $(top_builddir)/doc/man_html $(top_builddir)/doc/DoxygenLayout.xml $(top_builddir)/doc/docbook-xsl.css $(top_builddir)/doc/*.html
|
||||
|
||||
distclean-local: clean-local
|
||||
|
||||
endif # HAVE_DOXYGEN
|
||||
|
||||
install-data-hook:
|
||||
if HAVE_DOXYGEN
|
||||
@if [ ! -d $(top_builddir)/doc/html ]; then \
|
||||
echo ;\
|
||||
echo " No install data in '$(top_builddir)/doc/html'found! Please run 'make all' first." ;\
|
||||
echo ;\
|
||||
exit 1 ;\
|
||||
fi
|
||||
$(MKDIR_P) $(DESTDIR)$(htmldir)/html || exit 1
|
||||
cp -a -f $(top_builddir)/doc/html $(DESTDIR)$(htmldir)
|
||||
find $(DESTDIR)$(htmldir) -type f -name "*.md5" -delete
|
||||
endif # HAVE_DOXYGEN
|
||||
if BUILD_LICENSE_INSTALL
|
||||
$(MKDIR_P) $(DESTDIR)$(docdir) || exit 1
|
||||
$(INSTALL_DATA) $(top_srcdir)/LICENSE $(DESTDIR)$(docdir)
|
||||
$(INSTALL_DATA) $(top_srcdir)/COPYING $(DESTDIR)$(docdir)
|
||||
$(INSTALL_DATA) $(top_srcdir)/README $(DESTDIR)$(docdir)
|
||||
endif # BUILD_LICENSE_INSTALL
|
||||
|
||||
uninstall-hook:
|
||||
if BUILD_LICENSE_INSTALL
|
||||
@if [ -d $(DESTDIR)$(docdir) ] ; then \
|
||||
(cd $(DESTDIR)$(docdir) ; rm -f LICENSE README COPYING) ; \
|
||||
fi
|
||||
endif # BUILD_LICENSE_INSTALL
|
||||
if HAVE_DOXYGEN
|
||||
-rm -rf $(DESTDIR)$(htmldir)/html
|
||||
endif # HAVE_DOXYGEN
|
||||
|
||||
.PHONY: man-page-cleanup man-page-prepare man-page-start man-page-build
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
body pre {
|
||||
margin: 0.5em 10% 0.5em 1em;
|
||||
line-height: 1.0;
|
||||
color: navy;
|
||||
}
|
||||
dl {
|
||||
margin: .2em 0;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
dt {
|
||||
margin-top: 0.1em;
|
||||
}
|
||||
|
||||
+28
-1
@@ -4,7 +4,7 @@ libcoap {#mainpage}
|
||||
A C implementation of the Constrained Application Protocol (RFC 7252)
|
||||
=====================================================================
|
||||
|
||||
Copyright (C) 2010--2019 by Olaf Bergmann <bergmann@tzi.org> and others
|
||||
Copyright (C) 2010--2021 by Olaf Bergmann <bergmann@tzi.org> and others
|
||||
|
||||
About libcoap
|
||||
=============
|
||||
@@ -19,6 +19,33 @@ You might want to check out
|
||||
[libcoap-minimal](https://github.com/obgm/libcoap-minimal) for usage
|
||||
examples.
|
||||
|
||||
The following RFCs are supported
|
||||
|
||||
* RFC7252: The Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC7641: Observing Resources in the Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC7959: Block-Wise Transfers in the Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC7967: Constrained Application Protocol (CoAP) Option for No Server Response
|
||||
|
||||
* RFC8132: PATCH and FETCH Methods for the Constrained Application Protocol (CoAP)
|
||||
|
||||
* RFC8323: CoAP (Constrained Application Protocol) over TCP, TLS, and WebSockets
|
||||
[No WebSockets support]
|
||||
|
||||
* RFC8768: Constrained Application Protocol (CoAP) Hop-Limit Option
|
||||
|
||||
There is (D)TLS support for the following libraries
|
||||
|
||||
* OpenSSL (Minimum version 1.1.0) [PKI, PSK and PKCS11]
|
||||
|
||||
* GnuTLS (Minimum version 3.3.0) [PKI, PSK, RPK(3.6.6+) and PKCS11]
|
||||
|
||||
* Mbed TLS (Minimum version 2.7.10) [PKI and PSK] [Currently only DTLS]
|
||||
|
||||
* TinyDTLS [PSK and RPK] [DTLS Only]
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
|
||||
@@ -0,0 +1,431 @@
|
||||
= Upgrade from 4.2.1 to 4.3.0
|
||||
|
||||
== Summary
|
||||
|
||||
When compiling 4.2.1 based code with a 4.3.0 environment, this will initially
|
||||
throw up many errors as the API has been updated to make future coding simpler,
|
||||
adds more functionality and adds more rigorous coding checks. Updating your
|
||||
code with the following steps will significantly reduce the reported issues.
|
||||
|
||||
The examples are now also named with the (D)TLS library type as a suffix.
|
||||
E.g. coap-client is now coap-client-openssl.
|
||||
|
||||
== Include directory changes
|
||||
|
||||
Because of the API changes, the libcoap's include file directory has changed from `coap2/` to `coap3/`. Also, there is now no need to define additional include paths to the compiler options such as `-I include/coap3`.
|
||||
|
||||
=== Update coap2 to coap3
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
#include <coap2/coap.h>
|
||||
4.3.0
|
||||
#include <coap3/coap.h>
|
||||
----
|
||||
No other libcoap include files need to be included in your application.
|
||||
|
||||
== Call-back handler updates
|
||||
|
||||
Infrequently used parameters (which can easily be recreated) have been removed
|
||||
and others have been made const. These call-back handlers are those
|
||||
registered with the `coap_register_*()` functions as follows:
|
||||
|
||||
=== coap_register_handler()
|
||||
|
||||
The definition of `coap_method_handler_t` has been updated, so all the
|
||||
functions registered by `coap_register_handler()` need to be updated. Any
|
||||
application functions called by these functions may need to include `const` in
|
||||
their calling parameters.
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
static void
|
||||
hnd_get_time(coap_context_t *context,
|
||||
coap_resource_t *resource,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
coap_binary_t *token,
|
||||
coap_string_t *query,
|
||||
coap_pdu_t *response) {
|
||||
4.3.0
|
||||
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) {
|
||||
----
|
||||
If `context` or `token` need to be recreated, this is done by
|
||||
----
|
||||
coap_context_t *context = coap_session_get_context(session);
|
||||
coap_bin_const_t rcvd_token = coap_pdu_get_token(request);
|
||||
----
|
||||
|
||||
=== coap_register_response_handler()
|
||||
|
||||
The definition of `coap_response_handler_t` has been updated, so all the
|
||||
functions registered by `coap_register_response_handler()` need to be updated.
|
||||
Any application functions called by these functions may need to include `const`
|
||||
in their calling parameters. There is a new handler function exit code
|
||||
`COAP_RESPONSE_FAIL` (if the response is not liked and needs to be rejected
|
||||
with a `RST` packet) or `COAP_RESPONSE_OK`. Note that `coap_tid_t` has been
|
||||
replaced with `coap_mid_t` to reflect the parameter is the message id.
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
static void
|
||||
message_handler(struct coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *sent,
|
||||
coap_pdu_t *received,
|
||||
const coap_tid_t id) {
|
||||
4.3.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 mid) {
|
||||
----
|
||||
If `context` needs to be recreated, this is done by
|
||||
----
|
||||
coap_context_t *context = coap_session_get_context(session);
|
||||
----
|
||||
|
||||
=== coap_register_nack_handler()
|
||||
|
||||
The definition of `coap_nack_handler_t` has been updated, so all the functions
|
||||
registered by `coap_register_nack_handler()` need to be updated. Any
|
||||
application functions called by these functions may need to include `const` in
|
||||
their calling parameters. Note that `coap_tid_t` has been replaced with
|
||||
`coap_mid_t` to reflect the parameter is the message id.
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
static void
|
||||
nack_handler(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *sent,
|
||||
coap_nack_reason_t reason,
|
||||
const coap_tid_t id) {
|
||||
4.3.0
|
||||
static void
|
||||
nack_handler(coap_session_t *session,
|
||||
const coap_pdu_t *sent,
|
||||
const coap_nack_reason_t reason,
|
||||
const coap_mid_t mid) {
|
||||
----
|
||||
If `context` needs to be recreated, this is done by
|
||||
----
|
||||
coap_context_t *context = coap_session_get_context(session);
|
||||
----
|
||||
|
||||
=== coap_register_event_handler()
|
||||
|
||||
The definition of `coap_event_handler_t` been updated, so all the functions
|
||||
registered by `coap_register_event_handler()` need to be updated. Any
|
||||
application functions called by these functions may need to include `const` in
|
||||
their calling parameters.
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
static int
|
||||
event_handler(coap_context_t *context,
|
||||
coap_event_t event,
|
||||
struct coap_session_t *session) {
|
||||
4.3.0
|
||||
static int
|
||||
event_handler(coap_session_t *session,
|
||||
const coap_event_t event) {
|
||||
----
|
||||
Note the reversed order of the parameters. If `context` needs to be
|
||||
recreated, this is done by
|
||||
----
|
||||
coap_context_t *context = coap_session_get_context(session);
|
||||
----
|
||||
|
||||
=== coap_register_ping_handler()
|
||||
|
||||
The definition of `coap_ping_handler_t` been updated, so all the functions
|
||||
registered by `coap_register_ping_handler()` need to be updated. Any
|
||||
application functions called by these functions may need to include `const` in
|
||||
their calling parameters. Note that `coap_tid_t` has been replaced with
|
||||
`coap_mid_t` to reflect the parameter is the message id.
|
||||
|
||||
Example
|
||||
|
||||
----
|
||||
4.2.1
|
||||
void
|
||||
ping_handler(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *received,
|
||||
const coap_tid_t id);
|
||||
4.3.0
|
||||
void
|
||||
ping_handler(coap_session_t *session,
|
||||
const coap_pdu_t *received,
|
||||
const coap_mid_t mid);
|
||||
----
|
||||
If `context` needs to be recreated, this is done by
|
||||
----
|
||||
coap_context_t *context = coap_session_get_context(session);
|
||||
----
|
||||
|
||||
=== coap_register_pong_handler()
|
||||
|
||||
The definition of `coap_pong_handler_t` been updated, so all the functions
|
||||
registered by `coap_register_pong_handler()` need to be updated. Any
|
||||
application functions called by these functions may need to include `const` in
|
||||
their calling parameters. Note that `coap_tid_t` has been replaced with
|
||||
`coap_mid_t` to reflect the parameter is the message id.
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
void
|
||||
pong_handler(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *received,
|
||||
const coap_tid_t id);
|
||||
4.3.0
|
||||
void
|
||||
pong_handler(coap_session_t *session,
|
||||
const coap_pdu_t *received,
|
||||
const coap_mid_t mid);
|
||||
----
|
||||
If `context` needs to be recreated, this is done by
|
||||
----
|
||||
coap_context_t *context = coap_session_get_context(session);
|
||||
----
|
||||
|
||||
== libcoap structures no longer directly accessible
|
||||
|
||||
Many of the structures internally used by libcoap are no longer exposed to
|
||||
applications. Additional functions of the form `coap_X_get_Y()` and
|
||||
`coap_X_set_Y()` where `X` is the structure type and `Y` is the variable. Below
|
||||
is a non exhaustive set of examples,
|
||||
|
||||
=== coap_pdu_t code variable
|
||||
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
if (received->code ==
|
||||
4.3.0
|
||||
coap_pdu_code_t rcvd_code = coap_pdu_get_code(received);
|
||||
...
|
||||
if (rcvd_code ==
|
||||
----
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
response->code = COAP_RESPONSE_CODE(404);
|
||||
4.3.0
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_FOUND);
|
||||
----
|
||||
Note that more descriptive names are now supported for the response codes, but
|
||||
the old form can still be used.
|
||||
|
||||
=== coap_pdu_t type variable
|
||||
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
if (received->type ==
|
||||
4.3.0
|
||||
coap_pdu_code_t rcvd_type = coap_pdu_get_type(received);
|
||||
...
|
||||
if (rcvd_type ==
|
||||
----
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
request->type = COAP_MESSAGE_NON;
|
||||
4.3.0
|
||||
coap_pdu_set_type(request, COAP_MESSAGE_NON);
|
||||
----
|
||||
|
||||
=== coap_pdu_t token variable
|
||||
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
static inline int
|
||||
check_token(coap_pdu_t *received) {
|
||||
return received->token_length == the_token.length &&
|
||||
memcmp(received->token, the_token.s, the_token.length) == 0;
|
||||
}
|
||||
4.3.0
|
||||
static inline int
|
||||
check_token(const coap_pdu_t *received) {
|
||||
coap_bin_const_t rcvd_token = coap_pdu_get_token(received);
|
||||
|
||||
return rcvd_token.length == the_token.length &&
|
||||
memcmp(rcvd_token.s, the_token.s, the_token.length) == 0;
|
||||
}
|
||||
----
|
||||
|
||||
=== coap_session_t context variable
|
||||
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
if (session->context ==
|
||||
4.3.0
|
||||
coap_context_t context = coap_session_get_context(session);
|
||||
...
|
||||
if (context ==
|
||||
----
|
||||
|
||||
=== coap_session_t proto variable
|
||||
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
if (session->proto ==
|
||||
4.3.0
|
||||
coap_proto_t proto = coap_session_get_proto(session);
|
||||
...
|
||||
if (proto ==
|
||||
----
|
||||
|
||||
|
||||
== Functions with changed parameters
|
||||
|
||||
Some functions have had the parameters updated. Below are some of the more common ones.
|
||||
|
||||
=== coap_pdu_init()
|
||||
|
||||
The definition of the second parameter has changed from `coap_request_t` to
|
||||
`coap_pdu_code_t`.
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
pdu = coap_pdu_init(msgtype,
|
||||
COAP_REQUEST_GET,
|
||||
coap_new_message_id(session),
|
||||
coap_session_max_pdu_size(session));
|
||||
4.3.0
|
||||
pdu = coap_pdu_init(msgtype,
|
||||
COAP_REQUEST_CODE_GET,
|
||||
coap_new_message_id(session),
|
||||
coap_session_max_pdu_size(session));
|
||||
----
|
||||
Note that the second parameter (`COAP_REQUEST_CODE_GET`) goes further than
|
||||
just request codes and includes the possibility of response codes (e.g.
|
||||
`COAP_RESPONSE_CODE_CREATED`) from the `enum coap_pdu_code_t`. Hence the
|
||||
addition of `_CODE` in the parameter value.
|
||||
|
||||
=== coap_get_data()
|
||||
|
||||
The definition of the third parameter has been changed to be `const`
|
||||
|
||||
Example
|
||||
----
|
||||
4.2.1
|
||||
uint8_t *data;
|
||||
...
|
||||
ret = coap_get_data(pdu, &length, &data);
|
||||
4.3.0
|
||||
const uint8_t *data;
|
||||
...
|
||||
ret = coap_get_data(pdu, &length, &data);
|
||||
----
|
||||
|
||||
== Large Data Handling
|
||||
|
||||
Splitting up large data transmission into blocks (RFC7959) can now all be
|
||||
handled by internally by libcoap, removing the need for applications to know
|
||||
anything about how to work with blocks, or need to do any block packet loss
|
||||
recovery. In simple terms, `coap_context_set_block_mode()` must be called,
|
||||
`coap_add_data()` (or `coap_add_data_blocked_response()`) is replaced by
|
||||
`coap_add_data_large_response()` or `coap_add_data_large_request()`, and
|
||||
`coap_get_data_large()` used instead of `coap_get_data()`. See man page
|
||||
`coap_block(3)` for further information.
|
||||
|
||||
There are 3 ways of handling the block transfers
|
||||
|
||||
=== Application does all the work
|
||||
|
||||
This is how things were done in 4.2.1. The application recognizes the next
|
||||
block request coming in and then generates the next block response (including
|
||||
setting up the PDU if client). To continue using this method,
|
||||
`coap_context_set_block_mode()` must not be called and none of the `_large`
|
||||
functions used.
|
||||
|
||||
=== Application sees individual blocks
|
||||
|
||||
By calling `coap_context_set_block_mode(context, COAP_BLOCK_USE_LIBCOAP)` and
|
||||
using the `_large` functions, all the existing code that builds the next block
|
||||
response is no longer needed (and must be removed to prevent packet
|
||||
request/response duplication) as libcoap does this for the application.
|
||||
|
||||
By calling `coap_get_data_large()`, the application can determine if this is
|
||||
the first block or not (using `offset` value), whether the first block is all
|
||||
the data (`offset` = `0`, `length` = `total`) and whether this is the last
|
||||
block (`offset` + `length` = `total`). It is the responsibility of the
|
||||
application to re-assemble the individual blocks into a single body of data.
|
||||
|
||||
If this is the request handler in a server, the server still needs to return a
|
||||
`2.31 (Continue)` response code if the received data is not for the final block,
|
||||
otherwise a `2.01 (Created)` or `2.04 (Changed)` should be returned.
|
||||
|
||||
=== Application only sees all the data
|
||||
|
||||
By calling `coap_context_set_block_mode(context,
|
||||
COAP_BLOCK_USE_LIBCOAP|COAP_BLOCK_SINGLE_BODY)` and using the `_large`
|
||||
functions, all the existing code that builds the next block response is no
|
||||
longer needed (and must be removed to prevent request/response packet
|
||||
duplication) as libcoap does this for the application.
|
||||
|
||||
`coap_get_data_large()` will only return the entire body of data (`offset`
|
||||
always `0`, `length` = `total`) and there is no need to re-assemble individual
|
||||
blocks into a large body of data.
|
||||
|
||||
In RAM constrained environments, option 2 may be the preferred method.
|
||||
|
||||
== Observe Handling
|
||||
|
||||
In the server's request handler's call-back, there is no longer any need to
|
||||
check whether this is an Observe call (or Observe triggered requesting
|
||||
additional response call) and add in the Observe Option into the response pdu.
|
||||
This is now added by libcoap, and trying to add in the Observe Option for the
|
||||
second time in the call-back handler will throw up a Informational warning.
|
||||
|
||||
For the client, there is a new function `coap_cancel_observe()` that can be
|
||||
called to cancel an observation on the server. To use it,
|
||||
`coap_context_set_block_mode()` has to be called prior to sending the initial
|
||||
request containing the Observe option.
|
||||
|
||||
== Unused function parameters
|
||||
|
||||
`UNUSED_PARAM` has been replaced with `COAP_UNUSED`. If `COAP_UNUSED` is used,
|
||||
then the definition for `UNUSED_PARAM` can be removed.
|
||||
|
||||
== CoAP Message IDs
|
||||
|
||||
`coap_tid_t` has been replaced with `coap_mid_t`, as well as `COAP_TID_INVALID`
|
||||
has been replaced with `COAP_MID_INVALID`. This is so that the Message ID aligns
|
||||
with the definition in RFC7252.
|
||||
|
||||
== Async Support
|
||||
|
||||
The `async` support has been re-written to simplify usage, and allows the
|
||||
underlying libcoap to do the main management / work. A primary change is to
|
||||
register the async request with a defined delay time before triggering - which
|
||||
if set to 0 is an infinite time and the delay time subsequently updated if
|
||||
required. Consequently the `coap_async_*()` functions now have different
|
||||
parameters.
|
||||
+80
-8
@@ -1,35 +1,107 @@
|
||||
# examples/Makefile.am
|
||||
#
|
||||
# Copyright (C) 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
# Copyright (C) 2018-2021 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
EXTRA_DIST = share.libcoap.examples.Makefile share.libcoap.examples.README
|
||||
|
||||
# just do nothing if 'BUILD_EXAMPLES' isn't defined
|
||||
if BUILD_EXAMPLES
|
||||
|
||||
# picking up the default warning CFLAGS into AM_CFLAGS
|
||||
AM_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION) \
|
||||
$(WARNING_CFLAGS) $(DTLS_CFLAGS) -std=c99
|
||||
|
||||
#
|
||||
bin_PROGRAMS = coap-client coap-server coap-rd
|
||||
|
||||
bin_PROGRAMS = coap-client@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ \
|
||||
coap-server@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ \
|
||||
coap-rd@LIBCOAP_DTLS_LIB_EXTENSION_NAME@
|
||||
|
||||
check_PROGRAMS = coap-etsi_iot_01 coap-tiny
|
||||
|
||||
coap_client_SOURCES = client.c
|
||||
coap_client_LDADD = $(DTLS_LIBS) $(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
if BUILD_ADD_DEFAULT_NAMES
|
||||
noinst_PROGRAMS = coap-client coap-server coap-rd
|
||||
|
||||
coap_client_SOURCES = coap-client.c
|
||||
coap_client_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
|
||||
coap_server_SOURCES = coap-server.c
|
||||
coap_server_LDADD = $(DTLS_LIBS) $(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
coap_server_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
|
||||
coap_rd_SOURCES = coap-rd.c
|
||||
coap_rd_LDADD = $(DTLS_LIBS) $(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
coap_rd_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
endif # BUILD_ADD_DEFAULT_NAMES
|
||||
|
||||
coap_client@LIBCOAP_DTLS_LIB_EXTENSION_NAME@_SOURCES = coap-client.c
|
||||
coap_client@LIBCOAP_DTLS_LIB_EXTENSION_NAME@_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
|
||||
coap_server@LIBCOAP_DTLS_LIB_EXTENSION_NAME@_SOURCES = coap-server.c
|
||||
coap_server@LIBCOAP_DTLS_LIB_EXTENSION_NAME@_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
|
||||
coap_rd@LIBCOAP_DTLS_LIB_EXTENSION_NAME@_SOURCES = coap-rd.c
|
||||
coap_rd@LIBCOAP_DTLS_LIB_EXTENSION_NAME@_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
|
||||
coap_etsi_iot_01_SOURCES = etsi_iot_01.c
|
||||
coap_etsi_iot_01_LDADD = $(DTLS_LIBS) $(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
coap_etsi_iot_01_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
|
||||
coap_tiny_SOURCES = tiny.c
|
||||
coap_tiny_LDADD = $(DTLS_LIBS) $(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
coap_tiny_LDADD = $(DTLS_LIBS) \
|
||||
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
|
||||
|
||||
endif # BUILD_EXAMPLES
|
||||
|
||||
if BUILD_EXAMPLES_SOURCE
|
||||
EXAMPLES_DIR = $(DESTDIR)$(datadir)/libcoap/examples
|
||||
EXAMPLES_SRC = coap-client.c coap-server.c
|
||||
endif # BUILD_EXAMPLES_SOURCE
|
||||
|
||||
## Install example files
|
||||
install-exec-hook:
|
||||
if BUILD_EXAMPLES_SOURCE
|
||||
$(MKDIR_P) $(EXAMPLES_DIR)
|
||||
(cd $(top_srcdir)/examples ; \
|
||||
$(INSTALL_DATA) $(EXAMPLES_SRC) ../LICENSE ../COPYING $(EXAMPLES_DIR) ; \
|
||||
$(INSTALL_DATA) share.libcoap.examples.Makefile $(EXAMPLES_DIR)/Makefile; \
|
||||
$(INSTALL_DATA) share.libcoap.examples.README $(EXAMPLES_DIR)/README)
|
||||
endif # BUILD_EXAMPLES_SOURCE
|
||||
if BUILD_ADD_DEFAULT_NAMES
|
||||
if [ -d "$(DESTDIR)$(bindir)" ] ; then \
|
||||
(cd $(DESTDIR)$(bindir) && \
|
||||
(if [ -f coap-client@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ ] ; then \
|
||||
rm -f coap-client ; \
|
||||
$(LN_S) coap-client@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ coap-client ; \
|
||||
fi ; \
|
||||
if [ -f coap-server@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ ] ; then \
|
||||
rm -f coap-server ; \
|
||||
$(LN_S) coap-server@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ coap-server ; \
|
||||
fi ; \
|
||||
if [ -f coap-rd@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ ] ; then \
|
||||
rm -f coap-rd ; \
|
||||
$(LN_S) coap-rd@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ coap-rd ; \
|
||||
fi) \
|
||||
) ; \
|
||||
fi
|
||||
endif # BUILD_ADD_DEFAULT_NAMES
|
||||
|
||||
uninstall-hook:
|
||||
if BUILD_EXAMPLES_SOURCE
|
||||
rm -rf $(DESTDIR)$(datadir)/libcoap/examples
|
||||
endif # BUILD_EXAMPLES_SOURCE
|
||||
if BUILD_ADD_DEFAULT_NAMES
|
||||
rm -f $(DESTDIR)$(bindir)/coap-client
|
||||
rm -f $(DESTDIR)$(bindir)/coap-server
|
||||
rm -f $(DESTDIR)$(bindir)/coap-rd
|
||||
endif # BUILD_ADD_DEFAULT_NAMES
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+282
-95
@@ -5,16 +5,18 @@
|
||||
*
|
||||
* Copyright (C) 2010--2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms of
|
||||
* use.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file rd.c
|
||||
* @file coap-rd.c
|
||||
* @brief CoRE resource directory
|
||||
*
|
||||
* @see http://tools.ietf.org/id/draft-shelby-core-resource-directory
|
||||
* @see https://tools.ietf.org/html/draft-ietf-core-resource-directory
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
@@ -28,6 +30,9 @@
|
||||
#ifdef _WIN32
|
||||
#define strcasecmp _stricmp
|
||||
#include "getopt.c"
|
||||
#if !defined(S_ISDIR)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/select.h>
|
||||
@@ -38,21 +43,28 @@
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <coap2/coap.h>
|
||||
#include <coap3/coap.h>
|
||||
|
||||
#define COAP_RESOURCE_CHECK_TIME 2
|
||||
|
||||
#define RD_ROOT_STR "rd"
|
||||
#define RD_ROOT_SIZE 2
|
||||
|
||||
static char *cert_file = NULL; /* Combined certificate and private key in PEM */
|
||||
static char *ca_file = NULL; /* CA for cert_file - for cert checking in PEM */
|
||||
static char *root_ca_file = NULL; /* List of trusted Root CAs in PEM */
|
||||
static int verify_peer_cert = 1; /* PKI granularity - by default set */
|
||||
#define MAX_KEY 64 /* Maximum length of a pre-shared key in bytes. */
|
||||
static uint8_t key[MAX_KEY];
|
||||
static ssize_t key_length = 0;
|
||||
static int key_defined = 0;
|
||||
static const char *hint = "CoAP";
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
typedef struct rd_t {
|
||||
UT_hash_handle hh; /**< hash handle (for internal use only) */
|
||||
coap_string_t uri_path; /**< the actual key for this resource */
|
||||
|
||||
size_t etag_len; /**< actual length of @c etag */
|
||||
unsigned char etag[8]; /**< ETag for current description */
|
||||
|
||||
@@ -61,11 +73,15 @@ typedef struct rd_t {
|
||||
|
||||
rd_t *resources = NULL;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED_PARAM __attribute__ ((unused))
|
||||
#else /* not a GCC */
|
||||
#define UNUSED_PARAM
|
||||
#endif /* GCC */
|
||||
static ssize_t
|
||||
cmdline_read_key(char *arg, unsigned char *buf, size_t maxlen) {
|
||||
size_t len = strnlen(arg, maxlen);
|
||||
if (len) {
|
||||
memcpy(buf, arg, len);
|
||||
return len;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline rd_t *
|
||||
rd_new(void) {
|
||||
@@ -77,7 +93,7 @@ rd_new(void) {
|
||||
return rd;
|
||||
}
|
||||
|
||||
static inline void
|
||||
static void
|
||||
rd_delete(rd_t *rd) {
|
||||
if (rd) {
|
||||
coap_free(rd->data.s);
|
||||
@@ -85,28 +101,29 @@ rd_delete(rd_t *rd) {
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
resource_rd_delete(void *ptr) {
|
||||
rd_delete(ptr);
|
||||
}
|
||||
|
||||
static int quit = 0;
|
||||
|
||||
/* SIGINT handler: set quit to 1 for graceful termination */
|
||||
static void
|
||||
handle_sigint(int signum UNUSED_PARAM) {
|
||||
handle_sigint(int signum COAP_UNUSED) {
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_get_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_get_resource(coap_resource_t *resource,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request COAP_UNUSED,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
rd_t *rd = NULL;
|
||||
rd_t *rd = coap_resource_get_userdata(resource);
|
||||
unsigned char buf[3];
|
||||
|
||||
HASH_FIND(hh, resources, resource->uri_path->s, resource->uri_path->length, rd);
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(205);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
|
||||
|
||||
coap_add_option(response,
|
||||
COAP_OPTION_CONTENT_TYPE,
|
||||
@@ -122,15 +139,13 @@ hnd_get_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_put_resource(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request COAP_UNUSED,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
#if 1
|
||||
response->code = COAP_RESPONSE_CODE(501);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_IMPLEMENTED);
|
||||
#else /* FIXME */
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *token, *etag;
|
||||
@@ -140,7 +155,7 @@ hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
? COAP_MESSAGE_ACK : COAP_MESSAGE_NON;
|
||||
rd_t *rd = NULL;
|
||||
unsigned char code; /* result code */
|
||||
unsigned char *data;
|
||||
const uint8_t *data;
|
||||
coap_string_t tmp;
|
||||
|
||||
HASH_FIND(hh, resources, resource->uri_path.s, resource->uri_path.length, rd);
|
||||
@@ -156,7 +171,7 @@ hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
if (!tmp.s) {
|
||||
coap_log(LOG_DEBUG,
|
||||
"hnd_put_rd: cannot allocate storage for new rd\n");
|
||||
code = COAP_RESPONSE_CODE(503);
|
||||
code = COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@@ -172,12 +187,12 @@ hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
memcpy(rd->etag, COAP_OPT_VALUE(etag), rd->etag_len);
|
||||
}
|
||||
|
||||
code = COAP_RESPONSE_CODE(204);
|
||||
code = COAP_RESPONSE_CODE_CHANGED;
|
||||
/* FIXME: update lifetime */
|
||||
|
||||
} else {
|
||||
|
||||
code = COAP_RESPONSE_CODE(503);
|
||||
code = COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
finish:
|
||||
@@ -185,7 +200,7 @@ hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
response = coap_pdu_init(type, code, request->hdr->id, size);
|
||||
|
||||
if (!response) {
|
||||
coap_log(LOG_DEBUG, "cannot create response for message %d\n",
|
||||
coap_log(LOG_DEBUG, "cannot create response for mid=0x%x\n",
|
||||
request->hdr->id);
|
||||
return;
|
||||
}
|
||||
@@ -193,46 +208,40 @@ hnd_put_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
if (request->hdr->token_length)
|
||||
coap_add_token(response, request->hdr->token_length, request->hdr->token);
|
||||
|
||||
if (coap_send(ctx, peer, response) == COAP_INVALID_TID) {
|
||||
coap_log(LOG_DEBUG, "hnd_get_rd: cannot send response for message %d\n",
|
||||
if (coap_send(ctx, peer, response) == COAP_INVALID_MID) {
|
||||
coap_log(LOG_DEBUG, "hnd_get_rd: cannot send response for mid=0x%x\n",
|
||||
request->hdr->id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_delete_resource(coap_context_t *ctx,
|
||||
struct coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_delete_resource(coap_resource_t *resource,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request COAP_UNUSED,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
rd_t *rd = NULL;
|
||||
rd_t *rd = coap_resource_get_userdata(resource);
|
||||
|
||||
HASH_FIND(hh, resources, resource->uri_path->s, resource->uri_path->length, rd);
|
||||
if (rd) {
|
||||
HASH_DELETE(hh, resources, rd);
|
||||
rd_delete(rd);
|
||||
}
|
||||
/* FIXME: link attributes for resource have been created dynamically
|
||||
* using coap_malloc() and must be released. */
|
||||
coap_delete_resource(ctx, resource);
|
||||
coap_delete_resource(coap_session_get_context(session), resource);
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(202);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_get_rd(coap_context_t *ctx UNUSED_PARAM,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_get_rd(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request COAP_UNUSED,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
unsigned char buf[3];
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(205);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
|
||||
|
||||
coap_add_option(response,
|
||||
COAP_OPTION_CONTENT_TYPE,
|
||||
@@ -293,8 +302,8 @@ parse_param(const uint8_t *search,
|
||||
}
|
||||
|
||||
static void
|
||||
add_source_address(struct coap_resource_t *resource,
|
||||
coap_address_t *peer) {
|
||||
add_source_address(coap_resource_t *resource,
|
||||
const coap_address_t *peer) {
|
||||
#define BUFSIZE 64
|
||||
char *buf;
|
||||
size_t n = 1;
|
||||
@@ -350,14 +359,15 @@ add_source_address(struct coap_resource_t *resource,
|
||||
coap_add_attr(resource,
|
||||
coap_make_str_const("A"),
|
||||
&attr_val,
|
||||
COAP_ATTR_FLAGS_RELEASE_VALUE);
|
||||
0);
|
||||
coap_free(buf);
|
||||
#undef BUFSIZE
|
||||
}
|
||||
|
||||
static rd_t *
|
||||
make_rd(coap_pdu_t *pdu) {
|
||||
make_rd(const coap_pdu_t *pdu) {
|
||||
rd_t *rd;
|
||||
unsigned char *data;
|
||||
const uint8_t *data;
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *etag;
|
||||
|
||||
@@ -388,12 +398,10 @@ make_rd(coap_pdu_t *pdu) {
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_post_rd(coap_context_t *ctx,
|
||||
struct coap_resource_t *resource UNUSED_PARAM,
|
||||
hnd_post_rd(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
const coap_pdu_t *request,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
coap_resource_t *r;
|
||||
#define LOCSIZE 68
|
||||
@@ -406,7 +414,7 @@ hnd_post_rd(coap_context_t *ctx,
|
||||
|
||||
loc = (unsigned char *)coap_malloc(LOCSIZE);
|
||||
if (!loc) {
|
||||
response->code = COAP_RESPONSE_CODE(500);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
|
||||
return;
|
||||
}
|
||||
memcpy(loc, RD_ROOT_STR, RD_ROOT_SIZE);
|
||||
@@ -436,7 +444,7 @@ hnd_post_rd(coap_context_t *ctx,
|
||||
} else { /* generate node identifier */
|
||||
loc_size +=
|
||||
snprintf((char *)(loc + loc_size), LOCSIZE - loc_size - 1,
|
||||
"%x", request->tid);
|
||||
"%x", coap_pdu_get_mid(request));
|
||||
|
||||
if (loc_size > 1) {
|
||||
if (ins.length) {
|
||||
@@ -463,7 +471,7 @@ hnd_post_rd(coap_context_t *ctx,
|
||||
|
||||
resource_val.s = loc;
|
||||
resource_val.length = loc_size;
|
||||
r = coap_resource_init(&resource_val, COAP_RESOURCE_FLAGS_RELEASE_URI);
|
||||
r = coap_resource_init(&resource_val, 0);
|
||||
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_resource);
|
||||
coap_register_handler(r, COAP_REQUEST_PUT, hnd_put_resource);
|
||||
coap_register_handler(r, COAP_REQUEST_DELETE, hnd_delete_resource);
|
||||
@@ -480,7 +488,8 @@ hnd_post_rd(coap_context_t *ctx,
|
||||
coap_add_attr(r,
|
||||
coap_make_str_const("ins"),
|
||||
&attr_val,
|
||||
COAP_ATTR_FLAGS_RELEASE_VALUE);
|
||||
0);
|
||||
coap_free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,30 +505,29 @@ hnd_post_rd(coap_context_t *ctx,
|
||||
coap_add_attr(r,
|
||||
coap_make_str_const("rt"),
|
||||
&attr_val,
|
||||
COAP_ATTR_FLAGS_RELEASE_VALUE);
|
||||
0);
|
||||
coap_free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
add_source_address(r, &session->addr_info.remote);
|
||||
add_source_address(r, coap_session_get_addr_remote(session));
|
||||
|
||||
{
|
||||
rd_t *rd;
|
||||
rd = make_rd(request);
|
||||
if (rd) {
|
||||
rd->uri_path.s = loc;
|
||||
rd->uri_path.length = loc_size;
|
||||
HASH_ADD(hh, resources, uri_path.s[0], rd->uri_path.length, rd);
|
||||
coap_resource_set_userdata(r, rd);
|
||||
} else {
|
||||
/* FIXME: send error response and delete r */
|
||||
}
|
||||
}
|
||||
|
||||
coap_add_resource(ctx, r);
|
||||
coap_add_resource(coap_session_get_context(session), r);
|
||||
|
||||
|
||||
/* create response */
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(201);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CREATED);
|
||||
|
||||
{ /* split path into segments and add Location-Path options */
|
||||
unsigned char _b[LOCSIZE];
|
||||
@@ -536,6 +544,7 @@ hnd_post_rd(coap_context_t *ctx,
|
||||
b += coap_opt_size(b);
|
||||
}
|
||||
}
|
||||
coap_free(loc);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -552,28 +561,138 @@ init_resources(coap_context_t *ctx) {
|
||||
|
||||
coap_add_resource(ctx, r);
|
||||
|
||||
coap_resource_release_userdata_handler(ctx, resource_rd_delete);
|
||||
}
|
||||
|
||||
static void
|
||||
usage( const char *program, const char *version) {
|
||||
const char *p;
|
||||
char buffer[64];
|
||||
char buffer[72];
|
||||
const char *lib_version = coap_package_version();
|
||||
|
||||
p = strrchr( program, '/' );
|
||||
if ( p )
|
||||
program = ++p;
|
||||
|
||||
fprintf( stderr, "%s v%s -- CoRE Resource Directory implementation\n"
|
||||
"(c) 2011-2012 Olaf Bergmann <bergmann@tzi.org>\n\n"
|
||||
"%s\n\n"
|
||||
"usage: %s [-A address] [-p port]\n\n"
|
||||
"\t-A address\tinterface address to bind to\n"
|
||||
"\t-p port\t\tlisten on specified port\n"
|
||||
"\t-v num\t\tverbosity level (default: 3)\n",
|
||||
program, version, coap_string_tls_version(buffer, sizeof(buffer)),
|
||||
"(c) 2011-2012,2019-2021 Olaf Bergmann <bergmann@tzi.org> and others\n\n"
|
||||
"%s\n"
|
||||
"%s\n"
|
||||
, program, version, lib_version,
|
||||
coap_string_tls_version(buffer, sizeof(buffer)));
|
||||
fprintf(stderr, "%s\n", coap_string_tls_support(buffer, sizeof(buffer)));
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-g group] [-G group_if] [-p port] [-v num] [-A address]\n"
|
||||
"\t [[-h hint] [-k key]]\n"
|
||||
"\t [[-c certfile] [-C cafile] [-n] [-R trust_casfile]]\n"
|
||||
"General Options\n"
|
||||
"\t-g group\tJoin the given multicast group.\n"
|
||||
"\t \t\tNote: DTLS over multicast is not currently supported\n"
|
||||
"\t-G group_if\tUse this interface for listening for the multicast\n"
|
||||
"\t \t\tgroup. This can be different from the implied interface\n"
|
||||
"\t \t\tif the -A option is used\n"
|
||||
"\t-p port\t\tListen on specified port\n"
|
||||
"\t-v num \t\tVerbosity level (default 3, maximum is 9). Above 7,\n"
|
||||
"\t \t\tthere is increased verbosity in GnuTLS and OpenSSL logging\n"
|
||||
"\t-A address\tInterface address to bind to\n"
|
||||
"PSK Options (if supported by underlying (D)TLS library)\n"
|
||||
"\t-h hint\t\tIdentity Hint. Default is CoAP. Zero length is no hint\n"
|
||||
"\t-k key \t\tPre-Shared Key. This argument requires (D)TLS with PSK\n"
|
||||
"\t \t\tto be available. This cannot be empty if defined.\n"
|
||||
"\t \t\tNote that both -c and -k need to be defined\n"
|
||||
"\t \t\tfor both PSK and PKI to be concurrently supported\n"
|
||||
"PKI Options (if supported by underlying (D)TLS library)\n"
|
||||
"\t-c certfile\tPEM file containing both CERTIFICATE and PRIVATE KEY\n"
|
||||
"\t \t\tThis argument requires (D)TLS with PKI to be available\n"
|
||||
"\t-n \t\tDisable remote peer certificate checking. This gives\n"
|
||||
"\t \t\tclients the ability to use PKI, but without any defined\n"
|
||||
"\t \t\tcertificates\n"
|
||||
"\t-C cafile\tPEM file that contains a list of one or\n"
|
||||
"\t \t\tmore CAs that are to be passed to the client for the\n"
|
||||
"\t \t\tclient to determine what client certificate to use.\n"
|
||||
"\t \t\tNormally, this list of CAs would be the root CA and and\n"
|
||||
"\t \t\tany intermediate CAs. Ideally the server certificate\n"
|
||||
"\t \t\tshould be signed by the same CA so that mutual\n"
|
||||
"\t \t\tauthentication can take place. The contents of cafile\n"
|
||||
"\t \t\tare added to the trusted store of root CAs.\n"
|
||||
"\t \t\tUsing the -C or -R options will will trigger the\n"
|
||||
"\t \t\tvalidation of the client certificate unless overridden\n"
|
||||
"\t \t\tby the -n option\n"
|
||||
"\t-R trust_casfile\tPEM file containing the set of trusted root CAs\n"
|
||||
"\t \t\tthat are to be used to validate the client certificate.\n"
|
||||
"\t \t\tAlternatively, this can point to a directory containing\n"
|
||||
"\t \t\ta set of CA PEM files.\n"
|
||||
"\t \t\tUsing '-R trust_casfile' disables common CA mutual\n"
|
||||
"\t \t\tauthentication which can only be done by using\n"
|
||||
"\t \t\t'-C cafile'.\n"
|
||||
"\t \t\tUsing the -C or -R options will will trigger the\n"
|
||||
"\t \t\tvalidation of the client certificate unless overridden\n"
|
||||
"\t \t\tby the -n option\n"
|
||||
,
|
||||
program);
|
||||
}
|
||||
|
||||
static void
|
||||
fill_keystore(coap_context_t *ctx) {
|
||||
if (cert_file == NULL && key_defined == 0) {
|
||||
if (coap_dtls_is_supported() || coap_tls_is_supported()) {
|
||||
coap_log(LOG_DEBUG,
|
||||
"(D)TLS not enabled as neither -k or -c options specified\n");
|
||||
}
|
||||
}
|
||||
if (cert_file) {
|
||||
coap_dtls_pki_t dtls_pki;
|
||||
memset (&dtls_pki, 0, sizeof(dtls_pki));
|
||||
dtls_pki.version = COAP_DTLS_PKI_SETUP_VERSION;
|
||||
if (ca_file || root_ca_file) {
|
||||
/*
|
||||
* Add in additional certificate checking.
|
||||
* This list of enabled can be tuned for the specific
|
||||
* requirements - see 'man coap_encryption'.
|
||||
*/
|
||||
dtls_pki.verify_peer_cert = verify_peer_cert;
|
||||
dtls_pki.check_common_ca = !root_ca_file;
|
||||
dtls_pki.allow_self_signed = 1;
|
||||
dtls_pki.allow_expired_certs = 1;
|
||||
dtls_pki.cert_chain_validation = 1;
|
||||
dtls_pki.cert_chain_verify_depth = 2;
|
||||
dtls_pki.check_cert_revocation = 1;
|
||||
dtls_pki.allow_no_crl = 1;
|
||||
dtls_pki.allow_expired_crl = 1;
|
||||
dtls_pki.validate_cn_call_back = NULL;
|
||||
dtls_pki.cn_call_back_arg = NULL;
|
||||
dtls_pki.validate_sni_call_back = NULL;
|
||||
dtls_pki.sni_call_back_arg = NULL;
|
||||
}
|
||||
dtls_pki.pki_key.key_type = COAP_PKI_KEY_PEM;
|
||||
dtls_pki.pki_key.key.pem.public_cert = cert_file;
|
||||
dtls_pki.pki_key.key.pem.private_key = cert_file;
|
||||
dtls_pki.pki_key.key.pem.ca_file = ca_file;
|
||||
/* If general root CAs are defined */
|
||||
if (root_ca_file) {
|
||||
struct stat stbuf;
|
||||
if ((stat(root_ca_file, &stbuf) == 0) && S_ISDIR(stbuf.st_mode)) {
|
||||
coap_context_set_pki_root_cas(ctx, NULL, root_ca_file);
|
||||
} else {
|
||||
coap_context_set_pki_root_cas(ctx, root_ca_file, NULL);
|
||||
}
|
||||
}
|
||||
coap_context_set_pki(ctx, &dtls_pki);
|
||||
}
|
||||
if (key_defined) {
|
||||
coap_dtls_spsk_t dtls_psk;
|
||||
memset (&dtls_psk, 0, sizeof(dtls_psk));
|
||||
dtls_psk.version = COAP_DTLS_SPSK_SETUP_VERSION;
|
||||
dtls_psk.validate_id_call_back = NULL;
|
||||
dtls_psk.validate_sni_call_back = NULL;
|
||||
dtls_psk.psk_info.hint.s = (const uint8_t *)hint;
|
||||
dtls_psk.psk_info.hint.length = hint ? strlen(hint) : 0;
|
||||
dtls_psk.psk_info.key.s = key;
|
||||
dtls_psk.psk_info.key.length = key_length;
|
||||
coap_context_set_psk2(ctx, &dtls_psk);
|
||||
}
|
||||
}
|
||||
|
||||
static coap_context_t *
|
||||
get_context(const char *node, const char *port) {
|
||||
coap_context_t *ctx = NULL;
|
||||
@@ -581,6 +700,13 @@ get_context(const char *node, const char *port) {
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *result, *rp;
|
||||
|
||||
ctx = coap_new_context(NULL);
|
||||
if (!ctx) {
|
||||
return NULL;
|
||||
}
|
||||
/* Need PSK set up before we set up (D)TLS endpoints */
|
||||
fill_keystore(ctx);
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
hints.ai_socktype = SOCK_DGRAM; /* Coap uses UDP */
|
||||
@@ -589,29 +715,59 @@ get_context(const char *node, const char *port) {
|
||||
s = getaddrinfo(node, port, &hints, &result);
|
||||
if ( s != 0 ) {
|
||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
|
||||
coap_free_context(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* iterate through results until success */
|
||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||
coap_address_t addr;
|
||||
coap_address_t addr, addrs;
|
||||
coap_endpoint_t *ep_udp = NULL, *ep_dtls = NULL, *ep_tcp = NULL, *ep_tls = NULL;
|
||||
|
||||
if (rp->ai_addrlen <= sizeof(addr.addr)) {
|
||||
if (rp->ai_addrlen <= (socklen_t)sizeof(addr.addr)) {
|
||||
coap_address_init(&addr);
|
||||
addr.size = rp->ai_addrlen;
|
||||
addr.size = (socklen_t)rp->ai_addrlen;
|
||||
memcpy(&addr.addr, rp->ai_addr, rp->ai_addrlen);
|
||||
|
||||
ctx = coap_new_context(&addr);
|
||||
if (ctx) {
|
||||
/* TODO: output address:port for successful binding */
|
||||
addrs = addr;
|
||||
if (addr.addr.sa.sa_family == AF_INET) {
|
||||
uint16_t temp = ntohs(addr.addr.sin.sin_port) + 1;
|
||||
addrs.addr.sin.sin_port = htons(temp);
|
||||
} else if (addr.addr.sa.sa_family == AF_INET6) {
|
||||
uint16_t temp = ntohs(addr.addr.sin6.sin6_port) + 1;
|
||||
addrs.addr.sin6.sin6_port = htons(temp);
|
||||
} else {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
ep_udp = coap_new_endpoint(ctx, &addr, COAP_PROTO_UDP);
|
||||
if (ep_udp) {
|
||||
if (coap_dtls_is_supported() && (key_defined || cert_file)) {
|
||||
ep_dtls = coap_new_endpoint(ctx, &addrs, COAP_PROTO_DTLS);
|
||||
if (!ep_dtls)
|
||||
coap_log(LOG_CRIT, "cannot create DTLS endpoint\n");
|
||||
}
|
||||
} else {
|
||||
coap_log(LOG_CRIT, "cannot create UDP endpoint\n");
|
||||
continue;
|
||||
}
|
||||
ep_tcp = coap_new_endpoint(ctx, &addr, COAP_PROTO_TCP);
|
||||
if (ep_tcp) {
|
||||
if (coap_tls_is_supported() && (key_defined || cert_file)) {
|
||||
ep_tls = coap_new_endpoint(ctx, &addrs, COAP_PROTO_TLS);
|
||||
if (!ep_tls)
|
||||
coap_log(LOG_CRIT, "cannot create TLS endpoint\n");
|
||||
}
|
||||
} else {
|
||||
coap_log(LOG_CRIT, "cannot create TCP endpoint\n");
|
||||
}
|
||||
if (ep_udp)
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "no context available for interface '%s'\n", node);
|
||||
|
||||
finish:
|
||||
finish:
|
||||
freeaddrinfo(result);
|
||||
return ctx;
|
||||
}
|
||||
@@ -623,21 +779,52 @@ main(int argc, char **argv) {
|
||||
char addr_str[NI_MAXHOST] = "::";
|
||||
char port_str[NI_MAXSERV] = "5683";
|
||||
char *group = NULL;
|
||||
char *group_if = NULL;
|
||||
int opt;
|
||||
coap_log_t log_level = LOG_WARNING;
|
||||
#ifndef _WIN32
|
||||
struct sigaction sa;
|
||||
#endif
|
||||
|
||||
while ((opt = getopt(argc, argv, "A:g:p:v:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "A:c:C:g:G:h:k:n:R:p:v:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'A' :
|
||||
strncpy(addr_str, optarg, NI_MAXHOST-1);
|
||||
addr_str[NI_MAXHOST - 1] = '\0';
|
||||
break;
|
||||
case 'c' :
|
||||
cert_file = optarg;
|
||||
break;
|
||||
case 'C' :
|
||||
ca_file = optarg;
|
||||
break;
|
||||
case 'g' :
|
||||
group = optarg;
|
||||
break;
|
||||
case 'G' :
|
||||
group_if = optarg;
|
||||
break;
|
||||
case 'h' :
|
||||
if (!optarg[0]) {
|
||||
hint = NULL;
|
||||
break;
|
||||
}
|
||||
hint = optarg;
|
||||
break;
|
||||
case 'k' :
|
||||
key_length = cmdline_read_key(optarg, key, MAX_KEY);
|
||||
if (key_length < 0) {
|
||||
coap_log( LOG_CRIT, "Invalid Pre-Shared Key specified\n" );
|
||||
break;
|
||||
}
|
||||
key_defined = 1;
|
||||
break;
|
||||
case 'n':
|
||||
verify_peer_cert = 0;
|
||||
break;
|
||||
case 'R' :
|
||||
root_ca_file = optarg;
|
||||
break;
|
||||
case 'p' :
|
||||
strncpy(port_str, optarg, NI_MAXSERV-1);
|
||||
port_str[NI_MAXSERV - 1] = '\0';
|
||||
@@ -660,7 +847,7 @@ main(int argc, char **argv) {
|
||||
return -1;
|
||||
|
||||
if (group)
|
||||
coap_join_mcast_group(ctx, group);
|
||||
coap_join_mcast_group_intf(ctx, group, group_if);
|
||||
|
||||
init_resources(ctx);
|
||||
|
||||
@@ -679,7 +866,7 @@ main(int argc, char **argv) {
|
||||
#endif
|
||||
|
||||
while ( !quit ) {
|
||||
result = coap_run_once( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
|
||||
result = coap_io_process( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
|
||||
if ( result >= 0 ) {
|
||||
/* coap_check_resource_list( ctx ); */
|
||||
}
|
||||
|
||||
+2200
-377
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,8 @@
|
||||
*
|
||||
* Copyright (C) 2010,2011,2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms of
|
||||
* use.
|
||||
*/
|
||||
@@ -25,16 +27,10 @@
|
||||
* of coap-client
|
||||
*/
|
||||
|
||||
/* #include "coap_config.h" */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <coap2/libcoap.h>
|
||||
#include <coap2/debug.h>
|
||||
#include <coap2/mem.h>
|
||||
#include "coap_list.h"
|
||||
|
||||
#include <coap3/coap.h>
|
||||
|
||||
int
|
||||
coap_insert(coap_list_t **head, coap_list_t *node) {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
*
|
||||
* Copyright (C) 2010,2011,2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms of
|
||||
* use.
|
||||
*/
|
||||
@@ -28,7 +30,7 @@
|
||||
#ifndef COAP_LIST_H_
|
||||
#define COAP_LIST_H_
|
||||
|
||||
#include <coap2/utlist.h>
|
||||
#include <coap3/utlist.h>
|
||||
|
||||
typedef struct coap_list_t {
|
||||
struct coap_list_t *next;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "coap.h"
|
||||
#include "coap3/coap.h"
|
||||
|
||||
static coap_context_t *coap_context;
|
||||
|
||||
@@ -92,7 +92,7 @@ init_coap() {
|
||||
}
|
||||
|
||||
void
|
||||
message_handler(struct coap_context_t *ctx,
|
||||
message_handler(coap_context_t *ctx,
|
||||
const coap_address_t *remote,
|
||||
coap_pdu_t *sent,
|
||||
coap_pdu_t *received,
|
||||
@@ -166,7 +166,7 @@ PROCESS_THREAD(coap_server_process, ev, data)
|
||||
coap_add_option(request, COAP_OPTION_OBSERVE, 0, NULL);
|
||||
{
|
||||
unsigned char buf[2];
|
||||
prng(buf, 2);
|
||||
coap_prng(buf, 2);
|
||||
coap_add_option(request, COAP_OPTION_TOKEN, 2, buf);
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ PROCESS_THREAD(coap_server_process, ev, data)
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if(ev == tcpip_event) {
|
||||
coap_read(coap_context); /* read received data */
|
||||
coap_io_do_io(coap_context); /* read received data */
|
||||
coap_dispatch(coap_context); /* and dispatch PDUs from receivequeue */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../coap_config.h.contiki
|
||||
@@ -0,0 +1,209 @@
|
||||
#ifndef COAP_CONFIG_H_
|
||||
#define COAP_CONFIG_H_
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#define WITH_CONTIKI 1
|
||||
|
||||
#ifndef COAP_CONSTRAINED_STACK
|
||||
#define COAP_CONSTRAINED_STACK 1
|
||||
#endif
|
||||
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 1
|
||||
#endif
|
||||
|
||||
#define PACKAGE_STRING "libcoap"
|
||||
#define PACKAGE_NAME "libcoap"
|
||||
|
||||
#ifndef COAP_DEFAULT_PDU_SIZE
|
||||
#define COAP_DEFAULT_PDU_SIZE 64
|
||||
#endif /* COAP_DEFAULT_PDU_SIZE */
|
||||
#ifndef COAP_RXBUFFER_SIZE
|
||||
#define COAP_RXBUFFER_SIZE 64
|
||||
#endif /* COAP_RXBUFFER_SIZE */
|
||||
|
||||
/** Number of resources that can be handled by a CoAP server in addition to
|
||||
* @c /.well-known/core */
|
||||
#ifndef COAP_MAX_RESOURCES
|
||||
#define COAP_MAX_RESOURCES 3
|
||||
#endif /* COAP_MAX_RESOURCES */
|
||||
|
||||
/** Number of attributes that can be handled (should be at least
|
||||
* @c 2 * COAP_MAX_RESOURCES. to carry the content type and the
|
||||
* resource type. */
|
||||
#ifndef COAP_MAX_ATTRIBUTES
|
||||
#define COAP_MAX_ATTRIBUTES 4
|
||||
#endif /* COAP_MAX_ATTRIBUTES */
|
||||
|
||||
/**
|
||||
* Number of PDUs that can be stored simultaneously. This number
|
||||
* includes both, the PDUs stored for retransmission as well as the
|
||||
* PDUs received. Beware that choosing a too small value can lead to
|
||||
* many retransmissions to be dealt with.
|
||||
*/
|
||||
#ifndef COAP_PDU_MAXCNT
|
||||
#define COAP_PDU_MAXCNT 4
|
||||
#endif /* COAP_PDU_MAXCNT */
|
||||
|
||||
/**
|
||||
* Maximum number of sessions.
|
||||
*/
|
||||
#ifndef COAP_MAX_SESSIONS
|
||||
#define COAP_MAX_SESSIONS 2
|
||||
#endif /* COAP_MAX_SESSIONS */
|
||||
|
||||
/**
|
||||
* Maximum number of subscriptions. Every additional subscriber costs
|
||||
* 36 B.
|
||||
*/
|
||||
#ifndef COAP_MAX_SUBSCRIBERS
|
||||
#define COAP_MAX_SUBSCRIBERS 3
|
||||
#endif /* COAP_MAX_SUBSCRIBERS */
|
||||
|
||||
/**
|
||||
* The maximum number of cache-key entries that allocate
|
||||
* fixed-size memory blocks.
|
||||
*/
|
||||
#ifndef COAP_MAX_CACHE_KEYS
|
||||
#define COAP_MAX_CACHE_KEYS (2U)
|
||||
#endif /* COAP_MAX_CACHE_KEYS */
|
||||
|
||||
/**
|
||||
* The maximum number of cache-entry entries that allocate
|
||||
* fixed-size memory blocks.
|
||||
*/
|
||||
#ifndef COAP_MAX_CACHE_ENTRIES
|
||||
#define COAP_MAX_CACHE_ENTRIES (2U)
|
||||
#endif /* COAP_MAX_CACHE_ENTRIES */
|
||||
|
||||
/**
|
||||
* Maximum number of large body transmissions.
|
||||
*/
|
||||
#ifndef COAP_MAX_LG_XMIT
|
||||
#define COAP_MAX_LG_XMIT 2
|
||||
#endif /* COAP_MAX_LG_XMIT */
|
||||
|
||||
/**
|
||||
* Maximum number of large body client receives.
|
||||
*/
|
||||
#ifndef COAP_MAX_LG_CRCV
|
||||
#define COAP_MAX_LG_CRCV 2
|
||||
#endif /* COAP_MAX_LG_CRCV */
|
||||
|
||||
/**
|
||||
* Maximum number of large body server receives.
|
||||
*/
|
||||
#ifndef COAP_MAX_LG_SRCV
|
||||
#define COAP_MAX_LG_SRCV 2
|
||||
#endif /* COAP_MAX_LG_SRCV */
|
||||
|
||||
/**
|
||||
* Number of notifications that may be sent non-confirmable before a
|
||||
* confirmable message is sent to detect if observers are alive. The
|
||||
* maximum allowed value here is @c 15.
|
||||
*/
|
||||
#ifndef COAP_OBS_MAX_NON
|
||||
#define COAP_OBS_MAX_NON 5
|
||||
#endif /* COAP_OBS_MAX_NON */
|
||||
|
||||
/**
|
||||
* Number of confirmable notifications that may fail (i.e. time out
|
||||
* without being ACKed) before an observer is removed. The maximum
|
||||
* value for COAP_OBS_MAX_FAIL is @c 3.
|
||||
*/
|
||||
#ifndef COAP_OBS_MAX_FAIL
|
||||
#define COAP_OBS_MAX_FAIL 3
|
||||
#endif /* COAP_OBS_MAX_FAIL */
|
||||
|
||||
#ifndef DEBUG
|
||||
# define DEBUG DEBUG_PRINT
|
||||
#endif
|
||||
|
||||
#define HAVE_STRNLEN 1
|
||||
#define HAVE_SNPRINTF 1
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* there is no file-oriented output */
|
||||
#define COAP_DEBUG_FD NULL
|
||||
#define COAP_ERR_FD NULL
|
||||
|
||||
#include "contiki-conf.h"
|
||||
|
||||
#if (defined(PLATFORM) && PLATFORM == PLATFORM_MC1322X) || defined(CONTIKI_TARGET_ECONOTAG)
|
||||
/* Redbee econotags get a special treatment here: endianness is set
|
||||
* explicitly, and
|
||||
*/
|
||||
|
||||
#define BYTE_ORDER UIP_LITTLE_ENDIAN
|
||||
|
||||
#define HAVE_ASSERT_H
|
||||
#define HAVE_UNISTD_H
|
||||
#define HAVE_SYS_TYPES_H
|
||||
#define HAVE_LIMITS_H
|
||||
#endif /* PLATFORM_MC1322X || CONTIKI_TARGET_ECONOTAG */
|
||||
|
||||
#if defined(TMOTE_SKY) || defined(CONTIKI_TARGET_SKY) || defined(CONTIKI_TARGET_WISMOTE)
|
||||
/* Need to set the byte order for TMote Sky explicitely */
|
||||
|
||||
#define BYTE_ORDER UIP_LITTLE_ENDIAN
|
||||
#undef COAP_DEFAULT_PDU_SIZE
|
||||
#undef COAP_RXBUFFER_SIZE
|
||||
#define COAP_DEFAULT_PDU_SIZE 100
|
||||
#define COAP_RXBUFFER_SIZE 100
|
||||
|
||||
#define COAP_MAX_BLOCK_SZX 2
|
||||
|
||||
typedef int ssize_t;
|
||||
typedef void FILE;
|
||||
|
||||
#define HAVE_LIMITS_H 1
|
||||
#undef HAVE_ASSERT_H
|
||||
#define HAVE_VPRINTF 1
|
||||
#endif /* defined(TMOTE_SKY) */
|
||||
|
||||
#ifdef CONTIKI_TARGET_MINIMAL_NET
|
||||
#undef COAP_DEFAULT_PDU_SIZE
|
||||
#undef COAP_RXBUFFER_SIZE
|
||||
#define COAP_DEFAULT_PDU_SIZE 1152
|
||||
#define COAP_RXBUFFER_SIZE 1472
|
||||
#define HAVE_ASSERT_H 1
|
||||
#define HAVE_VPRINTF 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#endif /* CONTIKI_TARGET_MINIMAL_NET */
|
||||
|
||||
#ifdef CONTIKI_TARGET_CC2538DK
|
||||
#define BYTE_ORDER UIP_LITTLE_ENDIAN
|
||||
#undef COAP_DEFAULT_PDU_SIZE
|
||||
#undef COAP_RXBUFFER_SIZE
|
||||
#define COAP_DEFAULT_PDU_SIZE 100
|
||||
#define COAP_RXBUFFER_SIZE 100
|
||||
|
||||
#undef COAP_MAX_BLOCK_SZX
|
||||
#define COAP_MAX_BLOCK_SZX 2
|
||||
|
||||
#define HAVE_LIMITS_H 1
|
||||
#endif /* CONTIKI_TARGET_CC2538DK */
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
# ifdef UIP_CONF_BYTE_ORDER
|
||||
# define BYTE_ORDER UIP_CONF_BYTE_ORDER
|
||||
# else
|
||||
# error "UIP_CONF_BYTE_ORDER not defined"
|
||||
# endif /* UIP_CONF_BYTE_ORDER */
|
||||
#endif /* BYTE_ORDER */
|
||||
|
||||
/* Define assert() as empty directive unless HAVE_ASSERT_H is given. */
|
||||
#ifndef HAVE_ASSERT_H
|
||||
# define assert(x)
|
||||
#endif
|
||||
|
||||
#define ntohs uip_ntohs
|
||||
|
||||
#include <stdio.h>
|
||||
#define coap_log(fd, ...) printf(__VA_ARGS__)
|
||||
|
||||
#endif /* COAP_CONFIG_H_ */
|
||||
|
||||
+27
-33
@@ -38,7 +38,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "coap.h"
|
||||
#include "coap3/coap.h"
|
||||
|
||||
static coap_context_t *coap_context;
|
||||
|
||||
@@ -91,52 +91,46 @@ init_coap_server(coap_context_t **ctx) {
|
||||
#endif
|
||||
|
||||
void
|
||||
hnd_get_time(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_string_t *query,
|
||||
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;
|
||||
|
||||
/* 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 */
|
||||
response->code =
|
||||
my_clock_base ? COAP_RESPONSE_CODE(205) : COAP_RESPONSE_CODE(404);
|
||||
|
||||
if (coap_find_observer(resource, session, token)) {
|
||||
coap_add_option(response, COAP_OPTION_OBSERVE,
|
||||
coap_encode_var_safe(buf, sizeof(buf),
|
||||
resource->observe),
|
||||
buf);
|
||||
}
|
||||
|
||||
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);
|
||||
/* output ticks */
|
||||
len = snprintf((char *)buf, sizeof(buf), "%u", (unsigned int)now);
|
||||
|
||||
} else { /* output human-readable time */
|
||||
struct tm *tmp;
|
||||
time_t tnow = now;
|
||||
tmp = gmtime(&tnow);
|
||||
if (!tmp) {
|
||||
/* If 'tnow' is not valid */
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
len = strftime((char *)buf, sizeof(buf), "%b %d %H:%M:%S", tmp);
|
||||
}
|
||||
}
|
||||
coap_add_data_blocked_response(request, response,
|
||||
COAP_MEDIATYPE_TEXT_PLAIN, 1,
|
||||
len,
|
||||
buf);
|
||||
}
|
||||
else {
|
||||
/* if my_clock_base was deleted, we pretend to have no such resource */
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +210,7 @@ PROCESS_THREAD(coap_server_process, ev, data)
|
||||
PROCESS_YIELD();
|
||||
if(ev == tcpip_event) {
|
||||
/* There is something to read on the endpoint */
|
||||
coap_run_once(coap_context, COAP_RUN_BLOCK);
|
||||
coap_io_process(coap_context, COAP_IO_WAIT);
|
||||
} else if (ev == PROCESS_EVENT_TIMER && etimer_expired(&dirty_timer)) {
|
||||
coap_resource_notify_observers(time_resource, NULL);
|
||||
etimer_reset(&dirty_timer);
|
||||
|
||||
Executable → Regular
+104
-157
@@ -2,6 +2,8 @@
|
||||
*
|
||||
* Copyright (C) 2012--2013 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
*/
|
||||
@@ -22,17 +24,10 @@
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "uthash.h"
|
||||
#include "coap.h"
|
||||
#include <coap3/coap.h>
|
||||
|
||||
#define COAP_RESOURCE_CHECK_TIME_SEC 1
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED_PARAM __attribute__ ((unused))
|
||||
#else /* not a GCC */
|
||||
#define UNUSED_PARAM
|
||||
#endif /* GCC */
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
@@ -51,13 +46,9 @@ typedef struct {
|
||||
unsigned char data[]; /* the actual contents */
|
||||
} coap_payload_t;
|
||||
|
||||
/* This variable is used to mimic long-running tasks that require
|
||||
* asynchronous responses. */
|
||||
static coap_async_state_t *async = NULL;
|
||||
|
||||
/* SIGINT handler: set quit to 1 for graceful termination */
|
||||
static void
|
||||
handle_sigint(int signum UNUSED_PARAM) {
|
||||
handle_sigint(int signum COAP_UNUSED) {
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
@@ -78,37 +69,37 @@ coap_new_payload(size_t size) {
|
||||
|
||||
static inline coap_payload_t *
|
||||
coap_find_payload(coap_resource_t *resource) {
|
||||
coap_payload_t *p = (coap_payload_t *)resource->user_data;
|
||||
return p;
|
||||
return coap_resource_get_userdata(resource);
|
||||
}
|
||||
|
||||
static void
|
||||
coap_add_payload(coap_resource_t *resource, coap_payload_t *payload){
|
||||
assert(payload);
|
||||
|
||||
resource->user_data = payload;
|
||||
coap_resource_set_userdata(resource, payload);
|
||||
}
|
||||
|
||||
static inline void
|
||||
coap_delete_payload(coap_resource_t *resource) {
|
||||
if (resource->user_data) {
|
||||
coap_free(resource->user_data);
|
||||
resource->user_data = NULL;
|
||||
}
|
||||
coap_free(coap_resource_get_userdata(resource));
|
||||
coap_resource_set_userdata(resource, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
coap_free_userdata(void *data) {
|
||||
coap_free(data);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
hnd_get_index(coap_context_t *ctx UNUSED_PARAM,
|
||||
coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_get_index(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
coap_pdu_t *request COAP_UNUSED,
|
||||
coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
unsigned char buf[3];
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(205);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
|
||||
|
||||
coap_add_option(response, COAP_OPTION_CONTENT_TYPE,
|
||||
coap_encode_var_safe(buf, sizeof(buf),
|
||||
@@ -123,25 +114,23 @@ hnd_get_index(coap_context_t *ctx UNUSED_PARAM,
|
||||
#endif
|
||||
|
||||
static void
|
||||
hnd_get_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_get_resource(coap_resource_t *resource,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
coap_payload_t *test_payload;
|
||||
|
||||
test_payload = coap_find_payload(resource);
|
||||
if (!test_payload) {
|
||||
response->code = COAP_RESPONSE_CODE(500);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(205);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
|
||||
|
||||
coap_add_data_blocked_response(resource, session, request, response, token,
|
||||
coap_add_data_blocked_response(request, response,
|
||||
test_payload->media_type, -1,
|
||||
test_payload->length,
|
||||
test_payload->data);
|
||||
@@ -150,12 +139,10 @@ hnd_get_resource(coap_context_t *ctx UNUSED_PARAM,
|
||||
|
||||
/* DELETE handler for dynamic resources created by POST /test */
|
||||
static void
|
||||
hnd_delete_resource(coap_context_t *ctx,
|
||||
coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_delete_resource(coap_resource_t *resource,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request COAP_UNUSED,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
coap_payload_t *payload;
|
||||
|
||||
@@ -164,25 +151,23 @@ hnd_delete_resource(coap_context_t *ctx,
|
||||
if (payload)
|
||||
coap_delete_payload(resource);
|
||||
|
||||
coap_delete_resource(ctx, resource);
|
||||
coap_delete_resource(coap_session_get_context(session), resource);
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(202);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_post_test(coap_context_t *ctx,
|
||||
coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_post_test(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *option;
|
||||
coap_payload_t *test_payload;
|
||||
size_t len;
|
||||
coap_str_const_t *uri;
|
||||
unsigned char *data;
|
||||
const uint8_t *data;
|
||||
|
||||
#define BUFSIZE 20
|
||||
int res;
|
||||
@@ -198,7 +183,7 @@ hnd_post_test(coap_context_t *ctx,
|
||||
uri = coap_new_str_const(buf, strlen((char *)buf));
|
||||
if (!(test_payload && uri)) {
|
||||
coap_log(LOG_CRIT, "cannot allocate new resource under /test");
|
||||
response->code = COAP_RESPONSE_CODE(500);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
|
||||
coap_free(test_payload);
|
||||
coap_free(uri);
|
||||
} else {
|
||||
@@ -219,7 +204,7 @@ hnd_post_test(coap_context_t *ctx,
|
||||
coap_decode_var_bytes(coap_opt_value(option), coap_opt_length(option));
|
||||
}
|
||||
|
||||
coap_add_resource(ctx, r);
|
||||
coap_add_resource(coap_session_get_context(session), r);
|
||||
coap_add_payload(r, test_payload);
|
||||
|
||||
/* add Location-Path */
|
||||
@@ -232,26 +217,24 @@ hnd_post_test(coap_context_t *ctx,
|
||||
buf += coap_opt_size(buf);
|
||||
}
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(201);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CREATED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_put_test(coap_context_t *ctx UNUSED_PARAM,
|
||||
coap_resource_t *resource,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_put_test(coap_resource_t *resource,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *option;
|
||||
coap_payload_t *payload;
|
||||
size_t len;
|
||||
unsigned char *data;
|
||||
const uint8_t *data;
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(204);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CHANGED);
|
||||
|
||||
coap_get_data(request, &len, &data);
|
||||
|
||||
@@ -289,16 +272,14 @@ hnd_put_test(coap_context_t *ctx UNUSED_PARAM,
|
||||
return;
|
||||
error:
|
||||
coap_log(LOG_WARNING, "cannot modify resource\n");
|
||||
response->code = COAP_RESPONSE_CODE(500);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_delete_test(coap_context_t *ctx UNUSED_PARAM,
|
||||
coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request UNUSED_PARAM,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_delete_test(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request COAP_UNUSED,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
/* the ETSI validation tool does not like empty resources... */
|
||||
#if 0
|
||||
@@ -309,16 +290,14 @@ hnd_delete_test(coap_context_t *ctx UNUSED_PARAM,
|
||||
payload->length = 0;
|
||||
#endif
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(202);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
|
||||
}
|
||||
|
||||
static void
|
||||
hnd_get_query(coap_context_t *ctx UNUSED_PARAM,
|
||||
coap_resource_t *resource UNUSED_PARAM,
|
||||
coap_session_t *session UNUSED_PARAM,
|
||||
coap_pdu_t *request,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
hnd_get_query(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session COAP_UNUSED,
|
||||
const coap_pdu_t *request,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_filter_t f;
|
||||
@@ -326,17 +305,17 @@ hnd_get_query(coap_context_t *ctx UNUSED_PARAM,
|
||||
size_t len, L;
|
||||
unsigned char buf[70];
|
||||
|
||||
response->code = COAP_RESPONSE_CODE(205);
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
|
||||
|
||||
coap_add_option(response, COAP_OPTION_CONTENT_TYPE,
|
||||
coap_encode_var_safe(buf, sizeof(buf),
|
||||
COAP_MEDIATYPE_TEXT_PLAIN),
|
||||
buf);
|
||||
|
||||
coap_option_filter_clear(f);
|
||||
coap_option_setb(f, COAP_OPTION_URI_QUERY);
|
||||
coap_option_filter_clear(&f);
|
||||
coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
|
||||
|
||||
coap_option_iterator_init(request, &opt_iter, f);
|
||||
coap_option_iterator_init(request, &opt_iter, &f);
|
||||
|
||||
len = 0;
|
||||
while ((len < sizeof(buf)) && (q = coap_option_next(&opt_iter))) {
|
||||
@@ -357,89 +336,65 @@ hnd_get_query(coap_context_t *ctx UNUSED_PARAM,
|
||||
|
||||
/* handler for TD_COAP_CORE_16 */
|
||||
static void
|
||||
hnd_get_separate(coap_context_t *ctx,
|
||||
coap_resource_t *resource UNUSED_PARAM,
|
||||
hnd_get_separate(coap_resource_t *resource COAP_UNUSED,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
coap_binary_t *token UNUSED_PARAM,
|
||||
coap_string_t *query UNUSED_PARAM,
|
||||
const coap_pdu_t *request,
|
||||
const coap_string_t *query COAP_UNUSED,
|
||||
coap_pdu_t *response) {
|
||||
coap_opt_iterator_t opt_iter;
|
||||
coap_opt_t *option;
|
||||
coap_opt_filter_t f;
|
||||
unsigned long delay = 5;
|
||||
|
||||
if (async) {
|
||||
if (async->id != request->tid) {
|
||||
coap_option_filter_clear(f);
|
||||
response->code = COAP_RESPONSE_CODE(503);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (request) {
|
||||
coap_async_t *async;
|
||||
coap_bin_const_t token = coap_pdu_get_token(request);
|
||||
|
||||
/* search for option delay in query list */
|
||||
coap_option_filter_clear(f);
|
||||
coap_option_setb(f, COAP_OPTION_URI_QUERY);
|
||||
async = coap_find_async(session, token);
|
||||
|
||||
coap_option_iterator_init(request, &opt_iter, f);
|
||||
if (!async) {
|
||||
/* Set up an async request to trigger delay in the future */
|
||||
|
||||
while ((option = coap_option_next(&opt_iter))) {
|
||||
if (strncmp("delay=", (const char *)coap_opt_value(option), 6) == 0) {
|
||||
int i;
|
||||
unsigned long d = 0;
|
||||
/* search for option delay in query list */
|
||||
coap_option_filter_clear(&f);
|
||||
coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
|
||||
|
||||
for (i = 6; i < coap_opt_length(option); ++i)
|
||||
d = d * 10 + coap_opt_value(option)[i] - '0';
|
||||
coap_option_iterator_init(request, &opt_iter, &f);
|
||||
|
||||
/* don't allow delay to be less than COAP_RESOURCE_CHECK_TIME*/
|
||||
delay = d < COAP_RESOURCE_CHECK_TIME_SEC
|
||||
? COAP_RESOURCE_CHECK_TIME_SEC
|
||||
: d;
|
||||
coap_log(LOG_DEBUG, "set delay to %lu\n", delay);
|
||||
break;
|
||||
while ((option = coap_option_next(&opt_iter))) {
|
||||
if (strncmp("delay=", (const char *)coap_opt_value(option), 6) == 0) {
|
||||
unsigned int i;
|
||||
unsigned long d = 0;
|
||||
|
||||
for (i = 6; i < coap_opt_length(option); ++i)
|
||||
d = d * 10 + coap_opt_value(option)[i] - '0';
|
||||
|
||||
/* don't allow delay to be less than COAP_RESOURCE_CHECK_TIME*/
|
||||
delay = d < COAP_RESOURCE_CHECK_TIME_SEC
|
||||
? COAP_RESOURCE_CHECK_TIME_SEC
|
||||
: d;
|
||||
coap_log(LOG_DEBUG, "set delay to %lu\n", delay);
|
||||
break;
|
||||
}
|
||||
}
|
||||
async = coap_register_async(session,
|
||||
request,
|
||||
COAP_TICKS_PER_SECOND * delay);
|
||||
if (async == NULL) {
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE);
|
||||
return;
|
||||
}
|
||||
/* Not setting response code will cause empty ACK to be sent
|
||||
if Confirmable */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async = coap_register_async(ctx, session, request, COAP_ASYNC_SEPARATE,
|
||||
(void *)(COAP_TICKS_PER_SECOND * delay));
|
||||
}
|
||||
|
||||
static void
|
||||
check_async(coap_context_t *ctx,
|
||||
coap_tick_t now) {
|
||||
coap_pdu_t *response;
|
||||
coap_async_state_t *tmp;
|
||||
|
||||
size_t size = 8;
|
||||
|
||||
if (!async || now < async->created + (unsigned long)async->appdata)
|
||||
return;
|
||||
|
||||
response = coap_pdu_init(async->flags & COAP_ASYNC_CONFIRM
|
||||
? COAP_MESSAGE_CON
|
||||
: COAP_MESSAGE_NON,
|
||||
COAP_RESPONSE_CODE(205), 0, size);
|
||||
if (!response) {
|
||||
coap_log(LOG_DEBUG, "check_async: insufficient memory, we'll try later\n");
|
||||
async->appdata =
|
||||
(void *)((unsigned long)async->appdata + 15 * COAP_TICKS_PER_SECOND);
|
||||
return;
|
||||
}
|
||||
|
||||
response->tid = coap_new_message_id(async->session);
|
||||
|
||||
if (async->tokenlen)
|
||||
coap_add_token(response, async->tokenlen, async->token);
|
||||
|
||||
/* no request (observe) or async set up, so this is the delayed request */
|
||||
coap_add_data(response, 4, (const uint8_t *)"done");
|
||||
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
|
||||
|
||||
if (coap_send(async->session, response) == COAP_INVALID_TID) {
|
||||
coap_log(LOG_DEBUG, "check_async: cannot send response for message %d\n",
|
||||
response->tid);
|
||||
}
|
||||
coap_remove_async(ctx, async->session, async->id, &tmp);
|
||||
coap_free_async(async);
|
||||
async = NULL;
|
||||
/* async is automatically removed by libcoap */
|
||||
}
|
||||
|
||||
static coap_payload_t *
|
||||
@@ -502,6 +457,7 @@ init_resources(coap_context_t *ctx) {
|
||||
coap_add_attr(r, coap_make_str_const("obs"), NULL, 0);
|
||||
#endif
|
||||
coap_add_resource(ctx, r);
|
||||
coap_resource_release_userdata_handler(ctx, coap_free_userdata);
|
||||
coap_add_payload(r, test_payload);
|
||||
}
|
||||
|
||||
@@ -596,7 +552,7 @@ get_context(const char *node, const char *port) {
|
||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||
coap_address_t addr;
|
||||
|
||||
if (rp->ai_addrlen <= sizeof(addr.addr)) {
|
||||
if (rp->ai_addrlen <= (socklen_t)sizeof(addr.addr)) {
|
||||
coap_address_init(&addr);
|
||||
addr.size = rp->ai_addrlen;
|
||||
memcpy(&addr.addr, rp->ai_addr, rp->ai_addrlen);
|
||||
@@ -620,7 +576,6 @@ int
|
||||
main(int argc, char **argv) {
|
||||
coap_context_t *ctx;
|
||||
int result;
|
||||
coap_tick_t now;
|
||||
char addr_str[NI_MAXHOST] = "::";
|
||||
char port_str[NI_MAXSERV] = "5683";
|
||||
int opt;
|
||||
@@ -652,8 +607,6 @@ main(int argc, char **argv) {
|
||||
if (!ctx)
|
||||
return -1;
|
||||
|
||||
coap_register_option(ctx, COAP_OPTION_BLOCK2);
|
||||
|
||||
init_resources(ctx);
|
||||
|
||||
memset (&sa, 0, sizeof(sa));
|
||||
@@ -667,18 +620,12 @@ main(int argc, char **argv) {
|
||||
sigaction (SIGPIPE, &sa, NULL);
|
||||
|
||||
while ( !quit ) {
|
||||
result = coap_run_once( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
|
||||
result = coap_io_process( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
|
||||
if ( result >= 0 ) {
|
||||
/* coap_check_resource_list( ctx ); */
|
||||
}
|
||||
/* check if we have to send asynchronous responses */
|
||||
coap_ticks(&now);
|
||||
check_async(ctx, now);
|
||||
}
|
||||
|
||||
RESOURCES_ITER(ctx->resources, r) {
|
||||
coap_delete_payload(r);
|
||||
}
|
||||
coap_free_context( ctx );
|
||||
coap_cleanup();
|
||||
|
||||
|
||||
+12
-9
@@ -1,4 +1,9 @@
|
||||
top_srcdir = ../..
|
||||
include_dir = $(top_srcdir)/include
|
||||
|
||||
LIBCOAP_API_VERSION = $(shell sed -ne 's/^LIBCOAP_API_VERSION=\([0-9]\+\).*$$/\1/p' $(top_srcdir)/configure.ac)
|
||||
|
||||
coap_include_dir = $(include_dir)/coap$(LIBCOAP_API_VERSION)
|
||||
|
||||
WITH_LWIP_BRANCH=STABLE-2_0_3_RELEASE
|
||||
WITH_LWIP_CONTRIB_BRANCH=STABLE-2_0_1_RELEASE
|
||||
@@ -35,30 +40,28 @@ LWIPOBJS += mld6.o ip6.o icmp6.o ethip6.o nd6.o ip6_addr.o ip6_frag.o
|
||||
|
||||
CFLAGS += -std=gnu99
|
||||
|
||||
CFLAGS += -I$(top_srcdir)/include/coap2
|
||||
# set path to coap_include_dir for lwippools.h
|
||||
CFLAGS += -I$(top_srcdir)/include -I$(coap_include_dir)
|
||||
|
||||
vpath %.c $(top_srcdir)/src
|
||||
|
||||
COAPOBJS = net.o coap_debug.o option.o resource.o pdu.o encode.o subscribe.o coap_io_lwip.o block.o uri.o str.o coap_session.o coap_notls.o coap_hashkey.o address.o
|
||||
COAPOBJS = net.o coap_cache.o coap_debug.o option.o resource.o pdu.o encode.o subscribe.o coap_io_lwip.o block.o uri.o str.o coap_session.o coap_notls.o coap_hashkey.o address.o coap_tcp.o async.o
|
||||
|
||||
CFLAGS += -g3 -Wall -Wextra -pedantic -O0 -fpack-struct
|
||||
CFLAGS += -g3 -Wall -Wextra -pedantic -O0
|
||||
# not sorted out yet
|
||||
CFLAGS += -Wno-unused-parameter
|
||||
|
||||
CFLAGS += -Ilwip/src/include/ -Ilwip/src/include/ipv4/ -Ilwip-contrib/ports/unix/port/include/ -Ilwip-contrib/ports/unix/proj/minimal/
|
||||
|
||||
# making an executable out of all of it
|
||||
|
||||
OBJS = server.o server-coap.o ${LWIPOBJS} ${COAPOBJS}
|
||||
|
||||
../../include/coap2/coap.h:
|
||||
@echo "Error: coap.h not present. Run the autotools chain (\`./autogen.sh && ./configure\`) in the project root directory to build the required coap.h file."
|
||||
$(coap_include_dir)/coap.h:
|
||||
@echo "Error: $@ not present. Run the autotools chain (\`./autogen.sh && ./configure\`) in the project root directory to build the required coap.h file."
|
||||
@exit 1
|
||||
|
||||
${OBJS}: lwip lwip-contrib ../../include/coap2/coap.h
|
||||
${OBJS}: lwip lwip-contrib $(coap_include_dir)/coap.h
|
||||
|
||||
server: ${OBJS}
|
||||
# $(CC) ${OBJS} -o server -lrt
|
||||
|
||||
clean:
|
||||
rm -f ${OBJS}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../coap_config.h.lwip
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* coap_config.h.lwip -- LwIP configuration for libcoap
|
||||
*
|
||||
* Copyright (C) 2021 Olaf Bergmann <bergmann@tzi.org> and others
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_CONFIG_H_
|
||||
#define COAP_CONFIG_H_
|
||||
|
||||
#include <lwip/opt.h>
|
||||
#include <lwip/debug.h>
|
||||
#include <lwip/def.h> /* provide ntohs, htons */
|
||||
|
||||
#define WITH_LWIP 1
|
||||
|
||||
#ifndef COAP_CONSTRAINED_STACK
|
||||
#define COAP_CONSTRAINED_STACK 1
|
||||
#endif
|
||||
|
||||
#ifndef COAP_DISABLE_TCP
|
||||
#define COAP_DISABLE_TCP 1
|
||||
#endif
|
||||
|
||||
#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)
|
||||
|
||||
/* 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
|
||||
|
||||
#endif /* COAP_CONFIG_H_ */
|
||||
@@ -1,3 +1,15 @@
|
||||
/*
|
||||
* lwipopts.h -- LwIP example
|
||||
*
|
||||
* Copyright (C) 2013-2016 Christian Amsüss <chrysn@fsfe.org>
|
||||
* Copyright (C) 2018 John Shallow <supjps-libcoap@jpshallow.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
typedef unsigned int sys_prot_t;
|
||||
|
||||
#define NO_SYS 1
|
||||
|
||||
+15
-12
@@ -1,5 +1,17 @@
|
||||
/*
|
||||
* server-coap.h -- LwIP example
|
||||
*
|
||||
* Copyright (C) 2013-2016 Christian Amsüss <chrysn@fsfe.org>
|
||||
* Copyright (C) 2018-2021 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
*
|
||||
* 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 <coap.h>
|
||||
#include <coap3/coap.h>
|
||||
|
||||
coap_context_t *main_coap_context;
|
||||
|
||||
@@ -13,10 +25,8 @@ static coap_resource_t *time_resource = NULL; /* just for testing */
|
||||
#endif
|
||||
|
||||
void
|
||||
hnd_get_time(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request, coap_binary_t *token,
|
||||
coap_string_t *query,
|
||||
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;
|
||||
@@ -30,13 +40,6 @@ hnd_get_time(coap_context_t *ctx, struct coap_resource_t *resource,
|
||||
response->code =
|
||||
my_clock_base ? COAP_RESPONSE_CODE(205) : COAP_RESPONSE_CODE(404);
|
||||
|
||||
if (coap_find_observer(resource, session, token)) {
|
||||
coap_add_option(response, COAP_OPTION_OBSERVE,
|
||||
coap_encode_var_safe(buf, sizeof(buf),
|
||||
resource->observe),
|
||||
buf);
|
||||
}
|
||||
|
||||
if (my_clock_base)
|
||||
coap_add_option(response, COAP_OPTION_CONTENT_FORMAT,
|
||||
coap_encode_var_safe(buf, sizeof(buf),
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
/*
|
||||
* server-coap.h -- LwIP example
|
||||
*
|
||||
* Copyright (C) 2013-2016 Christian Amsüss <chrysn@fsfe.org>
|
||||
*
|
||||
* 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 <coap.h>
|
||||
#include <coap3/coap.h>
|
||||
|
||||
void server_coap_init(void);
|
||||
/* call this when you think that resources could be dirty */
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Makefile for libcoap standalone examples
|
||||
#
|
||||
# Copyright (C) 2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
#
|
||||
# This file is part of the CoAP C library libcoap. Please see README and
|
||||
# COPYING for terms of use.
|
||||
|
||||
# Set external variable LIBCOAP if you need a specific libcoap library.
|
||||
# E.g. libcoap-3-openssl, libcoap-3-gnutls, libcoap-3-mbedtls or libcoap-3-notls
|
||||
#
|
||||
LIBCOAP?=libcoap-3
|
||||
|
||||
WARNING_CFLAGS= \
|
||||
-pedantic \
|
||||
-Wall \
|
||||
-Wcast-qual \
|
||||
-Wextra \
|
||||
-Wformat-security \
|
||||
-Winline \
|
||||
-Wmissing-declarations \
|
||||
-Wmissing-prototypes \
|
||||
-Wnested-externs \
|
||||
-Wpointer-arith \
|
||||
-Wshadow \
|
||||
-Wstrict-prototypes \
|
||||
-Wswitch-default \
|
||||
-Wswitch-enum \
|
||||
-Wunused \
|
||||
-Wwrite-strings
|
||||
|
||||
pkgconfig=$(shell pkg-config $(1) $(2))
|
||||
|
||||
CPPFLAGS=-D_GNU_SOURCE $(WARNING_CFLAGS) $(call pkgconfig,--cflags,$(LIBCOAP))
|
||||
CFLAGS=-std=c99
|
||||
LDLIBS=$(call pkgconfig,--libs-only-l,$(LIBCOAP))
|
||||
libdirs=$(call pkgconfig,--libs-only-L,$(LIBCOAP))
|
||||
rpath=$(shell echo "$(libdirs)" | sed -e 's/^-L/-Wl,--rpath /')
|
||||
LDFLAGS=$(libdirs) $(rpath)
|
||||
|
||||
all: coap-client coap-server
|
||||
|
||||
clean:
|
||||
rm -f *.o coap-client coap-server
|
||||
@@ -0,0 +1,9 @@
|
||||
This directory contains some example libcoap code for a client or server which
|
||||
can easily be modified as per your requirements.
|
||||
|
||||
The provided code is the same as used to build the installed binaries
|
||||
coap-client and coap-server.
|
||||
|
||||
Simply 'cd' into this directory and then run 'make' to build the executables.
|
||||
|
||||
|
||||
+35
-20
@@ -2,6 +2,8 @@
|
||||
*
|
||||
* Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
*/
|
||||
@@ -19,20 +21,33 @@
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "coap.h"
|
||||
#include <coap3/coap.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED_PARAM __attribute__ ((unused))
|
||||
#else /* not a GCC */
|
||||
#define UNUSED_PARAM
|
||||
#endif /* GCC */
|
||||
#define Nn 8 /* duplicate definition of N if built on sky motes */
|
||||
#define ENCODE_HEADER_SIZE 4
|
||||
#define HIBIT (1 << (Nn - 1))
|
||||
#define EMASK ((1 << ENCODE_HEADER_SIZE) - 1)
|
||||
#define MMASK ((1 << Nn) - 1 - EMASK)
|
||||
#define MAX_VALUE ( (1 << Nn) - (1 << ENCODE_HEADER_SIZE) ) * (1 << ((1 << ENCODE_HEADER_SIZE) - 1))
|
||||
|
||||
static coap_tid_t id;
|
||||
#define COAP_PSEUDOFP_DECODE_8_4(r) (r < HIBIT ? r : (r & MMASK) << (r & EMASK))
|
||||
|
||||
/* ls and s must be integer variables */
|
||||
/* #define COAP_PSEUDOFP_ENCODE_8_4_DOWN(v,ls) (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (v >> ls) & MMASK) + ls) */
|
||||
COAP_STATIC_INLINE unsigned char
|
||||
COAP_PSEUDOFP_ENCODE_8_4_DOWN(unsigned int v, int *ls) {
|
||||
if (v < HIBIT) return v;
|
||||
*ls = coap_fls(v) - Nn;
|
||||
return ((v >> *ls) & MMASK) + *ls;
|
||||
}
|
||||
#define COAP_PSEUDOFP_ENCODE_8_4_UP(v,ls,s) (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (s = (((v + ((1<<ENCODE_HEADER_SIZE<<ls)-1)) >> ls) & MMASK)), s == 0 ? HIBIT + ls + 1 : s + ls))
|
||||
|
||||
static coap_mid_t id;
|
||||
static int quit = 0;
|
||||
|
||||
/* SIGINT handler: set quit to 1 for graceful termination */
|
||||
static void
|
||||
handle_sigint(int signum UNUSED_PARAM) {
|
||||
handle_sigint(int signum COAP_UNUSED) {
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
@@ -43,14 +58,11 @@ make_pdu( unsigned int value ) {
|
||||
static unsigned char buf[20];
|
||||
int len, ls;
|
||||
|
||||
if (!(pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU)))
|
||||
if (!(pdu = coap_pdu_init(COAP_MESSAGE_NON, COAP_REQUEST_CODE_POST, id++,
|
||||
COAP_DEFAULT_MTU)))
|
||||
return NULL;
|
||||
|
||||
pdu->type = COAP_MESSAGE_NON;
|
||||
pdu->code = COAP_REQUEST_POST;
|
||||
pdu->tid = id++;
|
||||
|
||||
enc = COAP_PSEUDOFP_ENCODE_8_4_DOWN(value,ls);
|
||||
enc = COAP_PSEUDOFP_ENCODE_8_4_DOWN(value, &ls);
|
||||
|
||||
len = sprintf((char *)buf, "%c%u", enc, COAP_PSEUDOFP_DECODE_8_4(enc));
|
||||
coap_add_data( pdu, len, buf );
|
||||
@@ -74,8 +86,7 @@ usage( const char *program ) {
|
||||
}
|
||||
|
||||
static coap_session_t *
|
||||
get_session(const char *group) {
|
||||
coap_context_t *ctx = coap_new_context(NULL);
|
||||
get_session(coap_context_t *ctx, const char *group) {
|
||||
int s;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *result, *rp;
|
||||
@@ -109,8 +120,7 @@ get_session(const char *group) {
|
||||
|
||||
if (IN6_IS_ADDR_MULTICAST(&addr.addr.sin6.sin6_addr) ) {
|
||||
/* set socket options for multicast */
|
||||
if ( setsockopt(session->sock.fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
|
||||
(char *)&hops, sizeof(hops) ) < 0 )
|
||||
if (!coap_mcast_set_hops(session, hops))
|
||||
perror("setsockopt: IPV6_MULTICAST_HOPS");
|
||||
|
||||
}
|
||||
@@ -129,13 +139,18 @@ main(int argc, char **argv) {
|
||||
coap_pdu_t *pdu;
|
||||
coap_session_t *session;
|
||||
struct sigaction sa;
|
||||
coap_context_t *ctx;
|
||||
|
||||
if ( argc > 1 && strncmp(argv[1], "-h", 2) == 0 ) {
|
||||
usage( argv[0] );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
session = get_session(argc > 1 ? argv[1] : "::1");
|
||||
ctx = coap_new_context(NULL);
|
||||
if (!ctx)
|
||||
return -1;
|
||||
|
||||
session = get_session(ctx, argc > 1 ? argv[1] : "::1");
|
||||
|
||||
if ( !session )
|
||||
return -1;
|
||||
@@ -165,7 +180,7 @@ main(int argc, char **argv) {
|
||||
|
||||
}
|
||||
|
||||
coap_free_context( session->context );
|
||||
coap_free_context(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
* async.h -- state management for asynchronous messages
|
||||
*
|
||||
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file async.h
|
||||
* @brief State management for asynchronous messages
|
||||
*/
|
||||
|
||||
#ifndef COAP_ASYNC_H_
|
||||
#define COAP_ASYNC_H_
|
||||
|
||||
#include "net.h"
|
||||
|
||||
#ifndef WITHOUT_ASYNC
|
||||
|
||||
/**
|
||||
* @defgroup coap_async Asynchronous Messaging
|
||||
* @{
|
||||
* Structure for managing asynchronous state of CoAP resources. A
|
||||
* coap_resource_t object holds a list of coap_async_state_t objects that can be
|
||||
* used to generate a separate response in case a result of an operation cannot
|
||||
* be delivered in time, or the resource has been explicitly subscribed to with
|
||||
* the option @c observe.
|
||||
*/
|
||||
typedef struct coap_async_state_t {
|
||||
unsigned char flags; /**< holds the flags to control behaviour */
|
||||
|
||||
/**
|
||||
* Holds the internal time when the object was registered with a
|
||||
* resource. This field will be updated whenever
|
||||
* coap_register_async() is called for a specific resource.
|
||||
*/
|
||||
coap_tick_t created;
|
||||
|
||||
/**
|
||||
* This field can be used to register opaque application data with the
|
||||
* asynchronous state object.
|
||||
*/
|
||||
void *appdata;
|
||||
coap_session_t *session; /**< transaction session */
|
||||
coap_tid_t id; /**< transaction id */
|
||||
struct coap_async_state_t *next; /**< internally used for linking */
|
||||
size_t tokenlen; /**< length of the token */
|
||||
uint8_t token[8]; /**< the token to use in a response */
|
||||
} coap_async_state_t;
|
||||
|
||||
/* Definitions for Async Status Flags These flags can be used to control the
|
||||
* behaviour of asynchronous response generation.
|
||||
*/
|
||||
#define COAP_ASYNC_CONFIRM 0x01 /**< send confirmable response */
|
||||
#define COAP_ASYNC_SEPARATE 0x02 /**< send separate response */
|
||||
#define COAP_ASYNC_OBSERVED 0x04 /**< the resource is being observed */
|
||||
|
||||
/** release application data on destruction */
|
||||
#define COAP_ASYNC_RELEASE_DATA 0x08
|
||||
|
||||
/**
|
||||
* Allocates a new coap_async_state_t object and fills its fields according to
|
||||
* the given @p request. The @p flags are used to control generation of empty
|
||||
* ACK responses to stop retransmissions and to release registered @p data when
|
||||
* the resource is deleted by coap_free_async(). This function returns a pointer
|
||||
* to the registered coap_async_t object or @c NULL on error. Note that this
|
||||
* function will return @c NULL in case that an object with the same identifier
|
||||
* is already registered.
|
||||
*
|
||||
* @param context The context to use.
|
||||
* @param session The session that is used for asynchronous transmissions.
|
||||
* @param request The request that is handled asynchronously.
|
||||
* @param flags Flags to control state management.
|
||||
* @param data Opaque application data to register. Note that the
|
||||
* storage occupied by @p data is released on destruction
|
||||
* only if flag COAP_ASYNC_RELEASE_DATA is set.
|
||||
*
|
||||
* @return A pointer to the registered coap_async_state_t object or @c
|
||||
* NULL in case of an error.
|
||||
*/
|
||||
coap_async_state_t *
|
||||
coap_register_async(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
unsigned char flags,
|
||||
void *data);
|
||||
|
||||
/**
|
||||
* Removes the state object identified by @p id from @p context. The removed
|
||||
* object is returned in @p s, if found. Otherwise, @p s is undefined. This
|
||||
* function returns @c 1 if the object was removed, @c 0 otherwise. Note that
|
||||
* the storage allocated for the stored object is not released by this
|
||||
* functions. You will have to call coap_free_async() to do so.
|
||||
*
|
||||
* @param context The context where the async object is registered.
|
||||
* @param session The session that is used for asynchronous transmissions.
|
||||
* @param id The identifier of the asynchronous transaction.
|
||||
* @param s Will be set to the object identified by @p id after removal.
|
||||
*
|
||||
* @return @c 1 if object was removed and @p s updated, or @c 0 if no
|
||||
* object was found with the given id. @p s is valid only if the
|
||||
* return value is @c 1.
|
||||
*/
|
||||
int coap_remove_async(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_tid_t id,
|
||||
coap_async_state_t **s);
|
||||
|
||||
/**
|
||||
* Releases the memory that was allocated by coap_async_state_init() for the
|
||||
* object @p s. The registered application data will be released automatically
|
||||
* if COAP_ASYNC_RELEASE_DATA is set.
|
||||
*
|
||||
* @param state The object to delete.
|
||||
*/
|
||||
void
|
||||
coap_free_async(coap_async_state_t *state);
|
||||
|
||||
/**
|
||||
* Retrieves the object identified by @p id from the list of asynchronous
|
||||
* transactions that are registered with @p context. This function returns a
|
||||
* pointer to that object or @c NULL if not found.
|
||||
*
|
||||
* @param context The context where the asynchronous objects are registered
|
||||
* with.
|
||||
* @param session The session that is used for asynchronous transmissions.
|
||||
* @param id The id of the object to retrieve.
|
||||
*
|
||||
* @return A pointer to the object identified by @p id or @c NULL if
|
||||
* not found.
|
||||
*/
|
||||
coap_async_state_t *coap_find_async(coap_context_t *context, coap_session_t *session, coap_tid_t id);
|
||||
|
||||
/**
|
||||
* Updates the time stamp of @p s.
|
||||
*
|
||||
* @param s The state object to update.
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_touch_async(coap_async_state_t *s) { coap_ticks(&s->created); }
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* WITHOUT_ASYNC */
|
||||
|
||||
#endif /* COAP_ASYNC_H_ */
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* bits.h -- bit vector manipulation
|
||||
*
|
||||
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bits.h
|
||||
* @brief Bit vector manipulation
|
||||
*/
|
||||
|
||||
#ifndef COAP_BITS_H_
|
||||
#define COAP_BITS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Sets the bit @p bit in bit-vector @p vec. This function returns @c 1 if bit
|
||||
* was set or @c -1 on error (i.e. when the given bit does not fit in the
|
||||
* vector).
|
||||
*
|
||||
* @param vec The bit-vector to change.
|
||||
* @param size The size of @p vec in bytes.
|
||||
* @param bit The bit to set in @p vec.
|
||||
*
|
||||
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
bits_setb(uint8_t *vec, size_t size, uint8_t bit) {
|
||||
if (size <= ((size_t)bit >> 3))
|
||||
return -1;
|
||||
|
||||
*(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the bit @p bit from bit-vector @p vec. This function returns @c 1 if
|
||||
* bit was cleared or @c -1 on error (i.e. when the given bit does not fit in
|
||||
* the vector).
|
||||
*
|
||||
* @param vec The bit-vector to change.
|
||||
* @param size The size of @p vec in bytes.
|
||||
* @param bit The bit to clear from @p vec.
|
||||
*
|
||||
* @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise.
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
bits_clrb(uint8_t *vec, size_t size, uint8_t bit) {
|
||||
if (size <= ((size_t)bit >> 3))
|
||||
return -1;
|
||||
|
||||
*(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status of bit @p bit from bit-vector @p vec. This function returns
|
||||
* @c 1 if the bit is set, @c 0 otherwise (even in case of an error).
|
||||
*
|
||||
* @param vec The bit-vector to read from.
|
||||
* @param size The size of @p vec in bytes.
|
||||
* @param bit The bit to get from @p vec.
|
||||
*
|
||||
* @return @c 1 if the bit is set, @c 0 otherwise.
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
bits_getb(const uint8_t *vec, size_t size, uint8_t bit) {
|
||||
if (size <= ((size_t)bit >> 3))
|
||||
return -1;
|
||||
|
||||
return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0;
|
||||
}
|
||||
|
||||
#endif /* COAP_BITS_H_ */
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* block.h -- block transfer
|
||||
*
|
||||
* Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_BLOCK_H_
|
||||
#define COAP_BLOCK_H_
|
||||
|
||||
#include "encode.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
|
||||
struct coap_resource_t;
|
||||
struct coap_session_t;
|
||||
|
||||
/**
|
||||
* @defgroup block Block Transfer
|
||||
* API functions for handling PDUs using CoAP BLOCK options
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef COAP_MAX_BLOCK_SZX
|
||||
/**
|
||||
* The largest value for the SZX component in a Block option.
|
||||
*/
|
||||
#define COAP_MAX_BLOCK_SZX 6
|
||||
#endif /* COAP_MAX_BLOCK_SZX */
|
||||
|
||||
/**
|
||||
* Structure of Block options.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int num; /**< block number */
|
||||
unsigned int m:1; /**< 1 if more blocks follow, 0 otherwise */
|
||||
unsigned int szx:3; /**< block size */
|
||||
} coap_block_t;
|
||||
|
||||
/**
|
||||
* Returns the value of the least significant byte of a Block option @p opt.
|
||||
* For zero-length options (i.e. num == m == szx == 0), COAP_OPT_BLOCK_LAST
|
||||
* returns @c NULL.
|
||||
*/
|
||||
#define COAP_OPT_BLOCK_LAST(opt) \
|
||||
(coap_opt_length(opt) ? (coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
|
||||
|
||||
/** Returns the value of the More-bit of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_MORE(opt) \
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
|
||||
|
||||
/** Returns the value of the SZX-field of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_SZX(opt) \
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
|
||||
|
||||
/**
|
||||
* Returns the value of field @c num in the given block option @p block_opt.
|
||||
*/
|
||||
unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
|
||||
|
||||
/**
|
||||
* Checks if more than @p num blocks are required to deliver @p data_len
|
||||
* bytes of data for a block size of 1 << (@p szx + 4).
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
coap_more_blocks(size_t data_len, unsigned int num, uint16_t szx) {
|
||||
return ((num+1) << (szx + 4)) < data_len;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/** Sets the More-bit in @p block_opt */
|
||||
COAP_STATIC_INLINE void
|
||||
coap_opt_block_set_m(coap_opt_t *block_opt, int m) {
|
||||
if (m)
|
||||
*(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) |= 0x08;
|
||||
else
|
||||
*(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) &= ~0x08;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initializes @p block from @p pdu. @p type must be either COAP_OPTION_BLOCK1
|
||||
* or COAP_OPTION_BLOCK2. When option @p type was found in @p pdu, @p block is
|
||||
* initialized with values from this option and the function returns the value
|
||||
* @c 1. Otherwise, @c 0 is returned.
|
||||
*
|
||||
* @param pdu The pdu to search for option @p type.
|
||||
* @param type The option to search for (must be COAP_OPTION_BLOCK1 or
|
||||
* COAP_OPTION_BLOCK2).
|
||||
* @param block The block structure to initilize.
|
||||
*
|
||||
* @return @c 1 on success, @c 0 otherwise.
|
||||
*/
|
||||
int coap_get_block(coap_pdu_t *pdu, uint16_t type, coap_block_t *block);
|
||||
|
||||
/**
|
||||
* Writes a block option of type @p type to message @p pdu. If the requested
|
||||
* block size is too large to fit in @p pdu, it is reduced accordingly. An
|
||||
* exception is made for the final block when less space is required. The actual
|
||||
* length of the resource is specified in @p data_length.
|
||||
*
|
||||
* This function may change *block to reflect the values written to @p pdu. As
|
||||
* the function takes into consideration the remaining space @p pdu, no more
|
||||
* options should be added after coap_write_block_opt() has returned.
|
||||
*
|
||||
* @param block The block structure to use. On return, this object is
|
||||
* updated according to the values that have been written to
|
||||
* @p pdu.
|
||||
* @param type COAP_OPTION_BLOCK1 or COAP_OPTION_BLOCK2.
|
||||
* @param pdu The message where the block option should be written.
|
||||
* @param data_length The length of the actual data that will be added the @p
|
||||
* pdu by calling coap_add_block().
|
||||
*
|
||||
* @return @c 1 on success, or a negative value on error.
|
||||
*/
|
||||
int coap_write_block_opt(coap_block_t *block,
|
||||
uint16_t type,
|
||||
coap_pdu_t *pdu,
|
||||
size_t data_length);
|
||||
|
||||
/**
|
||||
* Adds the @p block_num block of size 1 << (@p block_szx + 4) from source @p
|
||||
* data to @p pdu.
|
||||
*
|
||||
* @param pdu The message to add the block.
|
||||
* @param len The length of @p data.
|
||||
* @param data The source data to fill the block with.
|
||||
* @param block_num The actual block number.
|
||||
* @param block_szx Encoded size of block @p block_number.
|
||||
*
|
||||
* @return @c 1 on success, @c 0 otherwise.
|
||||
*/
|
||||
int coap_add_block(coap_pdu_t *pdu,
|
||||
unsigned int len,
|
||||
const uint8_t *data,
|
||||
unsigned int block_num,
|
||||
unsigned char block_szx);
|
||||
|
||||
/**
|
||||
* Adds the appropriate part of @p data to the @p response pdu. If blocks are
|
||||
* required, then the appropriate block will be added to the PDU and sent.
|
||||
* Adds a ETAG option that is the hash of the entire data if the data is to be
|
||||
* split into blocks
|
||||
* Used by a GET request handler.
|
||||
*
|
||||
* @param resource The resource the data is associated with.
|
||||
* @param session The coap session.
|
||||
* @param request The requesting pdu.
|
||||
* @param response The response pdu.
|
||||
* @param token The token taken from the (original) requesting pdu.
|
||||
* @param media_type The format of the data.
|
||||
* @param maxage The maxmimum life of the data. If @c -1, then there
|
||||
* is no maxage.
|
||||
* @param length The total length of the data.
|
||||
* @param data The entire data block to transmit.
|
||||
*
|
||||
*/
|
||||
void
|
||||
coap_add_data_blocked_response(struct coap_resource_t *resource,
|
||||
struct coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
coap_pdu_t *response,
|
||||
const coap_binary_t *token,
|
||||
uint16_t media_type,
|
||||
int maxage,
|
||||
size_t length,
|
||||
const uint8_t* data);
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif /* COAP_BLOCK_H_ */
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* coap.h -- main header file for CoAP stack of libcoap
|
||||
*
|
||||
* Copyright (C) 2010-2012,2015-2017 Olaf Bergmann <bergmann@tzi.org>
|
||||
* 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
*
|
||||
* 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.2.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.2.1"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "libcoap.h"
|
||||
|
||||
#include "coap_forward_decls.h"
|
||||
#include "address.h"
|
||||
#include "async.h"
|
||||
#include "bits.h"
|
||||
#include "block.h"
|
||||
#include "coap_dtls.h"
|
||||
#include "coap_event.h"
|
||||
#include "coap_io.h"
|
||||
#include "coap_time.h"
|
||||
#include "coap_debug.h"
|
||||
#include "encode.h"
|
||||
#include "mem.h"
|
||||
#include "net.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
#include "prng.h"
|
||||
#include "resource.h"
|
||||
#include "str.h"
|
||||
#include "subscribe.h"
|
||||
#include "uri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COAP_H_ */
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* coap.h -- main header file for CoAP stack of libcoap
|
||||
*
|
||||
* Copyright (C) 2010-2012,2015-2017 Olaf Bergmann <bergmann@tzi.org>
|
||||
* 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
*
|
||||
* 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@"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "libcoap.h"
|
||||
|
||||
#include "coap_forward_decls.h"
|
||||
#include "address.h"
|
||||
#include "async.h"
|
||||
#include "bits.h"
|
||||
#include "block.h"
|
||||
#include "coap_dtls.h"
|
||||
#include "coap_event.h"
|
||||
#include "coap_io.h"
|
||||
#include "coap_time.h"
|
||||
#include "coap_debug.h"
|
||||
#include "encode.h"
|
||||
#include "mem.h"
|
||||
#include "net.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
#include "prng.h"
|
||||
#include "resource.h"
|
||||
#include "str.h"
|
||||
#include "subscribe.h"
|
||||
#include "uri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COAP_H_ */
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* coap.h -- main header file for CoAP stack of libcoap
|
||||
*
|
||||
* Copyright (C) 2010-2012,2015-2017 Olaf Bergmann <bergmann@tzi.org>
|
||||
* 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
*
|
||||
* 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.2.0"
|
||||
|
||||
/* 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.2.0"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "libcoap.h"
|
||||
|
||||
#include "coap_forward_decls.h"
|
||||
#include "address.h"
|
||||
#include "async.h"
|
||||
#include "bits.h"
|
||||
#include "block.h"
|
||||
#include "coap_dtls.h"
|
||||
#include "coap_event.h"
|
||||
#include "coap_io.h"
|
||||
#include "coap_time.h"
|
||||
#include "coap_debug.h"
|
||||
#include "encode.h"
|
||||
#include "mem.h"
|
||||
#include "net.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
#include "prng.h"
|
||||
#include "resource.h"
|
||||
#include "str.h"
|
||||
#include "subscribe.h"
|
||||
#include "uri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COAP_H_ */
|
||||
@@ -1,613 +0,0 @@
|
||||
/*
|
||||
* coap_dtls.h -- (Datagram) Transport Layer Support for libcoap
|
||||
*
|
||||
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2017 Jean-Claude Michelou <jcm@spinetix.com>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_DTLS_H_
|
||||
#define COAP_DTLS_H_
|
||||
|
||||
#include "coap_time.h"
|
||||
|
||||
struct coap_context_t;
|
||||
struct coap_session_t;
|
||||
struct coap_dtls_pki_t;
|
||||
|
||||
/**
|
||||
* @defgroup dtls DTLS Support
|
||||
* API functions for interfacing with DTLS libraries.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check whether DTLS is available.
|
||||
*
|
||||
* @return @c 1 if support for DTLS is enabled, or @c 0 otherwise.
|
||||
*/
|
||||
int coap_dtls_is_supported(void);
|
||||
|
||||
/**
|
||||
* Check whether TLS is available.
|
||||
*
|
||||
* @return @c 1 if support for TLS is enabled, or @c 0 otherwise.
|
||||
*/
|
||||
int coap_tls_is_supported(void);
|
||||
|
||||
typedef enum coap_tls_library_t {
|
||||
COAP_TLS_LIBRARY_NOTLS = 0, /**< No DTLS library */
|
||||
COAP_TLS_LIBRARY_TINYDTLS, /**< Using TinyDTLS library */
|
||||
COAP_TLS_LIBRARY_OPENSSL, /**< Using OpenSSL library */
|
||||
COAP_TLS_LIBRARY_GNUTLS, /**< Using GnuTLS library */
|
||||
} coap_tls_library_t;
|
||||
|
||||
/**
|
||||
* The structure used for returning the underlying (D)TLS library
|
||||
* information.
|
||||
*/
|
||||
typedef struct coap_tls_version_t {
|
||||
uint64_t version; /**< (D)TLS runtime Library Version */
|
||||
coap_tls_library_t type; /**< Library type. One of COAP_TLS_LIBRARY_* */
|
||||
uint64_t built_version; /**< (D)TLS Built against Library Version */
|
||||
} coap_tls_version_t;
|
||||
|
||||
/**
|
||||
* Determine the type and version of the underlying (D)TLS library.
|
||||
*
|
||||
* @return The version and type of library libcoap was compiled against.
|
||||
*/
|
||||
coap_tls_version_t *coap_get_tls_library_version(void);
|
||||
|
||||
/**
|
||||
* Additional Security setup handler that can be set up by
|
||||
* coap_context_set_pki().
|
||||
* Invoked when libcoap has done the validation checks at the TLS level,
|
||||
* but the application needs to do some additional checks/changes/updates.
|
||||
*
|
||||
* @param tls_session The security session definition - e.g. SSL * for OpenSSL.
|
||||
* NULL if server call-back.
|
||||
* This will be dependent on the underlying TLS library -
|
||||
* see coap_get_tls_library_version()
|
||||
* @param setup_data A structure containing setup data originally passed into
|
||||
* coap_context_set_pki() or coap_new_client_session_pki().
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
typedef int (*coap_dtls_security_setup_t)(void* tls_session,
|
||||
struct coap_dtls_pki_t *setup_data);
|
||||
|
||||
/**
|
||||
* CN Validation call-back that can be set up by coap_context_set_pki().
|
||||
* Invoked when libcoap has done the validation checks at the TLS level,
|
||||
* but the application needs to check that the CN is allowed.
|
||||
* CN is the SubjectAltName in the cert, if not present, then the leftmost
|
||||
* Common Name (CN) component of the subject name.
|
||||
*
|
||||
* @param cn The determined CN from the certificate
|
||||
* @param asn1_public_cert The ASN.1 DER encoded X.509 certificate
|
||||
* @param asn1_length The ASN.1 length
|
||||
* @param coap_session The CoAP session associated with the certificate update
|
||||
* @param depth Depth in cert chain. If 0, then client cert, else a CA
|
||||
* @param validated TLS layer can find no issues if 1
|
||||
* @param arg The same as was passed into coap_context_set_pki()
|
||||
* in setup_data->cn_call_back_arg
|
||||
*
|
||||
* @return @c 1 if accepted, else @c 0 if to be rejected.
|
||||
*/
|
||||
typedef int (*coap_dtls_cn_callback_t)(const char *cn,
|
||||
const uint8_t *asn1_public_cert,
|
||||
size_t asn1_length,
|
||||
struct coap_session_t *coap_session,
|
||||
unsigned depth,
|
||||
int validated,
|
||||
void *arg);
|
||||
|
||||
/**
|
||||
* The enum used for determining the provided PKI ASN.1 (DER) Private Key
|
||||
* formats.
|
||||
*/
|
||||
typedef enum coap_asn1_privatekey_type_t {
|
||||
COAP_ASN1_PKEY_NONE, /**< NONE */
|
||||
COAP_ASN1_PKEY_RSA, /**< RSA type */
|
||||
COAP_ASN1_PKEY_RSA2, /**< RSA2 type */
|
||||
COAP_ASN1_PKEY_DSA, /**< DSA type */
|
||||
COAP_ASN1_PKEY_DSA1, /**< DSA1 type */
|
||||
COAP_ASN1_PKEY_DSA2, /**< DSA2 type */
|
||||
COAP_ASN1_PKEY_DSA3, /**< DSA3 type */
|
||||
COAP_ASN1_PKEY_DSA4, /**< DSA4 type */
|
||||
COAP_ASN1_PKEY_DH, /**< DH type */
|
||||
COAP_ASN1_PKEY_DHX, /**< DHX type */
|
||||
COAP_ASN1_PKEY_EC, /**< EC type */
|
||||
COAP_ASN1_PKEY_HMAC, /**< HMAC type */
|
||||
COAP_ASN1_PKEY_CMAC, /**< CMAC type */
|
||||
COAP_ASN1_PKEY_TLS1_PRF, /**< TLS1_PRF type */
|
||||
COAP_ASN1_PKEY_HKDF /**< HKDF type */
|
||||
} coap_asn1_privatekey_type_t;
|
||||
|
||||
/**
|
||||
* The enum used for determining the PKI key formats.
|
||||
*/
|
||||
typedef enum coap_pki_key_t {
|
||||
COAP_PKI_KEY_PEM = 0, /**< The PKI key type is PEM */
|
||||
COAP_PKI_KEY_ASN1, /**< The PKI key type is ASN.1 (DER) */
|
||||
} coap_pki_key_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI PEM definitions.
|
||||
*/
|
||||
typedef struct coap_pki_key_pem_t {
|
||||
const char *ca_file; /**< File location of Common CA in PEM format */
|
||||
const char *public_cert; /**< File location of Public Cert in PEM format */
|
||||
const char *private_key; /**< File location of Private Key in PEM format */
|
||||
} coap_pki_key_pem_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI ASN.1 (DER) definitions.
|
||||
*/
|
||||
typedef struct coap_pki_key_asn1_t {
|
||||
const uint8_t *ca_cert; /**< ASN1 (DER) Common CA Cert */
|
||||
const uint8_t *public_cert; /**< ASN1 (DER) Public Cert */
|
||||
const uint8_t *private_key; /**< ASN1 (DER) Private Key */
|
||||
size_t ca_cert_len; /**< ASN1 CA Cert length */
|
||||
size_t public_cert_len; /**< ASN1 Public Cert length */
|
||||
size_t private_key_len; /**< ASN1 Private Key length */
|
||||
coap_asn1_privatekey_type_t private_key_type; /**< Private Key Type */
|
||||
} coap_pki_key_asn1_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI key information.
|
||||
*/
|
||||
typedef struct coap_dtls_key_t {
|
||||
coap_pki_key_t key_type; /**< key format type */
|
||||
union {
|
||||
coap_pki_key_pem_t pem; /**< for PEM keys */
|
||||
coap_pki_key_asn1_t asn1; /**< for ASN.1 (DER) keys */
|
||||
} key;
|
||||
} coap_dtls_key_t;
|
||||
|
||||
/**
|
||||
* Server Name Indication (SNI) Validation call-back that can be set up by
|
||||
* coap_context_set_pki().
|
||||
* Invoked if the SNI is not previously seen and prior to sending a certificate
|
||||
* set back to the client so that the appropriate certificate set can be used
|
||||
* based on the requesting SNI.
|
||||
*
|
||||
* @param sni The requested SNI
|
||||
* @param arg The same as was passed into coap_context_set_pki()
|
||||
* in setup_data->sni_call_back_arg
|
||||
*
|
||||
* @return New set of certificates to use, or @c NULL if SNI is to be rejected.
|
||||
*/
|
||||
typedef coap_dtls_key_t *(*coap_dtls_sni_callback_t)(const char *sni,
|
||||
void* arg);
|
||||
|
||||
|
||||
#define COAP_DTLS_PKI_SETUP_VERSION 1 /**< Latest PKI setup version */
|
||||
|
||||
/**
|
||||
* The structure used for defining the PKI setup data to be used.
|
||||
*/
|
||||
typedef struct coap_dtls_pki_t {
|
||||
uint8_t version; /** Set to 1 to support this version of the struct */
|
||||
|
||||
/* Options to enable different TLS functionality in libcoap */
|
||||
uint8_t verify_peer_cert; /**< 1 if peer cert is to be verified */
|
||||
uint8_t require_peer_cert; /**< 1 if peer cert is required */
|
||||
uint8_t allow_self_signed; /**< 1 if self signed certs are allowed */
|
||||
uint8_t allow_expired_certs; /**< 1 if expired certs are allowed */
|
||||
uint8_t cert_chain_validation; /**< 1 if to check cert_chain_verify_depth */
|
||||
uint8_t cert_chain_verify_depth; /**< recommended depth is 3 */
|
||||
uint8_t check_cert_revocation; /**< 1 if revocation checks wanted */
|
||||
uint8_t allow_no_crl; /**< 1 ignore if CRL not there */
|
||||
uint8_t allow_expired_crl; /**< 1 if expired crl is allowed */
|
||||
uint8_t reserved[6]; /**< Reserved - must be set to 0 for
|
||||
future compatibility */
|
||||
/* Size of 6 chosen to align to next
|
||||
* parameter, so if newly defined option
|
||||
* it can use one of the reserverd slot so
|
||||
* no need to change
|
||||
* COAP_DTLS_PKI_SETUP_VERSION and just
|
||||
* decrement the reserved[] count.
|
||||
*/
|
||||
|
||||
/** CN check call-back function.
|
||||
* If not NULL, is called when the TLS connection has passed the configured
|
||||
* TLS options above for the application to verify if the CN is valid.
|
||||
*/
|
||||
coap_dtls_cn_callback_t validate_cn_call_back;
|
||||
void *cn_call_back_arg; /**< Passed in to the CN call-back function */
|
||||
|
||||
/** SNI check call-back function.
|
||||
* If not @p NULL, called if the SNI is not previously seen and prior to
|
||||
* sending a certificate set back to the client so that the appropriate
|
||||
* certificate set can be used based on the requesting SNI.
|
||||
*/
|
||||
coap_dtls_sni_callback_t validate_sni_call_back;
|
||||
void *sni_call_back_arg; /**< Passed in to the sni call-back function */
|
||||
|
||||
/** Additional Security call-back handler that is invoked when libcoap has
|
||||
* done the standerd, defined validation checks at the TLS level,
|
||||
* If not @p NULL, called from within the TLS Client Hello connection
|
||||
* setup.
|
||||
*/
|
||||
coap_dtls_security_setup_t additional_tls_setup_call_back;
|
||||
|
||||
char* client_sni; /**< If not NULL, SNI to use in client TLS setup.
|
||||
Owned by the client app and must remain valid
|
||||
during the call to coap_new_client_session_pki() */
|
||||
|
||||
coap_dtls_key_t pki_key; /**< PKI key definition */
|
||||
} coap_dtls_pki_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup dtls_internal DTLS Support (Internal)
|
||||
* Internal API functions for interfacing with DTLS libraries.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new DTLS context for the given @p coap_context. This function
|
||||
* returns a pointer to a new DTLS context object or @c NULL on error.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_context The CoAP context where the DTLS object shall be used.
|
||||
*
|
||||
* @return A DTLS context object or @c NULL on error.
|
||||
*/
|
||||
void *
|
||||
coap_dtls_new_context(struct coap_context_t *coap_context);
|
||||
|
||||
typedef enum coap_dtls_role_t {
|
||||
COAP_DTLS_ROLE_CLIENT, /**< Internal function invoked for client */
|
||||
COAP_DTLS_ROLE_SERVER /**< Internal function invoked for server */
|
||||
} coap_dtls_role_t;
|
||||
|
||||
/**
|
||||
* Set the DTLS context's default PSK information.
|
||||
* This does the PSK specifics following coap_dtls_new_context().
|
||||
* If @p COAP_DTLS_ROLE_SERVER, then identity hint will also get set.
|
||||
* If @p COAP_DTLS_ROLE_SERVER, then the information will get put into the
|
||||
* TLS library's context (from which sessions are derived).
|
||||
* If @p COAP_DTLS_ROLE_CLIENT, then the information will get put into the
|
||||
* TLS library's session.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_context The CoAP context.
|
||||
* @param identity_hint The default PSK server identity hint sent to a client.
|
||||
* Required parameter. If @p NULL, will be set to "".
|
||||
* Empty string is a valid hint.
|
||||
* This parameter is ignored if COAP_DTLS_ROLE_CLIENT
|
||||
* @param role One of @p COAP_DTLS_ROLE_CLIENT or @p COAP_DTLS_ROLE_SERVER
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
|
||||
int
|
||||
coap_dtls_context_set_psk(struct coap_context_t *coap_context,
|
||||
const char *identity_hint,
|
||||
coap_dtls_role_t role);
|
||||
|
||||
/**
|
||||
* Set the DTLS context's default server PKI information.
|
||||
* This does the PKI specifics following coap_dtls_new_context().
|
||||
* If @p COAP_DTLS_ROLE_SERVER, then the information will get put into the
|
||||
* TLS library's context (from which sessions are derived).
|
||||
* If @p COAP_DTLS_ROLE_CLIENT, then the information will get put into the
|
||||
* TLS library's session.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_context The CoAP context.
|
||||
* @param setup_data Setup information defining how PKI is to be setup.
|
||||
* Required parameter. If @p NULL, PKI will not be
|
||||
* set up.
|
||||
* @param role One of @p COAP_DTLS_ROLE_CLIENT or @p COAP_DTLS_ROLE_SERVER
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
|
||||
int
|
||||
coap_dtls_context_set_pki(struct coap_context_t *coap_context,
|
||||
coap_dtls_pki_t *setup_data,
|
||||
coap_dtls_role_t role);
|
||||
|
||||
/**
|
||||
* Set the dtls context's default Root CA information for a client or server.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_context The current coap_context_t object.
|
||||
* @param ca_file If not @p NULL, is the full path name of a PEM encoded
|
||||
* file containing all the Root CAs to be used.
|
||||
* @param ca_dir If not @p NULL, points to a directory containing PEM
|
||||
* encoded files containing all the Root CAs to be used.
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
|
||||
int
|
||||
coap_dtls_context_set_pki_root_cas(struct coap_context_t *coap_context,
|
||||
const char *ca_file,
|
||||
const char *ca_dir);
|
||||
|
||||
/**
|
||||
* Check whether one of the coap_dtls_context_set_{psk|pki}() functions have
|
||||
* been called.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_context The current coap_context_t object.
|
||||
*
|
||||
* @return @c 1 if coap_dtls_context_set_{psk|pki}() called, else @c 0.
|
||||
*/
|
||||
|
||||
int coap_dtls_context_check_keys_enabled(struct coap_context_t *coap_context);
|
||||
|
||||
/**
|
||||
* Releases the storage allocated for @p dtls_context.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param dtls_context The DTLS context as returned by coap_dtls_new_context().
|
||||
*/
|
||||
void coap_dtls_free_context(void *dtls_context);
|
||||
|
||||
/**
|
||||
* Create a new client-side session. This should send a HELLO to the server.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the session.
|
||||
*/
|
||||
void *coap_dtls_new_client_session(struct coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Create a new DTLS server-side session.
|
||||
* Called after coap_dtls_hello() has returned @c 1, signalling that a validated
|
||||
* HELLO was received from a client.
|
||||
* This should send a HELLO to the server.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the DTLS session.
|
||||
*/
|
||||
void *coap_dtls_new_server_session(struct coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Terminates the DTLS session (may send an ALERT if necessary) then frees the
|
||||
* underlying TLS library object containing security parameters for the session.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_dtls_free_session(struct coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Notify of a change in the CoAP session's MTU, for example after
|
||||
* a PMTU update.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_dtls_session_update_mtu(struct coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Send data to a DTLS peer.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data pointer to data.
|
||||
* @param data_len Number of bytes to send.
|
||||
*
|
||||
* @return @c 0 if this would be blocking, @c -1 if there is an error or the
|
||||
* number of cleartext bytes sent.
|
||||
*/
|
||||
int coap_dtls_send(struct coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
|
||||
/**
|
||||
* Check if timeout is handled per CoAP session or per CoAP context.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @return @c 1 of timeout and retransmit is per context, @c 0 if it is
|
||||
* per session.
|
||||
*/
|
||||
int coap_dtls_is_context_timeout(void);
|
||||
|
||||
/**
|
||||
* Do all pending retransmits and get next timeout
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param dtls_context The DTLS context.
|
||||
*
|
||||
* @return @c 0 if no event is pending or date of the next retransmit.
|
||||
*/
|
||||
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context);
|
||||
|
||||
/**
|
||||
* Get next timeout for this session.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param now The current time in ticks.
|
||||
*
|
||||
* @return @c 0 If no event is pending or ticks time of the next retransmit.
|
||||
*/
|
||||
coap_tick_t coap_dtls_get_timeout(struct coap_session_t *coap_session,
|
||||
coap_tick_t now);
|
||||
|
||||
/**
|
||||
* Handle a DTLS timeout expiration.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_dtls_handle_timeout(struct coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Handling incoming data from a DTLS peer.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Encrypted datagram.
|
||||
* @param data_len Encrypted datagram size.
|
||||
*
|
||||
* @return Result of coap_handle_dgram on the decrypted CoAP PDU
|
||||
* or @c -1 for error.
|
||||
*/
|
||||
int coap_dtls_receive(struct coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
|
||||
/**
|
||||
* Handling client HELLO messages from a new candiate peer.
|
||||
* Note that session->tls is empty.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Encrypted datagram.
|
||||
* @param data_len Encrypted datagram size.
|
||||
*
|
||||
* @return @c 0 if a cookie verification message has been sent, @c 1 if the
|
||||
* HELLO contains a valid cookie and a server session should be created,
|
||||
* @c -1 if the message is invalid.
|
||||
*/
|
||||
int coap_dtls_hello(struct coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
|
||||
/**
|
||||
* Get DTLS overhead over cleartext PDUs.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*
|
||||
* @return Maximum number of bytes added by DTLS layer.
|
||||
*/
|
||||
unsigned int coap_dtls_get_overhead(struct coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Create a new TLS client-side session.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param connected Updated with whether the connection is connected yet or not.
|
||||
* @c 0 is not connected, @c 1 is connected.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the session.
|
||||
*/
|
||||
void *coap_tls_new_client_session(struct coap_session_t *coap_session, int *connected);
|
||||
|
||||
/**
|
||||
* Create a TLS new server-side session.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param connected Updated with whether the connection is connected yet or not.
|
||||
* @c 0 is not connected, @c 1 is connected.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the session.
|
||||
*/
|
||||
void *coap_tls_new_server_session(struct coap_session_t *coap_session, int *connected);
|
||||
|
||||
/**
|
||||
* Terminates the TLS session (may send an ALERT if necessary) then frees the
|
||||
* underlying TLS library object containing security parameters for the session.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_tls_free_session( struct coap_session_t *coap_session );
|
||||
|
||||
/**
|
||||
* Send data to a TLS peer, with implicit flush.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Pointer to data.
|
||||
* @param data_len Number of bytes to send.
|
||||
*
|
||||
* @return @c 0 if this should be retried, @c -1 if there is an error
|
||||
* or the number of cleartext bytes sent.
|
||||
*/
|
||||
ssize_t coap_tls_write(struct coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len
|
||||
);
|
||||
|
||||
/**
|
||||
* Read some data from a TLS peer.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Pointer to data.
|
||||
* @param data_len Maximum number of bytes to read.
|
||||
*
|
||||
* @return @c 0 if this should be retried, @c -1 if there is an error
|
||||
* or the number of cleartext bytes read.
|
||||
*/
|
||||
ssize_t coap_tls_read(struct coap_session_t *coap_session,
|
||||
uint8_t *data,
|
||||
size_t data_len
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialize the underlying (D)TLS Library layer.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
*/
|
||||
void coap_dtls_startup(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Sets the (D)TLS logging level to the specified @p level.
|
||||
* Note: coap_log_level() will influence output if at a specified level.
|
||||
*
|
||||
* @param level The logging level to use - LOG_*
|
||||
*/
|
||||
void coap_dtls_set_log_level(int level);
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Get the current (D)TLS logging.
|
||||
*
|
||||
* @return The current log level (one of LOG_*).
|
||||
*/
|
||||
int coap_dtls_get_log_level(void);
|
||||
|
||||
|
||||
#endif /* COAP_DTLS_H */
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* coap_forward_decls.h -- Forward declarations of structures that are
|
||||
* opaque to application programming that use libcoap.
|
||||
*
|
||||
* Copyright (C) 2019 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_forward_decls.h
|
||||
* @brief COAP forward definitions
|
||||
*/
|
||||
|
||||
#ifndef COAP_FORWARD_DECLS_H_
|
||||
#define COAP_FORWARD_DECLS_H_
|
||||
|
||||
/*
|
||||
* Define the forward declations for the structures (even non-opaque)
|
||||
* so that applications (using coap.h) as well as libcoap builds
|
||||
* can reference them (and makes .h file dependencies a lot simpler).
|
||||
*/
|
||||
struct coap_context_t;
|
||||
struct coap_dtls_pki_t;
|
||||
struct coap_endpoint_t;
|
||||
struct coap_queue_t;
|
||||
struct coap_session_t;
|
||||
struct coap_string_t;
|
||||
struct coap_subscription_t;
|
||||
|
||||
/*
|
||||
* typedef all the structures that are defined in coap_*_internal.h
|
||||
*/
|
||||
|
||||
/* ************* coap_session_internal.h ***************** */
|
||||
|
||||
/**
|
||||
* Abstraction of virtual endpoint that can be attached to coap_context_t.
|
||||
*/
|
||||
typedef struct coap_endpoint_t coap_endpoint_t;
|
||||
|
||||
/* ************* coap_subscribe_internal.h ***************** */
|
||||
|
||||
/** Subscriber information */
|
||||
typedef struct coap_subscription_t coap_subscription_t;
|
||||
|
||||
#endif /* COAP_FORWARD_DECLS_H_ */
|
||||
@@ -1,496 +0,0 @@
|
||||
/* coap_session.h -- Session management for libcoap
|
||||
*
|
||||
* Copyright (C) 2017 Jean-Claue Michelou <jcm@spinetix.com>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_session.h
|
||||
* @brief Defines the application visible session information
|
||||
*/
|
||||
|
||||
#ifndef COAP_SESSION_H_
|
||||
#define COAP_SESSION_H_
|
||||
|
||||
|
||||
#include "coap_forward_decls.h"
|
||||
#include "coap_io.h"
|
||||
#include "coap_time.h"
|
||||
#include "pdu.h"
|
||||
#include "uthash.h"
|
||||
|
||||
/**
|
||||
* Abstraction of a fixed point number that can be used where necessary instead
|
||||
* of a float. 1,000 fractional bits equals one integer
|
||||
*/
|
||||
typedef struct coap_fixed_point_t {
|
||||
uint16_t integer_part; /**< Integer part of fixed point variable */
|
||||
uint16_t fractional_part; /**< Fractional part of fixed point variable
|
||||
1/1000 (3 points) precision */
|
||||
} coap_fixed_point_t;
|
||||
|
||||
#define COAP_DEFAULT_SESSION_TIMEOUT 300
|
||||
#define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND)
|
||||
#define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100
|
||||
|
||||
#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
|
||||
#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS)
|
||||
|
||||
typedef uint8_t coap_session_type_t;
|
||||
/**
|
||||
* coap_session_type_t values
|
||||
*/
|
||||
#define COAP_SESSION_TYPE_CLIENT 1 /**< client-side */
|
||||
#define COAP_SESSION_TYPE_SERVER 2 /**< server-side */
|
||||
#define COAP_SESSION_TYPE_HELLO 3 /**< server-side ephemeral session for responding to a client hello */
|
||||
|
||||
typedef uint8_t coap_session_state_t;
|
||||
/**
|
||||
* coap_session_state_t values
|
||||
*/
|
||||
#define COAP_SESSION_STATE_NONE 0
|
||||
#define COAP_SESSION_STATE_CONNECTING 1
|
||||
#define COAP_SESSION_STATE_HANDSHAKE 2
|
||||
#define COAP_SESSION_STATE_CSM 3
|
||||
#define COAP_SESSION_STATE_ESTABLISHED 4
|
||||
|
||||
typedef struct coap_session_t {
|
||||
coap_proto_t proto; /**< protocol used */
|
||||
coap_session_type_t type; /**< client or server side socket */
|
||||
coap_session_state_t state; /**< current state of relationaship with peer */
|
||||
unsigned ref; /**< reference count from queues */
|
||||
unsigned tls_overhead; /**< overhead of TLS layer */
|
||||
unsigned mtu; /**< path or CSM mtu */
|
||||
coap_address_t local_if; /**< optional local interface address */
|
||||
UT_hash_handle hh;
|
||||
coap_addr_tuple_t addr_info; /**< key: remote/local address info */
|
||||
int ifindex; /**< interface index */
|
||||
coap_socket_t sock; /**< socket object for the session, if any */
|
||||
struct coap_endpoint_t *endpoint; /**< session's endpoint */
|
||||
struct coap_context_t *context; /**< session's context */
|
||||
void *tls; /**< security parameters */
|
||||
uint16_t tx_mid; /**< the last message id that was used in this session */
|
||||
uint8_t con_active; /**< Active CON request sent */
|
||||
coap_tid_t last_ping_mid; /**< the last keepalive message id that was used in this session */
|
||||
struct coap_queue_t *delayqueue; /**< list of delayed messages waiting to be sent */
|
||||
size_t partial_write; /**< if > 0 indicates number of bytes already written from the pdu at the head of sendqueue */
|
||||
uint8_t read_header[8]; /**< storage space for header of incoming message header */
|
||||
size_t partial_read; /**< if > 0 indicates number of bytes already read for an incoming message */
|
||||
coap_pdu_t *partial_pdu; /**< incomplete incoming pdu */
|
||||
coap_tick_t last_rx_tx;
|
||||
coap_tick_t last_tx_rst;
|
||||
coap_tick_t last_ping;
|
||||
coap_tick_t last_pong;
|
||||
coap_tick_t csm_tx;
|
||||
uint8_t *psk_identity;
|
||||
size_t psk_identity_len;
|
||||
uint8_t *psk_key;
|
||||
size_t psk_key_len;
|
||||
void *app; /**< application-specific data */
|
||||
unsigned int max_retransmit; /**< maximum re-transmit count (default 4) */
|
||||
coap_fixed_point_t ack_timeout; /**< timeout waiting for ack (default 2 secs) */
|
||||
coap_fixed_point_t ack_random_factor; /**< ack random factor backoff (default 1.5) */
|
||||
unsigned int dtls_timeout_count; /**< dtls setup retry counter */
|
||||
int dtls_event; /**< Tracking any (D)TLS events on this sesison */
|
||||
} coap_session_t;
|
||||
|
||||
/**
|
||||
* Increment reference counter on a session.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @return same as session
|
||||
*/
|
||||
coap_session_t *coap_session_reference(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Decrement reference counter on a session.
|
||||
* Note that the session may be deleted as a result and should not be used
|
||||
* after this call.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
*/
|
||||
void coap_session_release(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Stores @p data with the given session. This function overwrites any value
|
||||
* that has previously been stored with @p session.
|
||||
*/
|
||||
void coap_session_set_app_data(coap_session_t *session, void *data);
|
||||
|
||||
/**
|
||||
* Returns any application-specific data that has been stored with @p
|
||||
* session using the function coap_session_set_app_data(). This function will
|
||||
* return @c NULL if no data has been stored.
|
||||
*/
|
||||
void *coap_session_get_app_data(const coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Notify session that it has failed.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param reason The reason why the session was disconnected.
|
||||
*/
|
||||
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason);
|
||||
|
||||
/**
|
||||
* Notify session transport has just connected and CSM exchange can now start.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
*/
|
||||
void coap_session_send_csm(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Notify session that it has just connected or reconnected.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
*/
|
||||
void coap_session_connected(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Set the session MTU. This is the maximum message size that can be sent,
|
||||
* excluding IP and UDP overhead.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param mtu maximum message size
|
||||
*/
|
||||
void coap_session_set_mtu(coap_session_t *session, unsigned mtu);
|
||||
|
||||
/**
|
||||
* Get maximum acceptable PDU size
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @return maximum PDU size, not including header (but including token).
|
||||
*/
|
||||
size_t coap_session_max_pdu_size(const coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Creates a new client session to the designated server.
|
||||
* @param ctx The CoAP context.
|
||||
* @param local_if Address of local interface. It is recommended to use NULL to let the operating system choose a suitable local interface. If an address is specified, the port number should be zero, which means that a free port is automatically selected.
|
||||
* @param server The server's address. If the port number is zero, the default port for the protocol will be used.
|
||||
* @param proto Protocol.
|
||||
*
|
||||
* @return A new CoAP session or NULL if failed. Call coap_session_release to free.
|
||||
*/
|
||||
coap_session_t *coap_new_client_session(
|
||||
struct coap_context_t *ctx,
|
||||
const coap_address_t *local_if,
|
||||
const coap_address_t *server,
|
||||
coap_proto_t proto
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a new client session to the designated server with PSK credentials
|
||||
* @param ctx The CoAP context.
|
||||
* @param local_if Address of local interface. It is recommended to use NULL to let the operating system choose a suitable local interface. If an address is specified, the port number should be zero, which means that a free port is automatically selected.
|
||||
* @param server The server's address. If the port number is zero, the default port for the protocol will be used.
|
||||
* @param proto Protocol.
|
||||
* @param identity PSK client identity
|
||||
* @param key PSK shared key
|
||||
* @param key_len PSK shared key length
|
||||
*
|
||||
* @return A new CoAP session or NULL if failed. Call coap_session_release to free.
|
||||
*/
|
||||
coap_session_t *coap_new_client_session_psk(
|
||||
struct coap_context_t *ctx,
|
||||
const coap_address_t *local_if,
|
||||
const coap_address_t *server,
|
||||
coap_proto_t proto,
|
||||
const char *identity,
|
||||
const uint8_t *key,
|
||||
unsigned key_len
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a new client session to the designated server with PKI credentials
|
||||
* @param ctx The CoAP context.
|
||||
* @param local_if Address of local interface. It is recommended to use NULL to
|
||||
* let the operating system choose a suitable local interface.
|
||||
* If an address is specified, the port number should be zero,
|
||||
* which means that a free port is automatically selected.
|
||||
* @param server The server's address. If the port number is zero, the default
|
||||
* port for the protocol will be used.
|
||||
* @param proto CoAP Protocol.
|
||||
* @param setup_data PKI parameters.
|
||||
*
|
||||
* @return A new CoAP session or NULL if failed. Call coap_session_release()
|
||||
* to free.
|
||||
*/
|
||||
coap_session_t *coap_new_client_session_pki(
|
||||
struct coap_context_t *ctx,
|
||||
const coap_address_t *local_if,
|
||||
const coap_address_t *server,
|
||||
coap_proto_t proto,
|
||||
struct coap_dtls_pki_t *setup_data
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a new server session for the specified endpoint.
|
||||
* @param ctx The CoAP context.
|
||||
* @param ep An endpoint where an incoming connection request is pending.
|
||||
*
|
||||
* @return A new CoAP session or NULL if failed. Call coap_session_release to free.
|
||||
*/
|
||||
coap_session_t *coap_new_server_session(
|
||||
struct coap_context_t *ctx,
|
||||
struct coap_endpoint_t *ep
|
||||
);
|
||||
|
||||
/**
|
||||
* Function interface for datagram data transmission. This function returns
|
||||
* the number of bytes that have been transmitted, or a value less than zero
|
||||
* on error.
|
||||
*
|
||||
* @param session Session to send data on.
|
||||
* @param data The data to send.
|
||||
* @param datalen The actual length of @p data.
|
||||
*
|
||||
* @return The number of bytes written on success, or a value
|
||||
* less than zero on error.
|
||||
*/
|
||||
ssize_t coap_session_send(coap_session_t *session,
|
||||
const uint8_t *data, size_t datalen);
|
||||
|
||||
/**
|
||||
* Function interface for stream data transmission. This function returns
|
||||
* the number of bytes that have been transmitted, or a value less than zero
|
||||
* on error. The number of bytes written may be less than datalen because of
|
||||
* congestion control.
|
||||
*
|
||||
* @param session Session to send data on.
|
||||
* @param data The data to send.
|
||||
* @param datalen The actual length of @p data.
|
||||
*
|
||||
* @return The number of bytes written on success, or a value
|
||||
* less than zero on error.
|
||||
*/
|
||||
ssize_t coap_session_write(coap_session_t *session,
|
||||
const uint8_t *data, size_t datalen);
|
||||
|
||||
/**
|
||||
* Send a pdu according to the session's protocol. This function returns
|
||||
* the number of bytes that have been transmitted, or a value less than zero
|
||||
* on error.
|
||||
*
|
||||
* @param session Session to send pdu on.
|
||||
* @param pdu The pdu to send.
|
||||
*
|
||||
* @return The number of bytes written on success, or a value
|
||||
* less than zero on error.
|
||||
*/
|
||||
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu);
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Get session description.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @return description string.
|
||||
*/
|
||||
const char *coap_session_str(const coap_session_t *session);
|
||||
|
||||
ssize_t
|
||||
coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu,
|
||||
struct coap_queue_t *node);
|
||||
|
||||
/**
|
||||
* Create a new endpoint for communicating with peers.
|
||||
*
|
||||
* @param context The coap context that will own the new endpoint
|
||||
* @param listen_addr Address the endpoint will listen for incoming requests on or originate outgoing requests from. Use NULL to specify that no incoming request will be accepted and use a random endpoint.
|
||||
* @param proto Protocol used on this endpoint
|
||||
*/
|
||||
|
||||
coap_endpoint_t *coap_new_endpoint(struct coap_context_t *context, const coap_address_t *listen_addr, coap_proto_t proto);
|
||||
|
||||
/**
|
||||
* Set the endpoint's default MTU. This is the maximum message size that can be
|
||||
* sent, excluding IP and UDP overhead.
|
||||
*
|
||||
* @param endpoint The CoAP endpoint.
|
||||
* @param mtu maximum message size
|
||||
*/
|
||||
void coap_endpoint_set_default_mtu(coap_endpoint_t *endpoint, unsigned mtu);
|
||||
|
||||
void coap_free_endpoint(coap_endpoint_t *ep);
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Get endpoint description.
|
||||
*
|
||||
* @param endpoint The CoAP endpoint.
|
||||
* @return description string.
|
||||
*/
|
||||
const char *coap_endpoint_str(const coap_endpoint_t *endpoint);
|
||||
|
||||
/**
|
||||
* Lookup the server session for the packet received on an endpoint, or create
|
||||
* a new one.
|
||||
*
|
||||
* @param endpoint Active endpoint the packet was received on.
|
||||
* @param packet Received packet.
|
||||
* @param now The current time in ticks.
|
||||
* @return The CoAP session or @c NULL if error.
|
||||
*/
|
||||
coap_session_t *coap_endpoint_get_session(coap_endpoint_t *endpoint,
|
||||
const struct coap_packet_t *packet, coap_tick_t now);
|
||||
|
||||
/**
|
||||
* Create a new DTLS session for the @p session.
|
||||
* Note: the @p session is released if no DTLS server session can be created.
|
||||
*
|
||||
* @ingroup dtls_internal
|
||||
*
|
||||
* @param session Session to add DTLS session to
|
||||
* @param now The current time in ticks.
|
||||
*
|
||||
* @return CoAP session or @c NULL if error.
|
||||
*/
|
||||
coap_session_t *coap_session_new_dtls_session(coap_session_t *session,
|
||||
coap_tick_t now);
|
||||
|
||||
coap_session_t *coap_session_get_by_peer(struct coap_context_t *ctx,
|
||||
const struct coap_address_t *remote_addr, int ifindex);
|
||||
|
||||
void coap_session_free(coap_session_t *session);
|
||||
void coap_session_mfree(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* @defgroup cc Rate Control
|
||||
* The transmission parameters for CoAP rate control ("Congestion
|
||||
* Control" in stream-oriented protocols) are defined in
|
||||
* https://tools.ietf.org/html/rfc7252#section-4.8
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Number of seconds when to expect an ACK or a response to an
|
||||
* outstanding CON message.
|
||||
* RFC 7252, Section 4.8 Default value of ACK_TIMEOUT is 2
|
||||
*/
|
||||
#define COAP_DEFAULT_ACK_TIMEOUT ((coap_fixed_point_t){2,0})
|
||||
|
||||
/**
|
||||
* A factor that is used to randomize the wait time before a message
|
||||
* is retransmitted to prevent synchronization effects.
|
||||
* RFC 7252, Section 4.8 Default value of ACK_RANDOM_FACTOR is 1.5
|
||||
*/
|
||||
#define COAP_DEFAULT_ACK_RANDOM_FACTOR ((coap_fixed_point_t){1,500})
|
||||
|
||||
/**
|
||||
* Number of message retransmissions before message sending is stopped
|
||||
* RFC 7252, Section 4.8 Default value of MAX_RETRANSMIT is 4
|
||||
*/
|
||||
#define COAP_DEFAULT_MAX_RETRANSMIT 4
|
||||
|
||||
/**
|
||||
* The number of simultaneous outstanding interactions that a client
|
||||
* maintains to a given server.
|
||||
* RFC 7252, Section 4.8 Default value of NSTART is 1
|
||||
*/
|
||||
#define COAP_DEFAULT_NSTART 1
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Set the CoAP maximum retransmit count before failure
|
||||
*
|
||||
* Number of message retransmissions before message sending is stopped
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param value The value to set to. The default is 4 and should not normally
|
||||
* get changed.
|
||||
*/
|
||||
void coap_session_set_max_retransmit(coap_session_t *session,
|
||||
unsigned int value);
|
||||
|
||||
/**
|
||||
* Set the CoAP initial ack response timeout before the next re-transmit
|
||||
*
|
||||
* Number of seconds when to expect an ACK or a response to an
|
||||
* outstanding CON message.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param value The value to set to. The default is 2 and should not normally
|
||||
* get changed.
|
||||
*/
|
||||
void coap_session_set_ack_timeout(coap_session_t *session,
|
||||
coap_fixed_point_t value);
|
||||
|
||||
/**
|
||||
* Set the CoAP ack randomize factor
|
||||
*
|
||||
* A factor that is used to randomize the wait time before a message
|
||||
* is retransmitted to prevent synchronization effects.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param value The value to set to. The default is 1.5 and should not normally
|
||||
* get changed.
|
||||
*/
|
||||
void coap_session_set_ack_random_factor(coap_session_t *session,
|
||||
coap_fixed_point_t value);
|
||||
|
||||
/**
|
||||
* Get the CoAP maximum retransmit before failure
|
||||
*
|
||||
* Number of message retransmissions before message sending is stopped
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
*
|
||||
* @return Current maximum retransmit value
|
||||
*/
|
||||
unsigned int coap_session_get_max_transmit(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Get the CoAP initial ack response timeout before the next re-transmit
|
||||
*
|
||||
* Number of seconds when to expect an ACK or a response to an
|
||||
* outstanding CON message.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
*
|
||||
* @return Current ack response timeout value
|
||||
*/
|
||||
coap_fixed_point_t coap_session_get_ack_timeout(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Get the CoAP ack randomize factor
|
||||
*
|
||||
* A factor that is used to randomize the wait time before a message
|
||||
* is retransmitted to prevent synchronization effects.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
*
|
||||
* @return Current ack randomize value
|
||||
*/
|
||||
coap_fixed_point_t coap_session_get_ack_random_factor(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Send a ping message for the session.
|
||||
* @param session The CoAP session.
|
||||
*
|
||||
* @return COAP_INVALID_TID if there is an error
|
||||
*/
|
||||
coap_tid_t coap_session_send_ping(coap_session_t *session);
|
||||
|
||||
#define SESSIONS_ADD(e, obj) \
|
||||
HASH_ADD(hh, (e), addr_info, sizeof((obj)->addr_info), (obj))
|
||||
|
||||
#define SESSIONS_DELETE(e, obj) \
|
||||
HASH_DELETE(hh, (e), (obj))
|
||||
|
||||
#define SESSIONS_ITER(e, el, rtmp) \
|
||||
HASH_ITER(hh, (e), el, rtmp)
|
||||
|
||||
#define SESSIONS_ITER_SAFE(e, el, rtmp) \
|
||||
for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
|
||||
|
||||
#define SESSIONS_FIND(e, k, res) { \
|
||||
HASH_FIND(hh, (e), &(k), sizeof(k), (res)); \
|
||||
}
|
||||
|
||||
#endif /* COAP_SESSION_H */
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* coap_session_internal.h -- Structures, Enums & Functions that are not
|
||||
* exposed to application programming
|
||||
*
|
||||
* Copyright (C) 2010-2019 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_session_internal.h
|
||||
* @brief COAP session internal information
|
||||
*/
|
||||
|
||||
#ifndef COAP_SESSION_INTERNAL_H_
|
||||
#define COAP_SESSION_INTERNAL_H_
|
||||
|
||||
/**
|
||||
* @defgroup session_internal Sessions (Internal)
|
||||
* Structures, Enums and Functions that are not exposed to applications
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstraction of virtual endpoint that can be attached to coap_context_t. The
|
||||
* tuple (handle, addr) must uniquely identify this endpoint.
|
||||
*/
|
||||
struct coap_endpoint_t {
|
||||
struct coap_endpoint_t *next;
|
||||
struct coap_context_t *context; /**< endpoint's context */
|
||||
coap_proto_t proto; /**< protocol used on this interface */
|
||||
uint16_t default_mtu; /**< default mtu for this interface */
|
||||
coap_socket_t sock; /**< socket object for the interface, if any */
|
||||
coap_address_t bind_addr; /**< local interface address */
|
||||
struct coap_session_t *sessions; /**< hash table or list of active sessions */
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_SESSION_INTERNAL_H_ */
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* coap_subscribe_internal.h -- Structures, Enums & Functions that are not
|
||||
* exposed to application programming
|
||||
*
|
||||
* Copyright (C) 2010-2019 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_subscribe_internal.h
|
||||
* @brief COAP subscribe internal information
|
||||
*/
|
||||
|
||||
#ifndef COAP_SUBSCRIBE_INTERNAL_H_
|
||||
#define COAP_SUBSCRIBE_INTERNAL_H_
|
||||
|
||||
/**
|
||||
* @defgroup subscribe_internal Subscribe (Internal)
|
||||
* Structures, Enums and Functions that are not exposed to applications
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef COAP_OBS_MAX_NON
|
||||
/**
|
||||
* Number of notifications that may be sent non-confirmable before a confirmable
|
||||
* message is sent to detect if observers are alive. The maximum allowed value
|
||||
* here is @c 15.
|
||||
*/
|
||||
#define COAP_OBS_MAX_NON 5
|
||||
#endif /* COAP_OBS_MAX_NON */
|
||||
|
||||
#ifndef COAP_OBS_MAX_FAIL
|
||||
/**
|
||||
* Number of confirmable notifications that may fail (i.e. time out without
|
||||
* being ACKed) before an observer is removed. The maximum value for
|
||||
* COAP_OBS_MAX_FAIL is @c 3.
|
||||
*/
|
||||
#define COAP_OBS_MAX_FAIL 3
|
||||
#endif /* COAP_OBS_MAX_FAIL */
|
||||
|
||||
/** Subscriber information */
|
||||
struct coap_subscription_t {
|
||||
struct coap_subscription_t *next; /**< next element in linked list */
|
||||
struct coap_session_t *session; /**< subscriber session */
|
||||
|
||||
unsigned int non_cnt:4; /**< up to 15 non-confirmable notifies allowed */
|
||||
unsigned int fail_cnt:2; /**< up to 3 confirmable notifies can fail */
|
||||
unsigned int dirty:1; /**< set if the notification temporarily could not be
|
||||
* sent (in that case, the resource's partially
|
||||
* dirty flag is set too) */
|
||||
unsigned int has_block2:1; /**< GET request had Block2 definition */
|
||||
uint16_t tid; /**< transaction id, if any, in regular host byte order */
|
||||
coap_block_t block2; /**< GET request Block2 definition */
|
||||
size_t token_length; /**< actual length of token */
|
||||
unsigned char token[8]; /**< token used for subscription */
|
||||
struct coap_string_t *query; /**< query string used for subscription, if any */
|
||||
};
|
||||
|
||||
void coap_subscription_init(coap_subscription_t *);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_SUBSCRIBE_INTERNAL_H_ */
|
||||
@@ -1,809 +0,0 @@
|
||||
/*
|
||||
* net.h -- CoAP network interface
|
||||
*
|
||||
* Copyright (C) 2010-2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_NET_H_
|
||||
#define COAP_NET_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef _WIN32
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#ifdef WITH_LWIP
|
||||
#include <lwip/ip_addr.h>
|
||||
#endif
|
||||
|
||||
#include "coap_io.h"
|
||||
#include "coap_dtls.h"
|
||||
#include "coap_event.h"
|
||||
#include "coap_time.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
#include "prng.h"
|
||||
#include "coap_session.h"
|
||||
|
||||
struct coap_queue_t;
|
||||
|
||||
/**
|
||||
* Queue entry
|
||||
*/
|
||||
typedef struct coap_queue_t {
|
||||
struct coap_queue_t *next;
|
||||
coap_tick_t t; /**< when to send PDU for the next time */
|
||||
unsigned char retransmit_cnt; /**< retransmission counter, will be removed
|
||||
* when zero */
|
||||
unsigned int timeout; /**< the randomized timeout value */
|
||||
coap_session_t *session; /**< the CoAP session */
|
||||
coap_tid_t id; /**< CoAP transaction id */
|
||||
coap_pdu_t *pdu; /**< the CoAP PDU to send */
|
||||
} coap_queue_t;
|
||||
|
||||
/**
|
||||
* Adds @p node to given @p queue, ordered by variable t in @p node.
|
||||
*
|
||||
* @param queue Queue to add to.
|
||||
* @param node Node entry to add to Queue.
|
||||
*
|
||||
* @return @c 1 added to queue, @c 0 failure.
|
||||
*/
|
||||
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node);
|
||||
|
||||
/**
|
||||
* Destroys specified @p node.
|
||||
*
|
||||
* @param node Node entry to remove.
|
||||
*
|
||||
* @return @c 1 node deleted from queue, @c 0 failure.
|
||||
*/
|
||||
int coap_delete_node(coap_queue_t *node);
|
||||
|
||||
/**
|
||||
* Removes all items from given @p queue and frees the allocated storage.
|
||||
*
|
||||
* @param queue The queue to delete.
|
||||
*/
|
||||
void coap_delete_all(coap_queue_t *queue);
|
||||
|
||||
/**
|
||||
* Creates a new node suitable for adding to the CoAP sendqueue.
|
||||
*
|
||||
* @return New node entry, or @c NULL if failure.
|
||||
*/
|
||||
coap_queue_t *coap_new_node(void);
|
||||
|
||||
struct coap_resource_t;
|
||||
struct coap_context_t;
|
||||
#ifndef WITHOUT_ASYNC
|
||||
struct coap_async_state_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Response handler that is used as call-back in coap_context_t.
|
||||
*
|
||||
* @param context CoAP session.
|
||||
* @param session CoAP session.
|
||||
* @param sent The PDU that was transmitted.
|
||||
* @param received The PDU that was received.
|
||||
* @param id CoAP transaction ID.
|
||||
*/
|
||||
typedef void (*coap_response_handler_t)(struct coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *sent,
|
||||
coap_pdu_t *received,
|
||||
const coap_tid_t id);
|
||||
|
||||
/**
|
||||
* Negative Acknowedge handler that is used as call-back in coap_context_t.
|
||||
*
|
||||
* @param context CoAP session.
|
||||
* @param session CoAP session.
|
||||
* @param sent The PDU that was transmitted.
|
||||
* @param reason The reason for the NACK.
|
||||
* @param id CoAP transaction ID.
|
||||
*/
|
||||
typedef void (*coap_nack_handler_t)(struct coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *sent,
|
||||
coap_nack_reason_t reason,
|
||||
const coap_tid_t id);
|
||||
|
||||
/**
|
||||
* Recieved Ping handler that is used as call-back in coap_context_t.
|
||||
*
|
||||
* @param context CoAP session.
|
||||
* @param session CoAP session.
|
||||
* @param received The PDU that was received.
|
||||
* @param id CoAP transaction ID.
|
||||
*/
|
||||
typedef void (*coap_ping_handler_t)(struct coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *received,
|
||||
const coap_tid_t id);
|
||||
|
||||
/**
|
||||
* Recieved Pong handler that is used as call-back in coap_context_t.
|
||||
*
|
||||
* @param context CoAP session.
|
||||
* @param session CoAP session.
|
||||
* @param received The PDU that was received.
|
||||
* @param id CoAP transaction ID.
|
||||
*/
|
||||
typedef void (*coap_pong_handler_t)(struct coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *received,
|
||||
const coap_tid_t id);
|
||||
|
||||
/**
|
||||
* The CoAP stack's global state is stored in a coap_context_t object.
|
||||
*/
|
||||
typedef struct coap_context_t {
|
||||
coap_opt_filter_t known_options;
|
||||
struct coap_resource_t *resources; /**< hash table or list of known
|
||||
resources */
|
||||
struct coap_resource_t *unknown_resource; /**< can be used for handling
|
||||
unknown resources */
|
||||
|
||||
#ifndef WITHOUT_ASYNC
|
||||
/**
|
||||
* list of asynchronous transactions */
|
||||
struct coap_async_state_t *async_state;
|
||||
#endif /* WITHOUT_ASYNC */
|
||||
|
||||
/**
|
||||
* The time stamp in the first element of the sendqeue is relative
|
||||
* to sendqueue_basetime. */
|
||||
coap_tick_t sendqueue_basetime;
|
||||
coap_queue_t *sendqueue;
|
||||
coap_endpoint_t *endpoint; /**< the endpoints used for listening */
|
||||
coap_session_t *sessions; /**< client sessions */
|
||||
|
||||
#ifdef WITH_CONTIKI
|
||||
struct uip_udp_conn *conn; /**< uIP connection object */
|
||||
struct etimer retransmit_timer; /**< fires when the next packet must be sent */
|
||||
struct etimer notify_timer; /**< used to check resources periodically */
|
||||
#endif /* WITH_CONTIKI */
|
||||
|
||||
#ifdef WITH_LWIP
|
||||
uint8_t timer_configured; /**< Set to 1 when a retransmission is
|
||||
* scheduled using lwIP timers for this
|
||||
* context, otherwise 0. */
|
||||
#endif /* WITH_LWIP */
|
||||
|
||||
coap_response_handler_t response_handler;
|
||||
coap_nack_handler_t nack_handler;
|
||||
coap_ping_handler_t ping_handler;
|
||||
coap_pong_handler_t pong_handler;
|
||||
|
||||
/**
|
||||
* Callback function that is used to signal events to the
|
||||
* application. This field is set by coap_set_event_handler().
|
||||
*/
|
||||
coap_event_handler_t handle_event;
|
||||
|
||||
ssize_t (*network_send)(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen);
|
||||
|
||||
ssize_t (*network_read)(coap_socket_t *sock, struct coap_packet_t *packet);
|
||||
|
||||
size_t(*get_client_psk)(const coap_session_t *session, const uint8_t *hint, size_t hint_len, uint8_t *identity, size_t *identity_len, size_t max_identity_len, uint8_t *psk, size_t max_psk_len);
|
||||
size_t(*get_server_psk)(const coap_session_t *session, const uint8_t *identity, size_t identity_len, uint8_t *psk, size_t max_psk_len);
|
||||
size_t(*get_server_hint)(const coap_session_t *session, uint8_t *hint, size_t max_hint_len);
|
||||
|
||||
void *dtls_context;
|
||||
uint8_t *psk_hint;
|
||||
size_t psk_hint_len;
|
||||
uint8_t *psk_key;
|
||||
size_t psk_key_len;
|
||||
|
||||
unsigned int session_timeout; /**< Number of seconds of inactivity after which an unused session will be closed. 0 means use default. */
|
||||
unsigned int max_idle_sessions; /**< Maximum number of simultaneous unused sessions per endpoint. 0 means no maximum. */
|
||||
unsigned int max_handshake_sessions; /**< Maximum number of simultaneous negotating sessions per endpoint. 0 means use default. */
|
||||
unsigned int ping_timeout; /**< Minimum inactivity time before sending a ping message. 0 means disabled. */
|
||||
unsigned int csm_timeout; /**< Timeout for waiting for a CSM from the remote side. 0 means disabled. */
|
||||
|
||||
void *app; /**< application-specific data */
|
||||
#ifdef COAP_EPOLL_SUPPORT
|
||||
int epfd; /**< External FD for epoll */
|
||||
int eptimerfd; /**< Internal FD for timeout */
|
||||
coap_tick_t next_timeout; /**< When the next timeout is to occur */
|
||||
#endif /* COAP_EPOLL_SUPPORT */
|
||||
} coap_context_t;
|
||||
|
||||
/**
|
||||
* Registers a new message handler that is called whenever a response was
|
||||
* received that matches an ongoing transaction.
|
||||
*
|
||||
* @param context The context to register the handler for.
|
||||
* @param handler The response handler to register.
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_register_response_handler(coap_context_t *context,
|
||||
coap_response_handler_t handler) {
|
||||
context->response_handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new message handler that is called whenever a confirmable
|
||||
* message (request or response) is dropped after all retries have been
|
||||
* exhausted, or a rst message was received, or a network or TLS level
|
||||
* event was received that indicates delivering the message is not possible.
|
||||
*
|
||||
* @param context The context to register the handler for.
|
||||
* @param handler The nack handler to register.
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_register_nack_handler(coap_context_t *context,
|
||||
coap_nack_handler_t handler) {
|
||||
context->nack_handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new message handler that is called whenever a CoAP Ping
|
||||
* message is received.
|
||||
*
|
||||
* @param context The context to register the handler for.
|
||||
* @param handler The ping handler to register.
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_register_ping_handler(coap_context_t *context,
|
||||
coap_ping_handler_t handler) {
|
||||
context->ping_handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new message handler that is called whenever a CoAP Pong
|
||||
* message is received.
|
||||
*
|
||||
* @param context The context to register the handler for.
|
||||
* @param handler The pong handler to register.
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_register_pong_handler(coap_context_t *context,
|
||||
coap_pong_handler_t handler) {
|
||||
context->pong_handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the option type @p type with the given context object @p ctx.
|
||||
*
|
||||
* @param ctx The context to use.
|
||||
* @param type The option type to register.
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_register_option(coap_context_t *ctx, uint16_t type) {
|
||||
coap_option_setb(ctx->known_options, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sendqueue_basetime in the given context object @p ctx to @p now. This
|
||||
* function returns the number of elements in the queue head that have timed
|
||||
* out.
|
||||
*/
|
||||
unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now);
|
||||
|
||||
/**
|
||||
* Returns the next pdu to send without removing from sendqeue.
|
||||
*/
|
||||
coap_queue_t *coap_peek_next( coap_context_t *context );
|
||||
|
||||
/**
|
||||
* Returns the next pdu to send and removes it from the sendqeue.
|
||||
*/
|
||||
coap_queue_t *coap_pop_next( coap_context_t *context );
|
||||
|
||||
/**
|
||||
* Creates a new coap_context_t object that will hold the CoAP stack status.
|
||||
*/
|
||||
coap_context_t *coap_new_context(const coap_address_t *listen_addr);
|
||||
|
||||
/**
|
||||
* Set the context's default PSK hint and/or key for a server.
|
||||
*
|
||||
* @param context The current coap_context_t object.
|
||||
* @param hint The default PSK server hint sent to a client. If @p NULL, PSK
|
||||
* authentication is disabled. Empty string is a valid hint.
|
||||
* @param key The default PSK key. If @p NULL, PSK authentication will fail.
|
||||
* @param key_len The default PSK key's length. If @p 0, PSK authentication will
|
||||
* fail.
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
int coap_context_set_psk( coap_context_t *context, const char *hint,
|
||||
const uint8_t *key, size_t key_len );
|
||||
|
||||
/**
|
||||
* Set the context's default PKI information for a server.
|
||||
*
|
||||
* @param context The current coap_context_t object.
|
||||
* @param setup_data If @p NULL, PKI authentication will fail. Certificate
|
||||
* information required.
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
int
|
||||
coap_context_set_pki(coap_context_t *context,
|
||||
coap_dtls_pki_t *setup_data);
|
||||
|
||||
/**
|
||||
* Set the context's default Root CA information for a client or server.
|
||||
*
|
||||
* @param context The current coap_context_t object.
|
||||
* @param ca_file If not @p NULL, is the full path name of a PEM encoded
|
||||
* file containing all the Root CAs to be used.
|
||||
* @param ca_dir If not @p NULL, points to a directory containing PEM
|
||||
* encoded files containing all the Root CAs to be used.
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
int
|
||||
coap_context_set_pki_root_cas(coap_context_t *context,
|
||||
const char *ca_file,
|
||||
const char *ca_dir);
|
||||
|
||||
/**
|
||||
* Set the context keepalive timer for sessions.
|
||||
* A keepalive message will be sent after if a session has been inactive,
|
||||
* i.e. no packet sent or received, for the given number of seconds.
|
||||
* For unreliable protocols, a CoAP Empty message will be sent. If a
|
||||
* CoAP RST is not received, the CoAP Empty messages will get resent based
|
||||
* on the Confirmable retry parameters until there is a failure timeout,
|
||||
* at which point the session will be considered as disconnected.
|
||||
* For reliable protocols, a CoAP PING message will be sent. If a CoAP PONG
|
||||
* has not been received before the next PING is due to be sent, the session
|
||||
* will be considered as disconnected.
|
||||
*
|
||||
* @param context The coap_context_t object.
|
||||
* @param seconds Number of seconds for the inactivity timer, or zero
|
||||
* to disable CoAP-level keepalive messages.
|
||||
*
|
||||
* @return 1 if successful, else 0
|
||||
*/
|
||||
void coap_context_set_keepalive(coap_context_t *context, unsigned int seconds);
|
||||
|
||||
/**
|
||||
* Get the libcoap internal file descriptor for using in an application's
|
||||
* select() or returned as an event in an application's epoll_wait() call.
|
||||
*
|
||||
* @param context The coap_context_t object.
|
||||
*
|
||||
* @return The libcoap file descriptor or @c -1 if epoll is not available.
|
||||
*/
|
||||
int coap_context_get_coap_fd(coap_context_t *context);
|
||||
|
||||
/**
|
||||
* Returns a new message id and updates @p session->tx_mid accordingly. The
|
||||
* message id is returned in network byte order to make it easier to read in
|
||||
* tracing tools.
|
||||
*
|
||||
* @param session The current coap_session_t object.
|
||||
*
|
||||
* @return Incremented message id in network byte order.
|
||||
*/
|
||||
COAP_STATIC_INLINE uint16_t
|
||||
coap_new_message_id(coap_session_t *session) {
|
||||
return ++session->tx_mid;
|
||||
}
|
||||
|
||||
/**
|
||||
* CoAP stack context must be released with coap_free_context(). This function
|
||||
* clears all entries from the receive queue and send queue and deletes the
|
||||
* resources that have been registered with @p context, and frees the attached
|
||||
* endpoints.
|
||||
*
|
||||
* @param context The current coap_context_t object to free off.
|
||||
*/
|
||||
void coap_free_context(coap_context_t *context);
|
||||
|
||||
/**
|
||||
* Stores @p data with the given CoAP context. This function
|
||||
* overwrites any value that has previously been stored with @p
|
||||
* context.
|
||||
*
|
||||
* @param context The CoAP context.
|
||||
* @param data The data to store with wih the context. Note that this data
|
||||
* must be valid during the lifetime of @p context.
|
||||
*/
|
||||
void coap_set_app_data(coap_context_t *context, void *data);
|
||||
|
||||
/**
|
||||
* Returns any application-specific data that has been stored with @p
|
||||
* context using the function coap_set_app_data(). This function will
|
||||
* return @c NULL if no data has been stored.
|
||||
*
|
||||
* @param context The CoAP context.
|
||||
*
|
||||
* @return The data previously stored or @c NULL if not data stored.
|
||||
*/
|
||||
void *coap_get_app_data(const coap_context_t *context);
|
||||
|
||||
/**
|
||||
* Creates a new ACK PDU with specified error @p code. The options specified by
|
||||
* the filter expression @p opts will be copied from the original request
|
||||
* contained in @p request. Unless @c SHORT_ERROR_RESPONSE was defined at build
|
||||
* time, the textual reason phrase for @p code will be added as payload, with
|
||||
* Content-Type @c 0.
|
||||
* This function returns a pointer to the new response message, or @c NULL on
|
||||
* error. The storage allocated for the new message must be relased with
|
||||
* coap_free().
|
||||
*
|
||||
* @param request Specification of the received (confirmable) request.
|
||||
* @param code The error code to set.
|
||||
* @param opts An option filter that specifies which options to copy from
|
||||
* the original request in @p node.
|
||||
*
|
||||
* @return A pointer to the new message or @c NULL on error.
|
||||
*/
|
||||
coap_pdu_t *coap_new_error_response(coap_pdu_t *request,
|
||||
unsigned char code,
|
||||
coap_opt_filter_t opts);
|
||||
|
||||
/**
|
||||
* Sends an error response with code @p code for request @p request to @p dst.
|
||||
* @p opts will be passed to coap_new_error_response() to copy marked options
|
||||
* from the request. This function returns the transaction id if the message was
|
||||
* sent, or @c COAP_INVALID_TID otherwise.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param request The original request to respond to.
|
||||
* @param code The response code.
|
||||
* @param opts A filter that specifies the options to copy from the
|
||||
* @p request.
|
||||
*
|
||||
* @return The transaction id if the message was sent, or @c
|
||||
* COAP_INVALID_TID otherwise.
|
||||
*/
|
||||
coap_tid_t coap_send_error(coap_session_t *session,
|
||||
coap_pdu_t *request,
|
||||
unsigned char code,
|
||||
coap_opt_filter_t opts);
|
||||
|
||||
/**
|
||||
* Helper funktion to create and send a message with @p type (usually ACK or
|
||||
* RST). This function returns @c COAP_INVALID_TID when the message was not
|
||||
* sent, a valid transaction id otherwise.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param request The request that should be responded to.
|
||||
* @param type Which type to set.
|
||||
* @return transaction id on success or @c COAP_INVALID_TID
|
||||
* otherwise.
|
||||
*/
|
||||
coap_tid_t
|
||||
coap_send_message_type(coap_session_t *session, coap_pdu_t *request, unsigned char type);
|
||||
|
||||
/**
|
||||
* Sends an ACK message with code @c 0 for the specified @p request to @p dst.
|
||||
* This function returns the corresponding transaction id if the message was
|
||||
* sent or @c COAP_INVALID_TID on error.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param request The request to be acknowledged.
|
||||
*
|
||||
* @return The transaction id if ACK was sent or @c
|
||||
* COAP_INVALID_TID on error.
|
||||
*/
|
||||
coap_tid_t coap_send_ack(coap_session_t *session, coap_pdu_t *request);
|
||||
|
||||
/**
|
||||
* Sends an RST message with code @c 0 for the specified @p request to @p dst.
|
||||
* This function returns the corresponding transaction id if the message was
|
||||
* sent or @c COAP_INVALID_TID on error.
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param request The request to be reset.
|
||||
*
|
||||
* @return The transaction id if RST was sent or @c
|
||||
* COAP_INVALID_TID on error.
|
||||
*/
|
||||
COAP_STATIC_INLINE coap_tid_t
|
||||
coap_send_rst(coap_session_t *session, coap_pdu_t *request) {
|
||||
return coap_send_message_type(session, request, COAP_MESSAGE_RST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a CoAP message to given peer. The memory that is
|
||||
* allocated by pdu will be released by coap_send().
|
||||
* The caller must not use the pdu after calling coap_send().
|
||||
*
|
||||
* @param session The CoAP session.
|
||||
* @param pdu The CoAP PDU to send.
|
||||
*
|
||||
* @return The message id of the sent message or @c
|
||||
* COAP_INVALID_TID on error.
|
||||
*/
|
||||
coap_tid_t coap_send( coap_session_t *session, coap_pdu_t *pdu );
|
||||
|
||||
/**
|
||||
* Handles retransmissions of confirmable messages
|
||||
*
|
||||
* @param context The CoAP context.
|
||||
* @param node The node to retransmit.
|
||||
*
|
||||
* @return The message id of the sent message or @c
|
||||
* COAP_INVALID_TID on error.
|
||||
*/
|
||||
coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node);
|
||||
|
||||
/**
|
||||
* For applications with their own message loop, send all pending retransmits and
|
||||
* return the list of sockets with events to wait for and the next timeout
|
||||
* The application should call coap_read, then coap_write again when any condition below is true:
|
||||
* - data is available on any of the sockets with the COAP_SOCKET_WANT_READ
|
||||
* - an incoming connection is pending in the listen queue and the COAP_SOCKET_WANT_ACCEPT flag is set
|
||||
* - at least some data can be written without blocking on any of the sockets with the COAP_SOCKET_WANT_WRITE flag set
|
||||
* - a connection event occured (success or failure) and the COAP_SOCKET_WANT_CONNECT flag is set
|
||||
* - the timeout has expired
|
||||
* Before calling coap_read or coap_write again, the application should position COAP_SOCKET_CAN_READ and COAP_SOCKET_CAN_WRITE flags as applicable.
|
||||
*
|
||||
* @param ctx The CoAP context
|
||||
* @param sockets array of socket descriptors, filled on output
|
||||
* @param max_sockets size of socket array.
|
||||
* @param num_sockets pointer to the number of valid entries in the socket arrays on output
|
||||
* @param now Current time.
|
||||
*
|
||||
* @return timeout as maxmimum number of milliseconds that the application should wait for network events or 0 if the application should wait forever.
|
||||
*/
|
||||
|
||||
unsigned int
|
||||
coap_write(coap_context_t *ctx,
|
||||
coap_socket_t *sockets[],
|
||||
unsigned int max_sockets,
|
||||
unsigned int *num_sockets,
|
||||
coap_tick_t now
|
||||
);
|
||||
|
||||
/**
|
||||
* For applications with their own message loop, reads all data from the network.
|
||||
*
|
||||
* @param ctx The CoAP context
|
||||
* @param now Current time
|
||||
*/
|
||||
void coap_read(coap_context_t *ctx, coap_tick_t now);
|
||||
|
||||
#define COAP_RUN_BLOCK 0
|
||||
#define COAP_RUN_NONBLOCK 1
|
||||
|
||||
/**
|
||||
* The main message processing loop.
|
||||
*
|
||||
* @param ctx The CoAP context
|
||||
* @param timeout_ms Minimum number of milliseconds to wait for new packets
|
||||
* before returning. If COAP_RUN_BLOCK, the call will block
|
||||
* until at least one new packet is received. If
|
||||
* COAP_RUN_NONBLOCK, the function will return immediately
|
||||
* following without waiting for any new input not already
|
||||
* available.
|
||||
*
|
||||
* @return Number of milliseconds spent in coap_run_once, or @c -1 if there
|
||||
* was an error
|
||||
*/
|
||||
|
||||
int coap_run_once( coap_context_t *ctx, unsigned int timeout_ms );
|
||||
|
||||
/**
|
||||
* Any now timed out delayed packet is transmitted, along with any packets
|
||||
* associated with requested observable response.
|
||||
*
|
||||
* In addition, it returns when the next expected I/O is expected to take place
|
||||
* (e.g. a packet retransmit).
|
||||
*
|
||||
* Note: If epoll support is compiled into libcoap, coap_io_prepare_epoll() must
|
||||
* be used instead of coap_write().
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param ctx The CoAP context
|
||||
* @param now Current time.
|
||||
*
|
||||
* @return timeout Maxmimum number of milliseconds that can be used by a
|
||||
* epoll_wait() to wait for network events or 0 if wait should be
|
||||
* forever.
|
||||
*/
|
||||
unsigned int
|
||||
coap_io_prepare_epoll(coap_context_t *ctx, coap_tick_t now);
|
||||
|
||||
struct epoll_event;
|
||||
/**
|
||||
* Process all the epoll events
|
||||
*
|
||||
* Internal function
|
||||
*
|
||||
* @param ctx The current CoAP context.
|
||||
* @param events The list of events returned from an epoll_wait() call.
|
||||
* @param nevents The number of events.
|
||||
*
|
||||
*/
|
||||
void coap_io_do_events(coap_context_t *ctx, struct epoll_event* events,
|
||||
size_t nevents);
|
||||
|
||||
/**
|
||||
* Parses and interprets a CoAP datagram with context @p ctx. This function
|
||||
* returns @c 0 if the datagram was handled, or a value less than zero on
|
||||
* error.
|
||||
*
|
||||
* @param ctx The current CoAP context.
|
||||
* @param session The current CoAP session.
|
||||
* @param data The received packet'd data.
|
||||
* @param data_len The received packet'd data length.
|
||||
*
|
||||
* @return @c 0 if message was handled successfully, or less than zero on
|
||||
* error.
|
||||
*/
|
||||
int coap_handle_dgram(coap_context_t *ctx, coap_session_t *session, uint8_t *data, size_t data_len);
|
||||
|
||||
/**
|
||||
* Invokes the event handler of @p context for the given @p event and
|
||||
* @p data.
|
||||
*
|
||||
* @param context The CoAP context whose event handler is to be called.
|
||||
* @param event The event to deliver.
|
||||
* @param session The session related to @p event.
|
||||
* @return The result from the associated event handler or 0 if none was
|
||||
* registered.
|
||||
*/
|
||||
int coap_handle_event(coap_context_t *context,
|
||||
coap_event_t event,
|
||||
coap_session_t *session);
|
||||
/**
|
||||
* This function removes the element with given @p id from the list given list.
|
||||
* If @p id was found, @p node is updated to point to the removed element. Note
|
||||
* that the storage allocated by @p node is @b not released. The caller must do
|
||||
* this manually using coap_delete_node(). This function returns @c 1 if the
|
||||
* element with id @p id was found, @c 0 otherwise. For a return value of @c 0,
|
||||
* the contents of @p node is undefined.
|
||||
*
|
||||
* @param queue The queue to search for @p id.
|
||||
* @param session The session to look for.
|
||||
* @param id The transaction id to look for.
|
||||
* @param node If found, @p node is updated to point to the removed node. You
|
||||
* must release the storage pointed to by @p node manually.
|
||||
*
|
||||
* @return @c 1 if @p id was found, @c 0 otherwise.
|
||||
*/
|
||||
int coap_remove_from_queue(coap_queue_t **queue,
|
||||
coap_session_t *session,
|
||||
coap_tid_t id,
|
||||
coap_queue_t **node);
|
||||
|
||||
coap_tid_t
|
||||
coap_wait_ack( coap_context_t *context, coap_session_t *session,
|
||||
coap_queue_t *node);
|
||||
|
||||
/**
|
||||
* Retrieves transaction from the queue.
|
||||
*
|
||||
* @param queue The transaction queue to be searched.
|
||||
* @param session The session to find.
|
||||
* @param id The transaction id to find.
|
||||
*
|
||||
* @return A pointer to the transaction object or @c NULL if not found.
|
||||
*/
|
||||
coap_queue_t *coap_find_transaction(coap_queue_t *queue, coap_session_t *session, coap_tid_t id);
|
||||
|
||||
/**
|
||||
* Cancels all outstanding messages for session @p session that have the specified
|
||||
* token.
|
||||
*
|
||||
* @param context The context in use.
|
||||
* @param session Session of the messages to remove.
|
||||
* @param token Message token.
|
||||
* @param token_length Actual length of @p token.
|
||||
*/
|
||||
void coap_cancel_all_messages(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
const uint8_t *token,
|
||||
size_t token_length);
|
||||
|
||||
/**
|
||||
* Cancels all outstanding messages for session @p session.
|
||||
*
|
||||
* @param context The context in use.
|
||||
* @param session Session of the messages to remove.
|
||||
* @param reason The reasion for the session cancellation
|
||||
*/
|
||||
void
|
||||
coap_cancel_session_messages(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_nack_reason_t reason);
|
||||
|
||||
/**
|
||||
* Dispatches the PDUs from the receive queue in given context.
|
||||
*/
|
||||
void coap_dispatch(coap_context_t *context, coap_session_t *session,
|
||||
coap_pdu_t *pdu);
|
||||
|
||||
/**
|
||||
* Returns 1 if there are no messages to send or to dispatch in the context's
|
||||
* queues. */
|
||||
int coap_can_exit(coap_context_t *context);
|
||||
|
||||
/**
|
||||
* Returns the current value of an internal tick counter. The counter counts \c
|
||||
* COAP_TICKS_PER_SECOND ticks every second.
|
||||
*/
|
||||
void coap_ticks(coap_tick_t *);
|
||||
|
||||
/**
|
||||
* Verifies that @p pdu contains no unknown critical options. Options must be
|
||||
* registered at @p ctx, using the function coap_register_option(). A basic set
|
||||
* of options is registered automatically by coap_new_context(). This function
|
||||
* returns @c 1 if @p pdu is ok, @c 0 otherwise. The given filter object @p
|
||||
* unknown will be updated with the unknown options. As only @c COAP_MAX_OPT
|
||||
* options can be signalled this way, remaining options must be examined
|
||||
* manually.
|
||||
*
|
||||
* @code
|
||||
coap_opt_filter_t f = COAP_OPT_NONE;
|
||||
coap_opt_iterator_t opt_iter;
|
||||
|
||||
if (coap_option_check_critical(ctx, pdu, f) == 0) {
|
||||
coap_option_iterator_init(pdu, &opt_iter, f);
|
||||
|
||||
while (coap_option_next(&opt_iter)) {
|
||||
if (opt_iter.type & 0x01) {
|
||||
... handle unknown critical option in opt_iter ...
|
||||
}
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
*
|
||||
* @param ctx The context where all known options are registered.
|
||||
* @param pdu The PDU to check.
|
||||
* @param unknown The output filter that will be updated to indicate the
|
||||
* unknown critical options found in @p pdu.
|
||||
*
|
||||
* @return @c 1 if everything was ok, @c 0 otherwise.
|
||||
*/
|
||||
int coap_option_check_critical(coap_context_t *ctx,
|
||||
coap_pdu_t *pdu,
|
||||
coap_opt_filter_t unknown);
|
||||
|
||||
/**
|
||||
* Creates a new response for given @p request with the contents of @c
|
||||
* .well-known/core. The result is NULL on error or a newly allocated PDU that
|
||||
* must be either sent with coap_sent() or released by coap_delete_pdu().
|
||||
*
|
||||
* @param context The current coap context to use.
|
||||
* @param session The CoAP session.
|
||||
* @param request The request for @c .well-known/core .
|
||||
*
|
||||
* @return A new 2.05 response for @c .well-known/core or NULL on error.
|
||||
*/
|
||||
coap_pdu_t *coap_wellknown_response(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *request);
|
||||
|
||||
/**
|
||||
* Calculates the initial timeout based on the session CoAP transmission
|
||||
* parameters 'ack_timeout', 'ack_random_factor', and COAP_TICKS_PER_SECOND.
|
||||
* The calculation requires 'ack_timeout' and 'ack_random_factor' to be in
|
||||
* Qx.FRAC_BITS fixed point notation, whereas the passed parameter @p r
|
||||
* is interpreted as the fractional part of a Q0.MAX_BITS random value.
|
||||
*
|
||||
* @param session session timeout is associated with
|
||||
* @param r random value as fractional part of a Q0.MAX_BITS fixed point
|
||||
* value
|
||||
* @return COAP_TICKS_PER_SECOND * 'ack_timeout' *
|
||||
* (1 + ('ack_random_factor' - 1) * r)
|
||||
*/
|
||||
unsigned int coap_calc_timeout(coap_session_t *session, unsigned char r);
|
||||
|
||||
/**
|
||||
* Function interface for joining a multicast group for listening
|
||||
*
|
||||
* @param ctx The current context
|
||||
* @param groupname The name of the group that is to be joined for listening
|
||||
*
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
coap_join_mcast_group(coap_context_t *ctx, const char *groupname);
|
||||
|
||||
#endif /* COAP_NET_H_ */
|
||||
@@ -1,551 +0,0 @@
|
||||
/*
|
||||
* pdu.h -- CoAP message structure
|
||||
*
|
||||
* Copyright (C) 2010-2014 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file pdu.h
|
||||
* @brief Pre-defined constants that reflect defaults for CoAP
|
||||
*/
|
||||
|
||||
#ifndef COAP_PDU_H_
|
||||
#define COAP_PDU_H_
|
||||
|
||||
#include "coap_config.h"
|
||||
#include "uri.h"
|
||||
|
||||
struct coap_session_t;
|
||||
|
||||
#ifdef WITH_LWIP
|
||||
#include <lwip/pbuf.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#ifndef COAP_USER_DEFAULT_PORT
|
||||
#define COAP_USER_DEFAULT_PORT 5683 /* CoAP default UDP/TCP port */
|
||||
#endif
|
||||
|
||||
#define COAP_NSTACKX_PORT COAP_USER_DEFAULT_PORT
|
||||
|
||||
#define COAP_DEFAULT_PORT COAP_USER_DEFAULT_PORT
|
||||
|
||||
#define COAPS_DEFAULT_PORT 5684 /* CoAP default UDP/TCP port for secure transmission */
|
||||
#define COAP_DEFAULT_MAX_AGE 60 /* default maximum object lifetime in seconds */
|
||||
#ifndef COAP_DEFAULT_MTU
|
||||
#define COAP_DEFAULT_MTU 1152
|
||||
#endif /* COAP_DEFAULT_MTU */
|
||||
|
||||
/* TCP Message format constants, do not modify */
|
||||
#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
|
||||
#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
|
||||
#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
|
||||
|
||||
/* Derived message size limits */
|
||||
#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
|
||||
#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
|
||||
#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
|
||||
#define COAP_MAX_MESSAGE_SIZE_TCP32 (COAP_MESSAGE_SIZE_OFFSET_TCP32+0xFFFFFFFF)
|
||||
|
||||
#ifndef COAP_DEFAULT_MAX_PDU_RX_SIZE
|
||||
#if defined(WITH_CONTIKI) || defined(WITH_LWIP)
|
||||
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (COAP_MAX_MESSAGE_SIZE_TCP16+4)
|
||||
#else
|
||||
/* 8 MiB max-message-size plus some space for options */
|
||||
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8*1024*1024+256)
|
||||
#endif
|
||||
#endif /* COAP_DEFAULT_MAX_PDU_RX_SIZE */
|
||||
|
||||
#ifndef COAP_DEBUG_BUF_SIZE
|
||||
#if defined(WITH_CONTIKI) || defined(WITH_LWIP)
|
||||
#define COAP_DEBUG_BUF_SIZE 128
|
||||
#else /* defined(WITH_CONTIKI) || defined(WITH_LWIP) */
|
||||
/* 1024 derived from RFC7252 4.6. Message Size max payload */
|
||||
#define COAP_DEBUG_BUF_SIZE (8 + 1024 * 2)
|
||||
#endif /* defined(WITH_CONTIKI) || defined(WITH_LWIP) */
|
||||
#endif /* COAP_DEBUG_BUF_SIZE */
|
||||
|
||||
#define COAP_DEFAULT_VERSION 1 /* version of CoAP supported */
|
||||
#define COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */
|
||||
|
||||
/** well-known resources URI */
|
||||
#define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
|
||||
|
||||
/* CoAP message types */
|
||||
|
||||
#define COAP_MESSAGE_CON 0 /* confirmable message (requires ACK/RST) */
|
||||
#define COAP_MESSAGE_NON 1 /* non-confirmable message (one-shot message) */
|
||||
#define COAP_MESSAGE_ACK 2 /* used to acknowledge confirmable messages */
|
||||
#define COAP_MESSAGE_RST 3 /* indicates error in received messages */
|
||||
|
||||
/* CoAP request methods */
|
||||
|
||||
#define COAP_REQUEST_GET 1
|
||||
#define COAP_REQUEST_POST 2
|
||||
#define COAP_REQUEST_PUT 3
|
||||
#define COAP_REQUEST_DELETE 4
|
||||
#define COAP_REQUEST_FETCH 5 /* RFC 8132 */
|
||||
#define COAP_REQUEST_PATCH 6 /* RFC 8132 */
|
||||
#define COAP_REQUEST_IPATCH 7 /* RFC 8132 */
|
||||
|
||||
/*
|
||||
* CoAP option types (be sure to update coap_option_check_critical() when
|
||||
* adding options
|
||||
*/
|
||||
|
||||
#define COAP_OPTION_IF_MATCH 1 /* C, opaque, 0-8 B, (none) */
|
||||
#define COAP_OPTION_URI_HOST 3 /* C, String, 1-255 B, destination address */
|
||||
#define COAP_OPTION_ETAG 4 /* E, opaque, 1-8 B, (none) */
|
||||
#define COAP_OPTION_IF_NONE_MATCH 5 /* empty, 0 B, (none) */
|
||||
#define COAP_OPTION_URI_PORT 7 /* C, uint, 0-2 B, destination port */
|
||||
#define COAP_OPTION_LOCATION_PATH 8 /* E, String, 0-255 B, - */
|
||||
#define COAP_OPTION_URI_PATH 11 /* C, String, 0-255 B, (none) */
|
||||
#define COAP_OPTION_CONTENT_FORMAT 12 /* E, uint, 0-2 B, (none) */
|
||||
#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
|
||||
#define COAP_OPTION_MAXAGE 14 /* E, uint, 0--4 B, 60 Seconds */
|
||||
#define COAP_OPTION_URI_QUERY 15 /* C, String, 1-255 B, (none) */
|
||||
#define COAP_OPTION_ACCEPT 17 /* C, uint, 0-2 B, (none) */
|
||||
#define COAP_OPTION_LOCATION_QUERY 20 /* E, String, 0-255 B, (none) */
|
||||
#define COAP_OPTION_SIZE2 28 /* E, uint, 0-4 B, (none) */
|
||||
#define COAP_OPTION_PROXY_URI 35 /* C, String, 1-1034 B, (none) */
|
||||
#define COAP_OPTION_PROXY_SCHEME 39 /* C, String, 1-255 B, (none) */
|
||||
#define COAP_OPTION_SIZE1 60 /* E, uint, 0-4 B, (none) */
|
||||
|
||||
/* option types from RFC 7641 */
|
||||
|
||||
#define COAP_OPTION_OBSERVE 6 /* E, empty/uint, 0 B/0-3 B, (none) */
|
||||
#define COAP_OPTION_SUBSCRIPTION COAP_OPTION_OBSERVE
|
||||
|
||||
/* selected option types from RFC 7959 */
|
||||
|
||||
#define COAP_OPTION_BLOCK2 23 /* C, uint, 0--3 B, (none) */
|
||||
#define COAP_OPTION_BLOCK1 27 /* C, uint, 0--3 B, (none) */
|
||||
|
||||
/* selected option types from RFC 7967 */
|
||||
|
||||
#define COAP_OPTION_NORESPONSE 258 /* N, uint, 0--1 B, 0 */
|
||||
|
||||
#define COAP_MAX_OPT 65535 /**< the highest option number we know */
|
||||
|
||||
/* CoAP result codes (HTTP-Code / 100 * 40 + HTTP-Code % 100) */
|
||||
|
||||
/* As of draft-ietf-core-coap-04, response codes are encoded to base
|
||||
* 32, i.e. the three upper bits determine the response class while
|
||||
* the remaining five fine-grained information specific to that class.
|
||||
*/
|
||||
#define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
|
||||
|
||||
/* Determines the class of response code C */
|
||||
#define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
|
||||
|
||||
#ifndef SHORT_ERROR_RESPONSE
|
||||
/**
|
||||
* Returns a human-readable response phrase for the specified CoAP response @p
|
||||
* code. This function returns @c NULL if not found.
|
||||
*
|
||||
* @param code The response code for which the literal phrase should be
|
||||
* retrieved.
|
||||
*
|
||||
* @return A zero-terminated string describing the error, or @c NULL if not
|
||||
* found.
|
||||
*/
|
||||
const char *coap_response_phrase(unsigned char code);
|
||||
|
||||
#define COAP_ERROR_PHRASE_LENGTH 32 /**< maximum length of error phrase */
|
||||
|
||||
#else
|
||||
#define coap_response_phrase(x) ((char *)NULL)
|
||||
|
||||
#define COAP_ERROR_PHRASE_LENGTH 0 /**< maximum length of error phrase */
|
||||
#endif /* SHORT_ERROR_RESPONSE */
|
||||
|
||||
/* The following definitions exist for backwards compatibility */
|
||||
#if 0 /* this does not exist any more */
|
||||
#define COAP_RESPONSE_100 40 /* 100 Continue */
|
||||
#endif
|
||||
#define COAP_RESPONSE_200 COAP_RESPONSE_CODE(200) /* 2.00 OK */
|
||||
#define COAP_RESPONSE_201 COAP_RESPONSE_CODE(201) /* 2.01 Created */
|
||||
#define COAP_RESPONSE_304 COAP_RESPONSE_CODE(203) /* 2.03 Valid */
|
||||
#define COAP_RESPONSE_400 COAP_RESPONSE_CODE(400) /* 4.00 Bad Request */
|
||||
#define COAP_RESPONSE_404 COAP_RESPONSE_CODE(404) /* 4.04 Not Found */
|
||||
#define COAP_RESPONSE_405 COAP_RESPONSE_CODE(405) /* 4.05 Method Not Allowed */
|
||||
#define COAP_RESPONSE_415 COAP_RESPONSE_CODE(415) /* 4.15 Unsupported Media Type */
|
||||
#define COAP_RESPONSE_500 COAP_RESPONSE_CODE(500) /* 5.00 Internal Server Error */
|
||||
#define COAP_RESPONSE_501 COAP_RESPONSE_CODE(501) /* 5.01 Not Implemented */
|
||||
#define COAP_RESPONSE_503 COAP_RESPONSE_CODE(503) /* 5.03 Service Unavailable */
|
||||
#define COAP_RESPONSE_504 COAP_RESPONSE_CODE(504) /* 5.04 Gateway Timeout */
|
||||
#if 0 /* these response codes do not have a valid code any more */
|
||||
# define COAP_RESPONSE_X_240 240 /* Token Option required by server */
|
||||
# define COAP_RESPONSE_X_241 241 /* Uri-Authority Option required by server */
|
||||
#endif
|
||||
#define COAP_RESPONSE_X_242 COAP_RESPONSE_CODE(402) /* Critical Option not supported */
|
||||
|
||||
#define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)
|
||||
#define COAP_SIGNALING_CSM COAP_SIGNALING_CODE(701)
|
||||
#define COAP_SIGNALING_PING COAP_SIGNALING_CODE(702)
|
||||
#define COAP_SIGNALING_PONG COAP_SIGNALING_CODE(703)
|
||||
#define COAP_SIGNALING_RELEASE COAP_SIGNALING_CODE(704)
|
||||
#define COAP_SIGNALING_ABORT COAP_SIGNALING_CODE(705)
|
||||
|
||||
/* Applies to COAP_SIGNALING_CSM */
|
||||
#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
|
||||
#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4
|
||||
/* Applies to COAP_SIGNALING_PING / COAP_SIGNALING_PONG */
|
||||
#define COAP_SIGNALING_OPTION_CUSTODY 2
|
||||
/* Applies to COAP_SIGNALING_RELEASE */
|
||||
#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
|
||||
#define COAP_SIGNALING_OPTION_HOLD_OFF 4
|
||||
/* Applies to COAP_SIGNALING_ABORT */
|
||||
#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
|
||||
|
||||
/* CoAP media type encoding */
|
||||
|
||||
#define COAP_MEDIATYPE_TEXT_PLAIN 0 /* text/plain (UTF-8) */
|
||||
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40 /* application/link-format */
|
||||
#define COAP_MEDIATYPE_APPLICATION_XML 41 /* application/xml */
|
||||
#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42 /* application/octet-stream */
|
||||
#define COAP_MEDIATYPE_APPLICATION_RDF_XML 43 /* application/rdf+xml */
|
||||
#define COAP_MEDIATYPE_APPLICATION_EXI 47 /* application/exi */
|
||||
#define COAP_MEDIATYPE_APPLICATION_JSON 50 /* application/json */
|
||||
#define COAP_MEDIATYPE_APPLICATION_CBOR 60 /* application/cbor */
|
||||
|
||||
/* Content formats from RFC 8152 */
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98 /* application/cose; cose-type="cose-sign" */
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18 /* application/cose; cose-type="cose-sign1" */
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96 /* application/cose; cose-type="cose-encrypt" */
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16 /* application/cose; cose-type="cose-encrypt0" */
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC 97 /* application/cose; cose-type="cose-mac" */
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17 /* application/cose; cose-type="cose-mac0" */
|
||||
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY 101 /* application/cose-key */
|
||||
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102 /* application/cose-key-set */
|
||||
|
||||
/* Content formats from RFC 8428 */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENML_JSON 110 /* application/senml+json */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111 /* application/sensml+json */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112 /* application/senml+cbor */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113 /* application/sensml+cbor */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENML_EXI 114 /* application/senml-exi */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115 /* application/sensml-exi */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENML_XML 310 /* application/senml+xml */
|
||||
#define COAP_MEDIATYPE_APPLICATION_SENSML_XML 311 /* application/sensml+xml */
|
||||
|
||||
/* Note that identifiers for registered media types are in the range 0-65535. We
|
||||
* use an unallocated type here and hope for the best. */
|
||||
#define COAP_MEDIATYPE_ANY 0xff /* any media type */
|
||||
|
||||
/**
|
||||
* coap_tid_t is used to store CoAP transaction id, i.e. a hash value
|
||||
* built from the remote transport address and the message id of a
|
||||
* CoAP PDU. Valid transaction ids are greater or equal zero.
|
||||
*/
|
||||
typedef int coap_tid_t;
|
||||
|
||||
/** Indicates an invalid transaction id. */
|
||||
#define COAP_INVALID_TID -1
|
||||
|
||||
/**
|
||||
* Indicates that a response is suppressed. This will occur for error
|
||||
* responses if the request was received via IP multicast.
|
||||
*/
|
||||
#define COAP_DROPPED_RESPONSE -2
|
||||
|
||||
#define COAP_PDU_DELAYED -3
|
||||
|
||||
#define COAP_OPT_LONG 0x0F /* OC == 0b1111 indicates that the option list
|
||||
* in a CoAP message is limited by 0b11110000
|
||||
* marker */
|
||||
|
||||
#define COAP_OPT_END 0xF0 /* end marker */
|
||||
|
||||
#define COAP_PAYLOAD_START 0xFF /* payload marker */
|
||||
|
||||
/**
|
||||
* @deprecated Use coap_optlist_t instead.
|
||||
*
|
||||
* Structures for more convenient handling of options. (To be used with ordered
|
||||
* coap_list_t.) The option's data will be added to the end of the coap_option
|
||||
* structure (see macro COAP_OPTION_DATA).
|
||||
*/
|
||||
COAP_DEPRECATED typedef struct {
|
||||
uint16_t key; /* the option key (no delta coding) */
|
||||
unsigned int length;
|
||||
} coap_option;
|
||||
|
||||
#define COAP_OPTION_KEY(option) (option).key
|
||||
#define COAP_OPTION_LENGTH(option) (option).length
|
||||
#define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
|
||||
|
||||
/**
|
||||
* structure for CoAP PDUs
|
||||
* token, if any, follows the fixed size header, then options until
|
||||
* payload marker (0xff), then the payload if stored inline.
|
||||
* Memory layout is:
|
||||
* <---header--->|<---token---><---options--->0xff<---payload--->
|
||||
* header is addressed with a negative offset to token, its maximum size is
|
||||
* max_hdr_size.
|
||||
* options starts at token + token_length
|
||||
* payload starts at data, its length is used_size - (data - token)
|
||||
*/
|
||||
|
||||
typedef struct coap_pdu_t {
|
||||
uint8_t type; /**< message type */
|
||||
uint8_t code; /**< request method (value 1--10) or response code (value 40-255) */
|
||||
uint8_t max_hdr_size; /**< space reserved for protocol-specific header */
|
||||
uint8_t hdr_size; /**< actaul size used for protocol-specific header */
|
||||
uint8_t token_length; /**< length of Token */
|
||||
uint16_t tid; /**< transaction id, if any, in regular host byte order */
|
||||
uint16_t max_delta; /**< highest option number */
|
||||
size_t alloc_size; /**< allocated storage for token, options and payload */
|
||||
size_t used_size; /**< used bytes of storage for token, options and payload */
|
||||
size_t max_size; /**< maximum size for token, options and payload, or zero for variable size pdu */
|
||||
uint8_t *token; /**< first byte of token, if any, or options */
|
||||
uint8_t *data; /**< first byte of payload, if any */
|
||||
#ifdef WITH_LWIP
|
||||
struct pbuf *pbuf; /**< lwIP PBUF. The package data will always reside
|
||||
* inside the pbuf's payload, but this pointer
|
||||
* has to be kept because no exact offset can be
|
||||
* given. This field must not be accessed from
|
||||
* outside, because the pbuf's reference count
|
||||
* is checked to be 1 when the pbuf is assigned
|
||||
* to the pdu, and the pbuf stays exclusive to
|
||||
* this pdu. */
|
||||
#endif
|
||||
} coap_pdu_t;
|
||||
|
||||
#define COAP_PDU_IS_EMPTY(pdu) ((pdu)->code == 0)
|
||||
#define COAP_PDU_IS_REQUEST(pdu) (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32)
|
||||
#define COAP_PDU_IS_RESPONSE(pdu) ((pdu)->code >= 64 && (pdu)->code < 224)
|
||||
#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
|
||||
|
||||
#define COAP_PDU_MAX_UDP_HEADER_SIZE 4
|
||||
#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
|
||||
|
||||
#ifdef WITH_LWIP
|
||||
/**
|
||||
* Creates a CoAP PDU from an lwIP @p pbuf, whose reference is passed on to this
|
||||
* function.
|
||||
*
|
||||
* The pbuf is checked for being contiguous, and for having only one reference.
|
||||
* The reference is stored in the PDU and will be freed when the PDU is freed.
|
||||
*
|
||||
* (For now, these are fatal errors; in future, a new pbuf might be allocated,
|
||||
* the data copied and the passed pbuf freed).
|
||||
*
|
||||
* This behaves like coap_pdu_init(0, 0, 0, pbuf->tot_len), and afterwards
|
||||
* copying the contents of the pbuf to the pdu.
|
||||
*
|
||||
* @return A pointer to the new PDU object or @c NULL on error.
|
||||
*/
|
||||
coap_pdu_t * coap_pdu_from_pbuf(struct pbuf *pbuf);
|
||||
#endif
|
||||
|
||||
typedef uint8_t coap_proto_t;
|
||||
/**
|
||||
* coap_proto_t values
|
||||
*/
|
||||
#define COAP_PROTO_NONE 0
|
||||
#define COAP_PROTO_UDP 1
|
||||
#define COAP_PROTO_DTLS 2
|
||||
#define COAP_PROTO_TCP 3
|
||||
#define COAP_PROTO_TLS 4
|
||||
|
||||
/**
|
||||
* Creates a new CoAP PDU with at least enough storage space for the given
|
||||
* @p size maximum message size. The function returns a pointer to the
|
||||
* node coap_pdu_t object on success, or @c NULL on error. The storage allocated
|
||||
* for the result must be released with coap_delete_pdu() if coap_send() is not
|
||||
* called.
|
||||
*
|
||||
* @param type The type of the PDU (one of COAP_MESSAGE_CON, COAP_MESSAGE_NON,
|
||||
* COAP_MESSAGE_ACK, COAP_MESSAGE_RST).
|
||||
* @param code The message code.
|
||||
* @param tid The transcation id to set or 0 if unknown / not applicable.
|
||||
* @param size The maximum allowed number of byte for the message.
|
||||
* @return A pointer to the new PDU object or @c NULL on error.
|
||||
*/
|
||||
coap_pdu_t *
|
||||
coap_pdu_init(uint8_t type, uint8_t code, uint16_t tid, size_t size);
|
||||
|
||||
/**
|
||||
* Dynamically grows the size of @p pdu to @p new_size. The new size
|
||||
* must not exceed the PDU's configure maximum size. On success, this
|
||||
* function returns 1, otherwise 0.
|
||||
*
|
||||
* @param pdu The PDU to resize.
|
||||
* @param new_size The new size in bytes.
|
||||
* @return 1 if the operation succeeded, 0 otherwise.
|
||||
*/
|
||||
int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size);
|
||||
|
||||
/**
|
||||
* Clears any contents from @p pdu and resets @c used_size,
|
||||
* and @c data pointers. @c max_size is set to @p size, any
|
||||
* other field is set to @c 0. Note that @p pdu must be a valid
|
||||
* pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
|
||||
*/
|
||||
void coap_pdu_clear(coap_pdu_t *pdu, size_t size);
|
||||
|
||||
/**
|
||||
* Creates a new CoAP PDU.
|
||||
*/
|
||||
coap_pdu_t *coap_new_pdu(const struct coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Dispose of an CoAP PDU and frees associated storage.
|
||||
* Not that in general you should not call this function directly.
|
||||
* When a PDU is sent with coap_send(), coap_delete_pdu() will be
|
||||
* called automatically for you.
|
||||
*/
|
||||
|
||||
void coap_delete_pdu(coap_pdu_t *);
|
||||
|
||||
/**
|
||||
* Interprets @p data to determine the number of bytes in the header.
|
||||
* This function returns @c 0 on error or a number greater than zero on success.
|
||||
*
|
||||
* @param proto Session's protocol
|
||||
* @param data The first byte of raw data to parse as CoAP PDU.
|
||||
*
|
||||
* @return A value greater than zero on success or @c 0 on error.
|
||||
*/
|
||||
size_t coap_pdu_parse_header_size(coap_proto_t proto,
|
||||
const uint8_t *data);
|
||||
|
||||
/**
|
||||
* Parses @p data to extract the message size.
|
||||
* @p length must be at least coap_pdu_parse_header_size(proto, data).
|
||||
* This function returns @c 0 on error or a number greater than zero on success.
|
||||
*
|
||||
* @param proto Session's protocol
|
||||
* @param data The raw data to parse as CoAP PDU.
|
||||
* @param length The actual size of @p data.
|
||||
*
|
||||
* @return A value greater than zero on success or @c 0 on error.
|
||||
*/
|
||||
size_t coap_pdu_parse_size(coap_proto_t proto,
|
||||
const uint8_t *data,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* Decode the protocol specific header for the specified PDU.
|
||||
* @param pdu A newly received PDU.
|
||||
* @param proto The target wire protocol.
|
||||
* @return 1 for success or 0 on error.
|
||||
*/
|
||||
|
||||
int coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto);
|
||||
|
||||
/**
|
||||
* Verify consistency in the given CoAP PDU structure and locate the data.
|
||||
* This function returns @c 0 on error or a number greater than zero on
|
||||
* success.
|
||||
* This function only parses the token and options, up to the payload start
|
||||
* marker.
|
||||
*
|
||||
* @param pdu The PDU structure to.
|
||||
*
|
||||
* @return 1 on success or @c 0 on error.
|
||||
*/
|
||||
int coap_pdu_parse_opt(coap_pdu_t *pdu);
|
||||
|
||||
/**
|
||||
* Parses @p data into the CoAP PDU structure given in @p result.
|
||||
* The target pdu must be large enough to
|
||||
* This function returns @c 0 on error or a number greater than zero on success.
|
||||
*
|
||||
* @param proto Session's protocol
|
||||
* @param data The raw data to parse as CoAP PDU.
|
||||
* @param length The actual size of @p data.
|
||||
* @param pdu The PDU structure to fill. Note that the structure must
|
||||
* provide space to hold at least the token and options
|
||||
* part of the message.
|
||||
*
|
||||
* @return 1 on success or @c 0 on error.
|
||||
*/
|
||||
int coap_pdu_parse(coap_proto_t proto,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
coap_pdu_t *pdu);
|
||||
/**
|
||||
* Adds token of length @p len to @p pdu.
|
||||
* Adding the token destroys any following contents of the pdu. Hence options
|
||||
* and data must be added after coap_add_token() has been called. In @p pdu,
|
||||
* length is set to @p len + @c 4, and max_delta is set to @c 0. This function
|
||||
* returns @c 0 on error or a value greater than zero on success.
|
||||
*
|
||||
* @param pdu The PDU where the token is to be added.
|
||||
* @param len The length of the new token.
|
||||
* @param data The token to add.
|
||||
*
|
||||
* @return A value greater than zero on success, or @c 0 on error.
|
||||
*/
|
||||
int coap_add_token(coap_pdu_t *pdu,
|
||||
size_t len,
|
||||
const uint8_t *data);
|
||||
|
||||
/**
|
||||
* Adds option of given type to pdu that is passed as first
|
||||
* parameter.
|
||||
* coap_add_option() destroys the PDU's data, so coap_add_data() must be called
|
||||
* after all options have been added. As coap_add_token() destroys the options
|
||||
* following the token, the token must be added before coap_add_option() is
|
||||
* called. This function returns the number of bytes written or @c 0 on error.
|
||||
*/
|
||||
size_t coap_add_option(coap_pdu_t *pdu,
|
||||
uint16_t type,
|
||||
size_t len,
|
||||
const uint8_t *data);
|
||||
|
||||
/**
|
||||
* Adds option of given type to pdu that is passed as first parameter, but does
|
||||
* not write a value. It works like coap_add_option with respect to calling
|
||||
* sequence (i.e. after token and before data). This function returns a memory
|
||||
* address to which the option data has to be written before the PDU can be
|
||||
* sent, or @c NULL on error.
|
||||
*/
|
||||
uint8_t *coap_add_option_later(coap_pdu_t *pdu,
|
||||
uint16_t type,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* Adds given data to the pdu that is passed as first parameter. Note that the
|
||||
* PDU's data is destroyed by coap_add_option(). coap_add_data() must be called
|
||||
* only once per PDU, otherwise the result is undefined.
|
||||
*/
|
||||
int coap_add_data(coap_pdu_t *pdu,
|
||||
size_t len,
|
||||
const uint8_t *data);
|
||||
|
||||
/**
|
||||
* Adds given data to the pdu that is passed as first parameter but does not
|
||||
* copyt it. Note that the PDU's data is destroyed by coap_add_option().
|
||||
* coap_add_data() must be have been called once for this PDU, otherwise the
|
||||
* result is undefined.
|
||||
* The actual data must be copied at the returned location.
|
||||
*/
|
||||
uint8_t *coap_add_data_after(coap_pdu_t *pdu, size_t len);
|
||||
|
||||
/**
|
||||
* Retrieves the length and data pointer of specified PDU. Returns 0 on error or
|
||||
* 1 if *len and *data have correct values. Note that these values are destroyed
|
||||
* with the pdu.
|
||||
*/
|
||||
int coap_get_data(const coap_pdu_t *pdu,
|
||||
size_t *len,
|
||||
uint8_t **data);
|
||||
|
||||
/**
|
||||
* Compose the protocol specific header for the specified PDU.
|
||||
* @param pdu A newly composed PDU.
|
||||
* @param proto The target wire protocol.
|
||||
* @return Number of header bytes prepended before pdu->token or 0 on error.
|
||||
*/
|
||||
|
||||
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto);
|
||||
|
||||
#endif /* COAP_PDU_H_ */
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* prng.h -- Pseudo Random Numbers
|
||||
*
|
||||
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file prng.h
|
||||
* @brief Pseudo Random Numbers
|
||||
*/
|
||||
|
||||
#ifndef COAP_PRNG_H_
|
||||
#define COAP_PRNG_H_
|
||||
|
||||
/**
|
||||
* @defgroup prng Pseudo Random Numbers
|
||||
* API functions for gerating pseudo random numbers
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(WITH_CONTIKI)
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Fills \p buf with \p len random bytes. This is the default implementation for
|
||||
* prng(). You might want to change prng() to use a better PRNG on your specific
|
||||
* platform.
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
contiki_prng_impl(unsigned char *buf, size_t len) {
|
||||
uint16_t v = random_rand();
|
||||
while (len > sizeof(v)) {
|
||||
memcpy(buf, &v, sizeof(v));
|
||||
len -= sizeof(v);
|
||||
buf += sizeof(v);
|
||||
v = random_rand();
|
||||
}
|
||||
|
||||
memcpy(buf, &v, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define prng(Buf,Length) contiki_prng_impl((Buf), (Length))
|
||||
#define prng_init(Value) random_init((uint16_t)(Value))
|
||||
#elif defined(WITH_LWIP) && defined(LWIP_RAND)
|
||||
COAP_STATIC_INLINE int
|
||||
lwip_prng_impl(unsigned char *buf, size_t len) {
|
||||
u32_t v = LWIP_RAND();
|
||||
while (len > sizeof(v)) {
|
||||
memcpy(buf, &v, sizeof(v));
|
||||
len -= sizeof(v);
|
||||
buf += sizeof(v);
|
||||
v = LWIP_RAND();
|
||||
}
|
||||
|
||||
memcpy(buf, &v, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define prng(Buf,Length) lwip_prng_impl((Buf), (Length))
|
||||
#define prng_init(Value)
|
||||
#elif defined(_WIN32)
|
||||
#define prng_init(Value)
|
||||
errno_t __cdecl rand_s( _Out_ unsigned int* _RandomValue );
|
||||
/**
|
||||
* Fills \p buf with \p len random bytes. This is the default implementation for
|
||||
* prng(). You might want to change prng() to use a better PRNG on your specific
|
||||
* platform.
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
coap_prng_impl( unsigned char *buf, size_t len ) {
|
||||
while ( len != 0 ) {
|
||||
uint32_t r = 0;
|
||||
size_t i;
|
||||
if ( rand_s( &r ) != 0 )
|
||||
return 0;
|
||||
for ( i = 0; i < len && i < 4; i++ ) {
|
||||
*buf++ = (uint8_t)r;
|
||||
r >>= 8;
|
||||
}
|
||||
len -= i;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* Fills \p buf with \p len random bytes. This is the default implementation for
|
||||
* prng(). You might want to change prng() to use a better PRNG on your specific
|
||||
* platform.
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
coap_prng_impl( unsigned char *buf, size_t len ) {
|
||||
while ( len-- )
|
||||
*buf++ = rand() & 0xFF;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef prng
|
||||
/**
|
||||
* Fills \p Buf with \p Length bytes of random data.
|
||||
*
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define prng(Buf,Length) coap_prng_impl((Buf), (Length))
|
||||
#endif
|
||||
|
||||
#ifndef prng_init
|
||||
/**
|
||||
* Called to set the PRNG seed. You may want to re-define this to allow for a
|
||||
* better PRNG.
|
||||
*
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define prng_init(Value) srand((unsigned long)(Value))
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_PRNG_H_ */
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* str.h -- strings to be used in the CoAP library
|
||||
*
|
||||
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_STR_H_
|
||||
#define COAP_STR_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup string String handling support
|
||||
* API functions for handling strings
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Coap string data definition
|
||||
*/
|
||||
typedef struct coap_string_t {
|
||||
size_t length; /**< length of string */
|
||||
uint8_t *s; /**< string data */
|
||||
} coap_string_t;
|
||||
|
||||
/**
|
||||
* Coap string data definition with const data
|
||||
*/
|
||||
typedef struct coap_str_const_t {
|
||||
size_t length; /**< length of string */
|
||||
const uint8_t *s; /**< string data */
|
||||
} coap_str_const_t;
|
||||
|
||||
#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
|
||||
|
||||
/**
|
||||
* Coap binary data definition
|
||||
*/
|
||||
typedef struct coap_binary_t {
|
||||
size_t length; /**< length of binary data */
|
||||
uint8_t *s; /**< binary data */
|
||||
} coap_binary_t;
|
||||
|
||||
/**
|
||||
* Returns a new string object with at least size+1 bytes storage allocated.
|
||||
* The string must be released using coap_delete_string().
|
||||
*
|
||||
* @param size The size to allocate for the binary string data.
|
||||
*
|
||||
* @return A pointer to the new object or @c NULL on error.
|
||||
*/
|
||||
coap_string_t *coap_new_string(size_t size);
|
||||
|
||||
/**
|
||||
* Deletes the given string and releases any memory allocated.
|
||||
*
|
||||
* @param string The string to free off.
|
||||
*/
|
||||
void coap_delete_string(coap_string_t *string);
|
||||
|
||||
/**
|
||||
* Returns a new const string object with at least size+1 bytes storage
|
||||
* allocated, and the provided data copied into the string object.
|
||||
* The string must be released using coap_delete_str_const().
|
||||
*
|
||||
* @param data The data to put in the new string object.
|
||||
* @param size The size to allocate for the binary string data.
|
||||
*
|
||||
* @return A pointer to the new object or @c NULL on error.
|
||||
*/
|
||||
coap_str_const_t *coap_new_str_const(const uint8_t *data, size_t size);
|
||||
|
||||
/**
|
||||
* Deletes the given const string and releases any memory allocated.
|
||||
*
|
||||
* @param string The string to free off.
|
||||
*/
|
||||
void coap_delete_str_const(coap_str_const_t *string);
|
||||
|
||||
#define COAP_MAX_STR_CONST_FUNC 2
|
||||
/**
|
||||
* Take the specified string and create a coap_str_const_t *
|
||||
*
|
||||
* Note: the array is 2 deep as there are up to two callings of
|
||||
* coap_make_str_const in a function call. e.g. coap_add_attr().
|
||||
* Caution: If there are local variable assignments, these will cycle around
|
||||
* the var[COAP_MAX_STR_CONST_FUNC] set. No current examples do this.
|
||||
*
|
||||
* @param string The const string to convert to a coap_str_const_t *
|
||||
*
|
||||
* @return A pointer to one of two static variables containing the
|
||||
* coap_str_const_t * result
|
||||
*/
|
||||
coap_str_const_t *coap_make_str_const(const char *string);
|
||||
|
||||
/**
|
||||
* Compares the two strings for equality
|
||||
*
|
||||
* @param string1 The first string.
|
||||
* @param string2 The second string.
|
||||
*
|
||||
* @return @c 1 if the strings are equal
|
||||
* @c 0 otherwise.
|
||||
*/
|
||||
#define coap_string_equal(string1,string2) \
|
||||
((string1)->length == (string2)->length && ((string1)->length == 0 || \
|
||||
memcmp((string1)->s, (string2)->s, (string1)->length) == 0))
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_STR_H_ */
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* subscribe.h -- subscription handling for CoAP
|
||||
* see RFC7641
|
||||
*
|
||||
* Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file subscribe.h
|
||||
* @brief Defines the application visible subscribe information
|
||||
*/
|
||||
|
||||
#ifndef COAP_SUBSCRIBE_H_
|
||||
#define COAP_SUBSCRIBE_H_
|
||||
|
||||
/**
|
||||
* @defgroup observe Resource observation
|
||||
* API functions for interfacing with the observe handling (RFC7641)
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* The value COAP_OBSERVE_ESTABLISH in a GET request indicates a new observe
|
||||
* relationship for (sender address, token) is requested.
|
||||
*/
|
||||
#define COAP_OBSERVE_ESTABLISH 0
|
||||
|
||||
/**
|
||||
* The value COAP_OBSERVE_CANCEL in a GET request indicates that the observe
|
||||
* relationship for (sender address, token) must be cancelled.
|
||||
*/
|
||||
#define COAP_OBSERVE_CANCEL 1
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_SUBSCRIBE_H_ */
|
||||
@@ -2,7 +2,8 @@
|
||||
* address.h -- representation of network addresses
|
||||
*
|
||||
* Copyright (C) 2010-2011,2015-2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
@@ -31,6 +32,22 @@ typedef struct coap_address_t {
|
||||
ip_addr_t addr;
|
||||
} coap_address_t;
|
||||
|
||||
/**
|
||||
* Returns the port from @p addr in host byte order.
|
||||
*/
|
||||
COAP_STATIC_INLINE uint16_t
|
||||
coap_address_get_port(const coap_address_t *addr) {
|
||||
return ntohs(addr->port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port field of @p addr to @p port (in host byte order).
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_address_set_port(coap_address_t *addr, uint16_t port) {
|
||||
addr->port = htons(port);
|
||||
}
|
||||
|
||||
#define _coap_address_equals_impl(A, B) \
|
||||
((A)->port == (B)->port \
|
||||
&& (!!ip_addr_cmp(&(A)->addr,&(B)->addr)))
|
||||
@@ -38,9 +55,11 @@ typedef struct coap_address_t {
|
||||
#define _coap_address_isany_impl(A) ip_addr_isany(&(A)->addr)
|
||||
|
||||
#define _coap_is_mcast_impl(Address) ip_addr_ismulticast(&(Address)->addr)
|
||||
|
||||
#ifdef COAP_SUPPORT_SOCKET_BROADCAST
|
||||
#define _coap_is_bcast_impl(Address) ip_addr_isbroadcast(&(Address)->addr)
|
||||
#endif
|
||||
|
||||
#elif defined(WITH_CONTIKI)
|
||||
|
||||
#include "uip.h"
|
||||
@@ -50,6 +69,22 @@ typedef struct coap_address_t {
|
||||
uint16_t port;
|
||||
} coap_address_t;
|
||||
|
||||
/**
|
||||
* Returns the port from @p addr in host byte order.
|
||||
*/
|
||||
COAP_STATIC_INLINE uint16_t
|
||||
coap_address_get_port(const coap_address_t *addr) {
|
||||
return uip_ntohs(addr->port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port field of @p addr to @p port (in host byte order).
|
||||
*/
|
||||
COAP_STATIC_INLINE void
|
||||
coap_address_set_port(coap_address_t *addr, uint16_t port) {
|
||||
addr->port = uip_htons(port);
|
||||
}
|
||||
|
||||
#define _coap_address_equals_impl(A,B) \
|
||||
((A)->port == (B)->port \
|
||||
&& uip_ipaddr_cmp(&((A)->addr),&((B)->addr)))
|
||||
@@ -58,17 +93,13 @@ typedef struct coap_address_t {
|
||||
#define _coap_address_isany_impl(A) 0
|
||||
|
||||
#define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))
|
||||
|
||||
#ifdef COAP_SUPPORT_SOCKET_BROADCAST
|
||||
#define _coap_is_bcast_impl(Address) (0)
|
||||
#endif
|
||||
|
||||
#else /* WITH_LWIP || WITH_CONTIKI */
|
||||
|
||||
#ifdef LWIP_STACK
|
||||
#include <lwip/sockets.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif /* LWIP_STACK */
|
||||
/** multi-purpose address abstraction */
|
||||
typedef struct coap_address_t {
|
||||
socklen_t size; /**< size of addr */
|
||||
@@ -79,6 +110,16 @@ typedef struct coap_address_t {
|
||||
} addr;
|
||||
} coap_address_t;
|
||||
|
||||
/**
|
||||
* Returns the port from @p addr in host byte order.
|
||||
*/
|
||||
uint16_t coap_address_get_port(const coap_address_t *addr);
|
||||
|
||||
/**
|
||||
* Set the port field of @p addr to @p port (in host byte order).
|
||||
*/
|
||||
void coap_address_set_port(coap_address_t *addr, uint16_t port);
|
||||
|
||||
/**
|
||||
* Compares given address objects @p a and @p b. This function returns @c 1 if
|
||||
* addresses are equal, @c 0 otherwise. The parameters @p a and @p b must not be
|
||||
@@ -168,9 +209,11 @@ coap_address_isany(const coap_address_t *a) {
|
||||
* returns @c 1 if @p a is multicast, @c 0 otherwise.
|
||||
*/
|
||||
int coap_is_mcast(const coap_address_t *a);
|
||||
|
||||
#ifdef COAP_SUPPORT_SOCKET_BROADCAST
|
||||
int coap_is_bcast(const coap_address_t *a);
|
||||
#endif
|
||||
|
||||
#else /* !WITH_LWIP && !WITH_CONTIKI */
|
||||
/**
|
||||
* Checks if given address @p a denotes a multicast address. This function
|
||||
@@ -180,12 +223,14 @@ COAP_STATIC_INLINE int
|
||||
coap_is_mcast(const coap_address_t *a) {
|
||||
return a && _coap_is_mcast_impl(a);
|
||||
}
|
||||
|
||||
#ifdef COAP_SUPPORT_SOCKET_BROADCAST
|
||||
COAP_STATIC_INLINE int
|
||||
coap_is_bcast(const coap_address_t *a) {
|
||||
return a && _coap_is_bcast_impl(a);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !WITH_LWIP && !WITH_CONTIKI */
|
||||
|
||||
#endif /* COAP_ADDRESS_H_ */
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* async.h -- state management for asynchronous messages
|
||||
*
|
||||
* Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file async.h
|
||||
* @brief State management for asynchronous messages
|
||||
*/
|
||||
|
||||
#ifndef COAP_ASYNC_H_
|
||||
#define COAP_ASYNC_H_
|
||||
|
||||
#include "net.h"
|
||||
|
||||
/**
|
||||
* @defgroup coap_async Asynchronous Messaging
|
||||
* @{
|
||||
* API functions for Async "separate" messages.
|
||||
* A coap_context_t object holds a list of coap_async_t objects that can
|
||||
* be used to generate a separate response in the case a result of a request
|
||||
* cannot be delivered immediately.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns @c 1 if libcoap was built with separate messages enabled,
|
||||
* @c 0 otherwise.
|
||||
*/
|
||||
int coap_async_is_supported(void);
|
||||
|
||||
/**
|
||||
* Allocates a new coap_async_t object and fills its fields according to
|
||||
* the given @p request. This function returns a pointer to the registered
|
||||
* coap_async_t object or @c NULL on error. Note that this function will
|
||||
* return @c NULL in case that an object with the same identifier is already
|
||||
* registered.
|
||||
*
|
||||
* When the delay expires, a copy of the @p request will get sent to the
|
||||
* appropriate request handler.
|
||||
*
|
||||
* @param session The session that is used for asynchronous transmissions.
|
||||
* @param request The request that is handled asynchronously.
|
||||
* @param delay The amount of time to delay before sending response, 0 means
|
||||
* wait forever.
|
||||
*
|
||||
* @return A pointer to the registered coap_async_t object or @c
|
||||
* NULL in case of an error.
|
||||
*/
|
||||
coap_async_t *
|
||||
coap_register_async(coap_session_t *session,
|
||||
const coap_pdu_t *request,
|
||||
coap_tick_t delay);
|
||||
|
||||
/**
|
||||
* Update the delay timeout, so changing when the registered @p async triggers.
|
||||
*
|
||||
* When the new delay expires, a copy of the original request will get sent to
|
||||
* the appropriate request handler.
|
||||
*
|
||||
* @param async The object to update.
|
||||
* @param delay The amount of time to delay before sending response, 0 means
|
||||
* wait forever.
|
||||
*/
|
||||
void
|
||||
coap_async_set_delay(coap_async_t *async, coap_tick_t delay);
|
||||
|
||||
/**
|
||||
* Releases the memory that was allocated by coap_register_async() for the
|
||||
* object @p async.
|
||||
*
|
||||
* @param session The session to use.
|
||||
* @param async The object to delete.
|
||||
*/
|
||||
void
|
||||
coap_free_async(coap_session_t *session, coap_async_t *async);
|
||||
|
||||
/**
|
||||
* Retrieves the object identified by @p token from the list of asynchronous
|
||||
* transactions that are registered with @p context. This function returns a
|
||||
* pointer to that object or @c NULL if not found.
|
||||
*
|
||||
* @param session The session that is used for asynchronous transmissions.
|
||||
* @param token The PDU's token of the object to retrieve.
|
||||
*
|
||||
* @return A pointer to the object identified by @p token or @c NULL if
|
||||
* not found.
|
||||
*/
|
||||
coap_async_t *coap_find_async(coap_session_t *session, coap_bin_const_t token);
|
||||
|
||||
/**
|
||||
* Set the application data pointer held in @p async. This overwrites any
|
||||
* existing data pointer.
|
||||
*
|
||||
* @param async The async state object.
|
||||
* @param app_data The pointer to the data.
|
||||
*/
|
||||
void coap_async_set_app_data(coap_async_t *async, void *app_data);
|
||||
|
||||
/**
|
||||
* Gets the application data pointer held in @p async.
|
||||
*
|
||||
* @param async The async state object.
|
||||
*
|
||||
* @return The applicaton data pointer.
|
||||
*/
|
||||
void *coap_async_get_app_data(const coap_async_t *async);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_ASYNC_H_ */
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* block.h -- block transfer
|
||||
*
|
||||
* Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_BLOCK_H_
|
||||
#define COAP_BLOCK_H_
|
||||
|
||||
#include "encode.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
|
||||
/**
|
||||
* @defgroup block Block Transfer
|
||||
* API functions for handling PDUs using CoAP BLOCK options
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef COAP_MAX_BLOCK_SZX
|
||||
/**
|
||||
* The largest value for the SZX component in a Block option.
|
||||
*/
|
||||
#define COAP_MAX_BLOCK_SZX 6
|
||||
#endif /* COAP_MAX_BLOCK_SZX */
|
||||
|
||||
/**
|
||||
* Structure of Block options.
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int num; /**< block number */
|
||||
unsigned int m:1; /**< 1 if more blocks follow, 0 otherwise */
|
||||
unsigned int szx:3; /**< block size */
|
||||
} coap_block_t;
|
||||
|
||||
#define COAP_BLOCK_USE_LIBCOAP 0x01 /* Use libcoap to do block requests */
|
||||
#define COAP_BLOCK_SINGLE_BODY 0x02 /* Deliver the data as a single body */
|
||||
|
||||
/**
|
||||
* Returns the value of the least significant byte of a Block option @p opt.
|
||||
* For zero-length options (i.e. num == m == szx == 0), COAP_OPT_BLOCK_LAST
|
||||
* returns @c NULL.
|
||||
*/
|
||||
#define COAP_OPT_BLOCK_LAST(opt) \
|
||||
(coap_opt_length(opt) ? (coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
|
||||
|
||||
/** Returns the value of the More-bit of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_MORE(opt) \
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
|
||||
|
||||
/** Returns the value of the SZX-field of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_SZX(opt) \
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
|
||||
|
||||
/**
|
||||
* Returns the value of field @c num in the given block option @p block_opt.
|
||||
*/
|
||||
unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
|
||||
|
||||
/**
|
||||
* Checks if more than @p num blocks are required to deliver @p data_len
|
||||
* bytes of data for a block size of 1 << (@p szx + 4).
|
||||
*/
|
||||
COAP_STATIC_INLINE int
|
||||
coap_more_blocks(size_t data_len, unsigned int num, uint16_t szx) {
|
||||
return ((num+1) << (szx + 4)) < data_len;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/** Sets the More-bit in @p block_opt */
|
||||
COAP_STATIC_INLINE void
|
||||
coap_opt_block_set_m(coap_opt_t *block_opt, int m) {
|
||||
if (m)
|
||||
*(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) |= 0x08;
|
||||
else
|
||||
*(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) &= ~0x08;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initializes @p block from @p pdu. @p number must be either COAP_OPTION_BLOCK1
|
||||
* or COAP_OPTION_BLOCK2. When option @p number was found in @p pdu, @p block is
|
||||
* initialized with values from this option and the function returns the value
|
||||
* @c 1. Otherwise, @c 0 is returned.
|
||||
*
|
||||
* @param pdu The pdu to search for option @p number.
|
||||
* @param number The option number to search for (must be COAP_OPTION_BLOCK1 or
|
||||
* COAP_OPTION_BLOCK2).
|
||||
* @param block The block structure to initilize.
|
||||
*
|
||||
* @return @c 1 on success, @c 0 otherwise.
|
||||
*/
|
||||
int coap_get_block(const coap_pdu_t *pdu, coap_option_num_t number,
|
||||
coap_block_t *block);
|
||||
|
||||
/**
|
||||
* Writes a block option of type @p number to message @p pdu. If the requested
|
||||
* block size is too large to fit in @p pdu, it is reduced accordingly. An
|
||||
* exception is made for the final block when less space is required. The actual
|
||||
* length of the resource is specified in @p data_length.
|
||||
*
|
||||
* This function may change *block to reflect the values written to @p pdu. As
|
||||
* the function takes into consideration the remaining space @p pdu, no more
|
||||
* options should be added after coap_write_block_opt() has returned.
|
||||
*
|
||||
* @param block The block structure to use. On return, this object is
|
||||
* updated according to the values that have been written to
|
||||
* @p pdu.
|
||||
* @param number COAP_OPTION_BLOCK1 or COAP_OPTION_BLOCK2.
|
||||
* @param pdu The message where the block option should be written.
|
||||
* @param data_length The length of the actual data that will be added the @p
|
||||
* pdu by calling coap_add_block().
|
||||
*
|
||||
* @return @c 1 on success, or a negative value on error.
|
||||
*/
|
||||
int coap_write_block_opt(coap_block_t *block,
|
||||
coap_option_num_t number,
|
||||
coap_pdu_t *pdu,
|
||||
size_t data_length);
|
||||
|
||||
/**
|
||||
* Adds the @p block_num block of size 1 << (@p block_szx + 4) from source @p
|
||||
* data to @p pdu.
|
||||
*
|
||||
* @param pdu The message to add the block.
|
||||
* @param len The length of @p data.
|
||||
* @param data The source data to fill the block with.
|
||||
* @param block_num The actual block number.
|
||||
* @param block_szx Encoded size of block @p block_number.
|
||||
*
|
||||
* @return @c 1 on success, @c 0 otherwise.
|
||||
*/
|
||||
int coap_add_block(coap_pdu_t *pdu,
|
||||
size_t len,
|
||||
const uint8_t *data,
|
||||
unsigned int block_num,
|
||||
unsigned char block_szx);
|
||||
|
||||
/**
|
||||
* Re-assemble payloads into a body
|
||||
*
|
||||
* @param body_data The pointer to the data for the body holding the
|
||||
* representation so far or NULL if the first time.
|
||||
* @param length The length of @p data.
|
||||
* @param data The payload data to update the body with.
|
||||
* @param offset The offset of the @p data into the body.
|
||||
* @param total The estimated total size of the body.
|
||||
*
|
||||
* @return The current representation of the body or @c NULL if error.
|
||||
* If NULL, @p body_data will have been de-allocated.
|
||||
*/
|
||||
coap_binary_t *
|
||||
coap_block_build_body(coap_binary_t *body_data, size_t length,
|
||||
const uint8_t *data, size_t offset, size_t total);
|
||||
|
||||
/**
|
||||
* Adds the appropriate part of @p data to the @p response pdu. If blocks are
|
||||
* required, then the appropriate block will be added to the PDU and sent.
|
||||
* Adds a ETAG option that is the hash of the entire data if the data is to be
|
||||
* split into blocks
|
||||
* Used by a request handler.
|
||||
*
|
||||
* Note: The application will get called for every packet of a large body to
|
||||
* process. Consider using coap_add_data_response_large() instead.
|
||||
*
|
||||
* @param request The requesting pdu.
|
||||
* @param response The response pdu.
|
||||
* @param media_type The format of the data.
|
||||
* @param maxage The maxmimum life of the data. If @c -1, then there
|
||||
* is no maxage.
|
||||
* @param length The total length of the data.
|
||||
* @param data The entire data block to transmit.
|
||||
*
|
||||
*/
|
||||
void
|
||||
coap_add_data_blocked_response(const coap_pdu_t *request,
|
||||
coap_pdu_t *response,
|
||||
uint16_t media_type,
|
||||
int maxage,
|
||||
size_t length,
|
||||
const uint8_t* data);
|
||||
|
||||
/**
|
||||
* Callback handler for de-allocating the data based on @p app_ptr provided to
|
||||
* coap_add_data_large_*() functions following transmission of the supplied
|
||||
* data.
|
||||
*
|
||||
* @param session The session that this data is associated with
|
||||
* @param app_ptr The application provided pointer provided to the
|
||||
* coap_add_data_large_* functions.
|
||||
*/
|
||||
typedef void (*coap_release_large_data_t)(coap_session_t *session,
|
||||
void *app_ptr);
|
||||
|
||||
/**
|
||||
* Associates given data with the @p pdu that is passed as second parameter.
|
||||
*
|
||||
* If all the data can be transmitted in a single PDU, this is functionally
|
||||
* the same as coap_add_data() except @p release_func (if not NULL) will get
|
||||
* invoked after data transmission.
|
||||
*
|
||||
* Used for a client request.
|
||||
*
|
||||
* If the data spans multiple PDUs, then the data will get transmitted using
|
||||
* BLOCK1 option with the addition of the SIZE1 option.
|
||||
* The underlying library will handle the transmission of the individual blocks.
|
||||
* Once the body of data has been transmitted (or a failure occurred), then
|
||||
* @p release_func (if not NULL) will get called so the application can
|
||||
* de-allocate the @p data based on @p app_data. It is the responsibility of
|
||||
* the application not to change the contents of @p data until the data
|
||||
* transfer has completed.
|
||||
*
|
||||
* There is no need for the application to include the BLOCK1 option in the
|
||||
* @p pdu.
|
||||
*
|
||||
* coap_add_data_large_request() (or the alternative coap_add_data_large_*()
|
||||
* functions) must be called only once per PDU and must be the last PDU update
|
||||
* before the PDU is transmitted. The (potentially) initial data will get
|
||||
* transmitted when coap_send() is invoked.
|
||||
*
|
||||
* Note: COAP_BLOCK_USE_LIBCOAP must be set by coap_context_set_block_mode()
|
||||
* for libcoap to work correctly when using this function.
|
||||
*
|
||||
* @param session The session to associate the data with.
|
||||
* @param pdu The PDU to associate the data with.
|
||||
* @param length The length of data to transmit.
|
||||
* @param data The data to transmit.
|
||||
* @param release_func The function to call to de-allocate @p data or @c NULL
|
||||
* if the function is not required.
|
||||
* @param app_ptr A Pointer that the application can provide for when
|
||||
* release_func() is called.
|
||||
*
|
||||
* @return @c 1 if addition is successful, else @c 0.
|
||||
*/
|
||||
int coap_add_data_large_request(coap_session_t *session,
|
||||
coap_pdu_t *pdu,
|
||||
size_t length,
|
||||
const uint8_t *data,
|
||||
coap_release_large_data_t release_func,
|
||||
void *app_ptr);
|
||||
|
||||
/**
|
||||
* Associates given data with the @p response pdu that is passed as fourth
|
||||
* parameter.
|
||||
*
|
||||
* If all the data can be transmitted in a single PDU, this is functionally
|
||||
* the same as coap_add_data() except @p release_func (if not NULL) will get
|
||||
* invoked after data transmission. The MEDIA_TYPE, MAXAGE and ETAG options may
|
||||
* be added in as appropriate.
|
||||
*
|
||||
* Used by a server request handler to create the response.
|
||||
*
|
||||
* If the data spans multiple PDUs, then the data will get transmitted using
|
||||
* BLOCK2 (response) option with the addition of the SIZE2 and ETAG
|
||||
* options. The underlying library will handle the transmission of the
|
||||
* individual blocks. Once the body of data has been transmitted (or a
|
||||
* failure occurred), then @p release_func (if not NULL) will get called so the
|
||||
* application can de-allocate the @p data based on @p app_data. It is the
|
||||
* responsibility of the application not to change the contents of @p data
|
||||
* until the data transfer has completed.
|
||||
*
|
||||
* There is no need for the application to include the BLOCK2 option in the
|
||||
* @p pdu.
|
||||
*
|
||||
* coap_add_data_large_response() (or the alternative coap_add_data_large*()
|
||||
* functions) must be called only once per PDU and must be the last PDU update
|
||||
* before returning from the request handler function.
|
||||
*
|
||||
* Note: COAP_BLOCK_USE_LIBCOAP must be set by coap_context_set_block_mode()
|
||||
* for libcoap to work correctly when using this function.
|
||||
*
|
||||
* @param resource The resource the data is associated with.
|
||||
* @param session The coap session.
|
||||
* @param request The requesting pdu.
|
||||
* @param response The response pdu.
|
||||
* @param query The query taken from the (original) requesting pdu.
|
||||
* @param media_type The format of the data.
|
||||
* @param maxage The maxmimum life of the data. If @c -1, then there
|
||||
* is no maxage.
|
||||
* @param etag ETag to use if not 0.
|
||||
* @param length The total length of the data.
|
||||
* @param data The entire data block to transmit.
|
||||
* @param release_func The function to call to de-allocate @p data or NULL if
|
||||
* the function is not required.
|
||||
* @param app_ptr A Pointer that the application can provide for when
|
||||
* release_func() is called.
|
||||
*
|
||||
* @return @c 1 if addition is successful, else @c 0.
|
||||
*/
|
||||
int
|
||||
coap_add_data_large_response(coap_resource_t *resource,
|
||||
coap_session_t *session,
|
||||
const coap_pdu_t *request,
|
||||
coap_pdu_t *response,
|
||||
const coap_string_t *query,
|
||||
uint16_t media_type,
|
||||
int maxage,
|
||||
uint64_t etag,
|
||||
size_t length,
|
||||
const uint8_t *data,
|
||||
coap_release_large_data_t release_func,
|
||||
void *app_ptr);
|
||||
|
||||
/**
|
||||
* Set the context level CoAP block handling bits for handling RFC7959.
|
||||
* These bits flow down to a session when a session is created and if the peer
|
||||
* does not support something, an appropriate bit may get disabled in the
|
||||
* session block_mode.
|
||||
* The session block_mode then flows down into coap_crcv_t or coap_srcv_t where
|
||||
* again an appropriate bit may get disabled.
|
||||
*
|
||||
* Note: This function must be called before the session is set up.
|
||||
*
|
||||
* Note: COAP_BLOCK_USE_LIBCOAP must be set if libcoap is to do all the
|
||||
* block tracking and requesting, otherwise the application will have to do
|
||||
* all of this work (the default if coap_context_set_block_mode() is not
|
||||
* called).
|
||||
*
|
||||
* @param context The coap_context_t object.
|
||||
* @param block_mode Zero or more COAP_BLOCK_ or'd options
|
||||
*/
|
||||
void coap_context_set_block_mode(coap_context_t *context,
|
||||
uint8_t block_mode);
|
||||
|
||||
/**
|
||||
* Cancel an observe that is being tracked by the client large receive logic.
|
||||
* (coap_context_set_block_mode() has to be called)
|
||||
* This will trigger the sending of an observe cancel pdu to the server.
|
||||
*
|
||||
* @param session The session that is being used for the observe.
|
||||
* @param token The original token used to initiate the observation.
|
||||
* @param message_type The COAP_MESSAGE_ type (NON or CON) to send the observe
|
||||
* cancel pdu as.
|
||||
*
|
||||
* @return @c 1 if observe cancel transmission initiation is successful,
|
||||
* else @c 0.
|
||||
*/
|
||||
int coap_cancel_observe(coap_session_t *session, coap_binary_t *token,
|
||||
coap_pdu_type_t message_type);
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif /* COAP_BLOCK_H_ */
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* coap.h -- main header file for CoAP stack of libcoap
|
||||
*
|
||||
* Copyright (C) 2010-2012,2015-2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
* 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
*
|
||||
* 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.0"
|
||||
|
||||
/* 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.0"
|
||||
|
||||
/* Define the numeric version identifier for libcoap */
|
||||
#define LIBCOAP_VERSION (4003000U)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "coap3/libcoap.h"
|
||||
#include "securec.h"
|
||||
|
||||
#include "coap3/coap_forward_decls.h"
|
||||
#include "coap3/address.h"
|
||||
#include "coap3/async.h"
|
||||
#include "coap3/block.h"
|
||||
#include "coap3/coap_cache.h"
|
||||
#include "coap3/coap_debug.h"
|
||||
#include "coap3/coap_dtls.h"
|
||||
#include "coap3/coap_event.h"
|
||||
#include "coap3/coap_io.h"
|
||||
#include "coap3/coap_io_internal.h"
|
||||
#include "coap3/coap_prng.h"
|
||||
#include "coap3/coap_time.h"
|
||||
#include "coap3/encode.h"
|
||||
#include "coap3/mem.h"
|
||||
#include "coap3/net.h"
|
||||
#include "coap3/option.h"
|
||||
#include "coap3/pdu.h"
|
||||
#include "coap3/resource.h"
|
||||
#include "coap3/str.h"
|
||||
#include "coap3/subscribe.h"
|
||||
#include "coap3/uri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COAP_H_ */
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* coap.h -- main header file for CoAP stack of libcoap
|
||||
*
|
||||
* Copyright (C) 2010-2012,2015-2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
* 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
*
|
||||
* 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 "coap@LIBCOAP_API_VERSION@/libcoap.h"
|
||||
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_forward_decls.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/address.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/async.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/block.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_cache.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_debug.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_dtls.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_event.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_io.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_prng.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_time.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/encode.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/mem.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/net.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/option.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/pdu.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/resource.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/str.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/subscribe.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/uri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COAP_H_ */
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* coap.h -- main header file for CoAP stack of libcoap
|
||||
*
|
||||
* Copyright (C) 2010-2012,2015-2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
* 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
*
|
||||
* 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.0"
|
||||
|
||||
/* 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.0"
|
||||
|
||||
/* Define the numeric version identifier for libcoap */
|
||||
#define LIBCOAP_VERSION (4003000U)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "coap3/libcoap.h"
|
||||
|
||||
#include "coap3/coap_forward_decls.h"
|
||||
#include "coap3/address.h"
|
||||
#include "coap3/async.h"
|
||||
#include "coap3/block.h"
|
||||
#include "coap3/coap_cache.h"
|
||||
#include "coap3/coap_debug.h"
|
||||
#include "coap3/coap_dtls.h"
|
||||
#include "coap3/coap_event.h"
|
||||
#include "coap3/coap_io.h"
|
||||
#include "coap3/coap_prng.h"
|
||||
#include "coap3/coap_time.h"
|
||||
#include "coap3/encode.h"
|
||||
#include "coap3/mem.h"
|
||||
#include "coap3/net.h"
|
||||
#include "coap3/option.h"
|
||||
#include "coap3/pdu.h"
|
||||
#include "coap3/resource.h"
|
||||
#include "coap3/str.h"
|
||||
#include "coap3/subscribe.h"
|
||||
#include "coap3/uri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COAP_H_ */
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* coap.h -- main header file for CoAP stack of libcoap
|
||||
*
|
||||
* Copyright (C) 2010-2012,2015-2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
* 2015 Carsten Schoenert <c.schoenert@t-online.de>
|
||||
*
|
||||
* 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 "coap@LIBCOAP_API_VERSION@/libcoap.h"
|
||||
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_forward_decls.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/address.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/async.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/block.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_cache.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_debug.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_dtls.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_event.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_io.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_prng.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/coap_time.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/encode.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/mem.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/net.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/option.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/pdu.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/resource.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/str.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/subscribe.h"
|
||||
#include "coap@LIBCOAP_API_VERSION@/uri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COAP_H_ */
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* coap_asn1_internal.h -- ASN.1 functions for libcoap
|
||||
*
|
||||
* Copyright (C) 2020 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_asn1_internal.h
|
||||
* @brief COAP ASN.1 internal information
|
||||
*/
|
||||
|
||||
#ifndef COAP_ASN1_INTERNAL_H_
|
||||
#define COAP_ASN1_INTERNAL_H_
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup asn1 ASN.1 Support (Internal)
|
||||
* CoAP ASN.1 Structures, Enums and Functions that are not exposed to
|
||||
* applications
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
COAP_ASN1_NONE = 0,
|
||||
COAP_ASN1_INTEGER = 2,
|
||||
COAP_ASN1_BITSTRING = 3,
|
||||
COAP_ASN1_OCTETSTRING = 4,
|
||||
COAP_ASN1_IDENTIFIER = 6,
|
||||
} coap_asn1_tag_t;
|
||||
|
||||
/**
|
||||
* Callback to validate the asn1 tag and data.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param data The start of the tag and data
|
||||
* @param size The size of the tag and data
|
||||
*
|
||||
* @return @c 1 if pass, else @c 0 if fail
|
||||
*/
|
||||
typedef int (*asn1_validate)(const uint8_t *data, size_t size);
|
||||
|
||||
/**
|
||||
* Get the asn1 length from the current @p ptr.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param ptr The current asn.1 object length pointer
|
||||
*
|
||||
* @return The length of the asn.1 object. @p ptr is updated to be after the length.
|
||||
*/
|
||||
size_t asn1_len(const uint8_t **ptr);
|
||||
|
||||
/**
|
||||
* Get the asn1 tag from the current @p ptr.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param ptr The current asn.1 object tag pointer
|
||||
* @param constructed 1 if current tag is constructed
|
||||
* @param class The current class of the tag
|
||||
*
|
||||
* @return The tag value.@p ptr is updated to be after the tag.
|
||||
*/
|
||||
coap_asn1_tag_t asn1_tag_c(const uint8_t **ptr, int *constructed, int *class);
|
||||
|
||||
/**
|
||||
* Get the asn1 tag and data from the current @p ptr.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param ltag The tag to look for
|
||||
* @param ptr The current asn.1 object pointer
|
||||
* @param tlen The remaining size oof the asn.1 data
|
||||
* @param validate Call validate to verify tag data or @c NULL
|
||||
*
|
||||
* @return The asn.1 tag and data or @c NULL if not found
|
||||
*/
|
||||
coap_binary_t *get_asn1_tag(coap_asn1_tag_t ltag, const uint8_t *ptr,
|
||||
size_t tlen, asn1_validate validate);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_ASN1_INTERNAL_H_ */
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* coap_async_internal.h -- state management for asynchronous messages
|
||||
*
|
||||
* Copyright (C) 2010-2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_async_internal.h
|
||||
* @brief CoAP async internal information
|
||||
*/
|
||||
|
||||
#ifndef COAP_ASYNC_INTERNAL_H_
|
||||
#define COAP_ASYNC_INTERNAL_H_
|
||||
|
||||
#include "coap3/net.h"
|
||||
|
||||
#ifndef WITHOUT_ASYNC
|
||||
|
||||
/**
|
||||
* @defgroup coap_async_internal Asynchronous Messaging (Internal)
|
||||
* @{
|
||||
* CoAP Async Structures, Enums and Functions that are not exposed to
|
||||
* applications.
|
||||
* A coap_context_t object holds a list of coap_async_t objects that can be
|
||||
* used to generate a separate response in the case a result of a request cannot
|
||||
* be delivered immediately.
|
||||
*/
|
||||
struct coap_async_t {
|
||||
struct coap_async_t *next; /**< internally used for linking */
|
||||
coap_tick_t delay; /**< When to delay to before triggering the response
|
||||
0 indicates never trigger */
|
||||
coap_session_t *session; /**< transaction session */
|
||||
coap_pdu_t *pdu; /**< copy of request pdu */
|
||||
void* appdata; /** User definable data pointer */
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if there are any pending Async requests - if so, send them off.
|
||||
* Otherewise return the time remaining for the next Async to be triggered
|
||||
* or 0 if nothing to do.
|
||||
*
|
||||
* @param context The current context.
|
||||
* @param now The current time in ticks.
|
||||
*
|
||||
* @return The tick time before the next Async needs to go, else 0 if
|
||||
* nothing to do.
|
||||
*/
|
||||
coap_tick_t coap_check_async(coap_context_t *context, coap_tick_t now);
|
||||
|
||||
/**
|
||||
* Removes and frees off all of the async entries for the given context.
|
||||
*
|
||||
* @param context The context to remove all async entries from.
|
||||
*/
|
||||
void
|
||||
coap_delete_all_async(coap_context_t *context);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* WITHOUT_ASYNC */
|
||||
|
||||
#endif /* COAP_ASYNC_INTERNAL_H_ */
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* coap_block_internal.h -- Structures, Enums & Functions that are not
|
||||
* exposed to application programming
|
||||
*
|
||||
* Copyright (C) 2010-2021 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2021 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_block_internal.h
|
||||
* @brief COAP block internal information
|
||||
*/
|
||||
|
||||
#ifndef COAP_BLOCK_INTERNAL_H_
|
||||
#define COAP_BLOCK_INTERNAL_H_
|
||||
|
||||
#include "coap_pdu_internal.h"
|
||||
#include "resource.h"
|
||||
|
||||
/**
|
||||
* @defgroup block_internal Block (Internal)
|
||||
* Structures, Enums and Functions that are not exposed to applications
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
COAP_RECURSE_OK,
|
||||
COAP_RECURSE_NO
|
||||
} coap_recurse_t;
|
||||
|
||||
struct coap_lg_range {
|
||||
uint32_t begin;
|
||||
uint32_t end;
|
||||
};
|
||||
|
||||
#define COAP_RBLOCK_CNT 4
|
||||
/**
|
||||
* Structure to keep track of received blocks
|
||||
*/
|
||||
typedef struct coap_rblock_t {
|
||||
uint32_t used;
|
||||
uint32_t retry;
|
||||
struct coap_lg_range range[COAP_RBLOCK_CNT];
|
||||
coap_tick_t last_seen;
|
||||
} coap_rblock_t;
|
||||
|
||||
/**
|
||||
* Structure to keep track of block1 specific information
|
||||
* (Requests)
|
||||
*/
|
||||
typedef struct coap_l_block1_t {
|
||||
coap_binary_t *app_token; /**< original PDU token */
|
||||
uint8_t token[8]; /**< last used token */
|
||||
size_t token_length; /**< length of token */
|
||||
uint32_t count; /**< the number of packets sent for payload */
|
||||
} coap_l_block1_t;
|
||||
|
||||
/**
|
||||
* Structure to keep track of block2 specific information
|
||||
* (Responses)
|
||||
*/
|
||||
typedef struct coap_l_block2_t {
|
||||
coap_resource_t *resource; /**< associated resource */
|
||||
coap_string_t *query; /**< Associated query for the resource */
|
||||
uint64_t etag; /**< ETag value */
|
||||
coap_time_t maxage_expire; /**< When this entry expires */
|
||||
} coap_l_block2_t;
|
||||
|
||||
/**
|
||||
* Structure to hold large body (many blocks) transmission information
|
||||
*/
|
||||
struct coap_lg_xmit_t {
|
||||
struct coap_lg_xmit_t *next;
|
||||
uint8_t blk_size; /**< large block transmission size */
|
||||
uint16_t option; /**< large block transmisson CoAP option */
|
||||
int last_block; /**< last acknowledged block number */
|
||||
const uint8_t *data; /**< large data ptr */
|
||||
size_t length; /**< large data length */
|
||||
size_t offset; /**< large data next offset to transmit */
|
||||
union {
|
||||
coap_l_block1_t b1;
|
||||
coap_l_block2_t b2;
|
||||
} b;
|
||||
coap_pdu_t pdu; /**< skeletal PDU */
|
||||
coap_tick_t last_payload; /**< Last time MAX_PAYLOAD was sent or 0 */
|
||||
coap_tick_t last_used; /**< Last time all data sent or 0 */
|
||||
coap_release_large_data_t release_func; /**< large data de-alloc function */
|
||||
void *app_ptr; /**< applicaton provided ptr for de-alloc function */
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure to hold large body (many blocks) client receive information
|
||||
*/
|
||||
struct coap_lg_crcv_t {
|
||||
struct coap_lg_crcv_t *next;
|
||||
uint8_t observe[3]; /**< Observe data (if set) (only 24 bits) */
|
||||
uint8_t observe_length;/**< Length of observe data */
|
||||
uint8_t observe_set; /**< Set if this is an observe receive PDU */
|
||||
uint8_t etag_set; /**< Set if ETag is in receive PDU */
|
||||
uint8_t etag_length; /**< ETag length */
|
||||
uint8_t etag[8]; /**< ETag for block checking */
|
||||
uint16_t content_format; /**< Content format for the set of blocks */
|
||||
uint8_t last_type; /**< Last request type (CON/NON) */
|
||||
uint8_t initial; /**< If set, has not been used yet */
|
||||
uint8_t szx; /**< size of individual blocks */
|
||||
size_t total_len; /**< Length as indicated by SIZE2 option */
|
||||
coap_binary_t *body_data; /**< Used for re-assembling entire body */
|
||||
coap_binary_t *app_token; /**< app requesting PDU token */
|
||||
uint8_t base_token[8]; /**< established base PDU token */
|
||||
size_t base_token_length; /**< length of token */
|
||||
uint8_t token[8]; /**< last used token */
|
||||
size_t token_length; /**< length of token */
|
||||
coap_pdu_t pdu; /**< skeletal PDU */
|
||||
coap_rblock_t rec_blocks; /** < list of received blocks */
|
||||
coap_tick_t last_used; /**< Last time all data sent or 0 */
|
||||
uint16_t block_option; /**< Block option in use */
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure to hold large body (many blocks) server receive information
|
||||
*/
|
||||
struct coap_lg_srcv_t {
|
||||
struct coap_lg_srcv_t *next;
|
||||
uint8_t observe[3]; /**< Observe data (if set) (only 24 bits) */
|
||||
uint8_t observe_length;/**< Length of observe data */
|
||||
uint8_t observe_set; /**< Set if this is an observe receive PDU */
|
||||
uint8_t rtag_set; /**< Set if RTag is in receive PDU */
|
||||
uint8_t rtag_length; /**< RTag length */
|
||||
uint8_t rtag[8]; /**< RTag for block checking */
|
||||
uint16_t content_format; /**< Content format for the set of blocks */
|
||||
uint8_t last_type; /**< Last request type (CON/NON) */
|
||||
uint8_t szx; /**< size of individual blocks */
|
||||
size_t total_len; /**< Length as indicated by SIZE1 option */
|
||||
coap_binary_t *body_data; /**< Used for re-assembling entire body */
|
||||
size_t amount_so_far; /**< Amount of data seen so far */
|
||||
coap_resource_t *resource; /**< associated resource */
|
||||
coap_str_const_t *uri_path; /** set to uri_path if unknown resource */
|
||||
coap_rblock_t rec_blocks; /** < list of received blocks */
|
||||
uint8_t last_token[8]; /**< last used token */
|
||||
size_t last_token_length; /**< length of token */
|
||||
coap_mid_t last_mid; /**< Last received mid for this set of packets */
|
||||
coap_tick_t last_used; /**< Last time data sent or 0 */
|
||||
uint16_t block_option; /**< Block option in use */
|
||||
};
|
||||
|
||||
coap_lg_crcv_t * coap_block_new_lg_crcv(coap_session_t *session,
|
||||
coap_pdu_t *pdu);
|
||||
|
||||
void coap_block_delete_lg_crcv(coap_session_t *session,
|
||||
coap_lg_crcv_t *lg_crcv);
|
||||
|
||||
coap_tick_t coap_block_check_lg_crcv_timeouts(coap_session_t *session,
|
||||
coap_tick_t now);
|
||||
|
||||
void coap_block_delete_lg_srcv(coap_session_t *session,
|
||||
coap_lg_srcv_t *lg_srcv);
|
||||
|
||||
coap_tick_t coap_block_check_lg_srcv_timeouts(coap_session_t *session,
|
||||
coap_tick_t now);
|
||||
|
||||
int coap_handle_request_send_block(coap_session_t *session,
|
||||
coap_pdu_t *pdu,
|
||||
coap_pdu_t *response,
|
||||
coap_resource_t *resource,
|
||||
coap_string_t *query);
|
||||
|
||||
int coap_handle_request_put_block(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *pdu,
|
||||
coap_pdu_t *response,
|
||||
coap_resource_t *resource,
|
||||
coap_string_t *uri_path,
|
||||
coap_opt_t *observe,
|
||||
coap_string_t *query,
|
||||
coap_method_handler_t h,
|
||||
int *added_block);
|
||||
|
||||
int coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *rcvd);
|
||||
|
||||
int coap_handle_response_get_block(coap_context_t *context,
|
||||
coap_session_t *session,
|
||||
coap_pdu_t *sent,
|
||||
coap_pdu_t *rcvd,
|
||||
coap_recurse_t recursive);
|
||||
|
||||
void coap_block_delete_lg_xmit(coap_session_t *session,
|
||||
coap_lg_xmit_t *lg_xmit);
|
||||
|
||||
/**
|
||||
* The function that does all the work for the coap_add_data_large*()
|
||||
* functions.
|
||||
*
|
||||
* @param session The session to associate the data with.
|
||||
* @param pdu The PDU to associate the data with.
|
||||
* @param resource The resource to associate the data with (BLOCK2).
|
||||
* @param query The query to associate the data with (BLOCK2).
|
||||
* @param maxage The maxmimum life of the data. If @c -1, then there
|
||||
* is no maxage (BLOCK2).
|
||||
* @param etag ETag to use if not 0 (BLOCK2).
|
||||
* @param length The length of data to transmit.
|
||||
* @param data The data to transmit.
|
||||
* @param release_func The function to call to de-allocate @p data or NULL if
|
||||
* the function is not required.
|
||||
* @param app_ptr A Pointer that the application can provide for when
|
||||
* release_func() is called.
|
||||
*
|
||||
* @return @c 1 if transmission initiation is successful, else @c 0.
|
||||
*/
|
||||
int coap_add_data_large_internal(coap_session_t *session,
|
||||
coap_pdu_t *pdu,
|
||||
coap_resource_t *resource,
|
||||
const coap_string_t *query,
|
||||
int maxage,
|
||||
uint64_t etag,
|
||||
size_t length,
|
||||
const uint8_t *data,
|
||||
coap_release_large_data_t release_func,
|
||||
void *app_ptr);
|
||||
|
||||
/**
|
||||
* The function checks that the code in a newly formed lg_xmit created by
|
||||
* coap_add_data_large_response() is updated.
|
||||
*
|
||||
* @param session The session
|
||||
* @param response The response PDU to to check
|
||||
* @param resource The requested resource
|
||||
* @param query The requested query
|
||||
*/
|
||||
void coap_check_code_lg_xmit(coap_session_t *session, coap_pdu_t *response,
|
||||
coap_resource_t *resource, coap_string_t *query);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_BLOCK_INTERNAL_H_ */
|
||||
@@ -0,0 +1,232 @@
|
||||
/* coap_cache.h -- Caching of CoAP requests
|
||||
*
|
||||
* Copyright (C) 2020 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_cache.h
|
||||
* @brief Provides a simple cache request storage for CoAP requests
|
||||
*/
|
||||
|
||||
#ifndef COAP_CACHE_H_
|
||||
#define COAP_CACHE_H_
|
||||
|
||||
#include "coap_forward_decls.h"
|
||||
|
||||
/**
|
||||
* @defgroup cache Cache Support
|
||||
* API functions for CoAP Caching
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Callback to free off the app data when the cache-entry is
|
||||
* being deleted / freed off.
|
||||
*
|
||||
* @param data The app data to be freed off.
|
||||
*/
|
||||
typedef void (*coap_cache_app_data_free_callback_t)(void *data);
|
||||
|
||||
typedef enum coap_cache_session_based_t {
|
||||
COAP_CACHE_NOT_SESSION_BASED,
|
||||
COAP_CACHE_IS_SESSION_BASED
|
||||
} coap_cache_session_based_t;
|
||||
|
||||
typedef enum coap_cache_record_pdu_t {
|
||||
COAP_CACHE_NOT_RECORD_PDU,
|
||||
COAP_CACHE_RECORD_PDU
|
||||
} coap_cache_record_pdu_t;
|
||||
|
||||
/**
|
||||
* Calculates a cache-key for the given CoAP PDU. See
|
||||
* https://tools.ietf.org/html/rfc7252#section-5.6
|
||||
* for an explanation of CoAP cache keys.
|
||||
*
|
||||
* Specific CoAP options can be removed from the cache-key. Examples of
|
||||
* this are the BLOCK1 and BLOCK2 options - which make no real sense including
|
||||
* them in a client or server environment, but should be included in a proxy
|
||||
* caching environment where things are cached on a per block basis.
|
||||
* This is done globally by calling the coap_cache_ignore_options()
|
||||
* function.
|
||||
*
|
||||
* NOTE: The returned cache-key needs to be freed off by the caller by
|
||||
* calling coap_cache_delete_key().
|
||||
*
|
||||
* @param session The session to add into cache-key if @p session_based
|
||||
* is set.
|
||||
* @param pdu The CoAP PDU for which a cache-key is to be
|
||||
* calculated.
|
||||
* @param session_based COAP_CACHE_IS_SESSION_BASED if session based
|
||||
* cache-key, else COAP_CACHE_NOT_SESSION_BASED.
|
||||
*
|
||||
* @return The returned cache-key or @c NULL if failure.
|
||||
*/
|
||||
coap_cache_key_t *coap_cache_derive_key(const coap_session_t *session,
|
||||
const coap_pdu_t *pdu,
|
||||
coap_cache_session_based_t session_based);
|
||||
|
||||
/**
|
||||
* Calculates a cache-key for the given CoAP PDU. See
|
||||
* https://tools.ietf.org/html/rfc7252#section-5.6
|
||||
* for an explanation of CoAP cache keys.
|
||||
*
|
||||
* Specific CoAP options can be removed from the cache-key. Examples of
|
||||
* this are the BLOCK1 and BLOCK2 options - which make no real sense including
|
||||
* them in a client or server environment, but should be included in a proxy
|
||||
* caching environment where things are cached on a per block basis.
|
||||
* This is done individually by specifying @p cache_ignore_count and
|
||||
* @p cache_ignore_options .
|
||||
*
|
||||
* NOTE: The returned cache-key needs to be freed off by the caller by
|
||||
* calling coap_cache_delete_key().
|
||||
*
|
||||
* @param session The session to add into cache-key if @p session_based
|
||||
* is set.
|
||||
* @param pdu The CoAP PDU for which a cache-key is to be
|
||||
* calculated.
|
||||
* @param session_based COAP_CACHE_IS_SESSION_BASED if session based
|
||||
* cache-key, else COAP_CACHE_NOT_SESSION_BASED.
|
||||
* @param ignore_options The array of options to ignore.
|
||||
* @param ignore_count The number of options to ignore.
|
||||
*
|
||||
* @return The returned cache-key or @c NULL if failure.
|
||||
*/
|
||||
coap_cache_key_t *coap_cache_derive_key_w_ignore(const coap_session_t *session,
|
||||
const coap_pdu_t *pdu,
|
||||
coap_cache_session_based_t session_based,
|
||||
const uint16_t *ignore_options,
|
||||
size_t ignore_count);
|
||||
|
||||
/**
|
||||
* Delete the cache-key.
|
||||
*
|
||||
* @param cache_key The cache-key to delete.
|
||||
*/
|
||||
void coap_delete_cache_key(coap_cache_key_t *cache_key);
|
||||
|
||||
/**
|
||||
* Define the CoAP options that are not to be included when calculating
|
||||
* the cache-key. Options that are defined as Non-Cache and the Observe
|
||||
* option are always ignored.
|
||||
*
|
||||
* @param context The context to save the ignored options information in.
|
||||
* @param options The array of options to ignore.
|
||||
* @param count The number of options to ignore. Use 0 to reset the
|
||||
* options matching.
|
||||
*
|
||||
* @return @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
int coap_cache_ignore_options(coap_context_t *context,
|
||||
const uint16_t *options, size_t count);
|
||||
|
||||
/**
|
||||
* Create a new cache-entry hash keyed by cache-key derived from the PDU.
|
||||
*
|
||||
* If @p session_based is set, then this cache-entry will get deleted when
|
||||
* the session is freed off.
|
||||
* If @p record_pdu is set, then the copied PDU will get freed off when
|
||||
* this cache-entry is deleted.
|
||||
*
|
||||
* The cache-entry is maintained on a context hash list.
|
||||
*
|
||||
* @param session The session to use to derive the context from.
|
||||
* @param pdu The pdu to use to generate the cache-key.
|
||||
* @param record_pdu COAP_CACHE_RECORD_PDU if to take a copy of the PDU for
|
||||
* later use, else COAP_CACHE_NOT_RECORD_PDU.
|
||||
* @param session_based COAP_CACHE_IS_SESSION_BASED if to associate this
|
||||
* cache-entry with the the session (which is embedded
|
||||
* in the cache-entry), else COAP_CACHE_NOT_SESSION_BASED.
|
||||
* @param idle_time Idle time in seconds before cache-entry is expired.
|
||||
* If set to 0, it does not expire (but will get
|
||||
* deleted if the session is deleted and it is session_based).
|
||||
*
|
||||
* @return The returned cache-key or @c NULL if failure.
|
||||
*/
|
||||
coap_cache_entry_t *coap_new_cache_entry(coap_session_t *session,
|
||||
const coap_pdu_t *pdu,
|
||||
coap_cache_record_pdu_t record_pdu,
|
||||
coap_cache_session_based_t session_based,
|
||||
unsigned int idle_time);
|
||||
|
||||
/**
|
||||
* Remove a cache-entry from the hash list and free off all the appropriate
|
||||
* contents apart from app_data.
|
||||
*
|
||||
* @param context The context to use.
|
||||
* @param cache_entry The cache-entry to remove.
|
||||
*/
|
||||
void coap_delete_cache_entry(coap_context_t *context,
|
||||
coap_cache_entry_t *cache_entry);
|
||||
|
||||
/**
|
||||
* Searches for a cache-entry identified by @p cache_key. This
|
||||
* function returns the corresponding cache-entry or @c NULL
|
||||
* if not found.
|
||||
*
|
||||
* @param context The context to use.
|
||||
* @param cache_key The cache-key to get the hashed coap-entry.
|
||||
*
|
||||
* @return The cache-entry for @p cache_key or @c NULL if not found.
|
||||
*/
|
||||
coap_cache_entry_t *coap_cache_get_by_key(coap_context_t *context,
|
||||
const coap_cache_key_t *cache_key);
|
||||
|
||||
/**
|
||||
* Searches for a cache-entry corresponding to @p pdu. This
|
||||
* function returns the corresponding cache-entry or @c NULL if not
|
||||
* found.
|
||||
*
|
||||
* @param session The session to use.
|
||||
* @param pdu The CoAP request to search for.
|
||||
* @param session_based COAP_CACHE_IS_SESSION_BASED if session based
|
||||
* cache-key to be used, else COAP_CACHE_NOT_SESSION_BASED.
|
||||
*
|
||||
* @return The cache-entry for @p request or @c NULL if not found.
|
||||
*/
|
||||
coap_cache_entry_t *coap_cache_get_by_pdu(coap_session_t *session,
|
||||
const coap_pdu_t *pdu,
|
||||
coap_cache_session_based_t session_based);
|
||||
|
||||
/**
|
||||
* Returns the PDU information stored in the @p coap_cache entry.
|
||||
*
|
||||
* @param cache_entry The CoAP cache entry.
|
||||
*
|
||||
* @return The PDU information stored in the cache_entry or NULL
|
||||
* if the PDU was not initially copied.
|
||||
*/
|
||||
const coap_pdu_t *coap_cache_get_pdu(const coap_cache_entry_t *cache_entry);
|
||||
|
||||
/**
|
||||
* Stores @p data with the given cache entry. This function
|
||||
* overwrites any value that has previously been stored with @p
|
||||
* cache_entry.
|
||||
*
|
||||
* @param cache_entry The CoAP cache entry.
|
||||
* @param data The data pointer to store with wih the cache entry. Note that
|
||||
* this data must be valid during the lifetime of @p cache_entry.
|
||||
* @param callback The callback to call to free off this data when the
|
||||
* cache-entry is deleted, or @c NULL if not required.
|
||||
*/
|
||||
void coap_cache_set_app_data(coap_cache_entry_t *cache_entry, void *data,
|
||||
coap_cache_app_data_free_callback_t callback);
|
||||
|
||||
/**
|
||||
* Returns any application-specific data that has been stored with @p
|
||||
* cache_entry using the function coap_cache_set_app_data(). This function will
|
||||
* return @c NULL if no data has been stored.
|
||||
*
|
||||
* @param cache_entry The CoAP cache entry.
|
||||
*
|
||||
* @return The data pointer previously stored or @c NULL if no data stored.
|
||||
*/
|
||||
void *coap_cache_get_app_data(const coap_cache_entry_t *cache_entry);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_CACHE_H */
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* coap_cache_internal.h -- Cache functions for libcoap
|
||||
*
|
||||
* Copyright (C) 2019--2020 Olaf Bergmann <bergmann@tzi.org> and others
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_cache_internal.h
|
||||
* @brief COAP cache internal information
|
||||
*/
|
||||
|
||||
#ifndef COAP_CACHE_INTERNAL_H_
|
||||
#define COAP_CACHE_INTERNAL_H_
|
||||
|
||||
#include "coap_io.h"
|
||||
|
||||
/**
|
||||
* @defgroup cache_internal Cache Support (Internal)
|
||||
* CoAP Cache Structures, Enums and Functions that are not exposed to
|
||||
* applications
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Holds a digest in binary typically sha256 except for notls */
|
||||
typedef struct coap_digest_t {
|
||||
uint8_t key[32];
|
||||
} coap_digest_t;
|
||||
|
||||
struct coap_cache_key_t {
|
||||
uint8_t key[32];
|
||||
};
|
||||
|
||||
struct coap_cache_entry_t {
|
||||
UT_hash_handle hh;
|
||||
coap_cache_key_t *cache_key;
|
||||
coap_session_t *session;
|
||||
coap_pdu_t *pdu;
|
||||
void* app_data;
|
||||
coap_tick_t expire_ticks;
|
||||
unsigned int idle_timeout;
|
||||
coap_cache_app_data_free_callback_t callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expire coap_cache_entry_t entries
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param context The context holding the coap-entries to exire
|
||||
*/
|
||||
void coap_expire_cache_entries(coap_context_t *context);
|
||||
|
||||
typedef void coap_digest_ctx_t;
|
||||
|
||||
/**
|
||||
* Initialize a coap_digest
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @return The digest context or @c NULL if failure.
|
||||
*/
|
||||
coap_digest_ctx_t *coap_digest_setup(void);
|
||||
|
||||
/**
|
||||
* Free off coap_digest_ctx_t. Always done by
|
||||
* coap_digest_final()
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param digest_ctx The coap_digest context.
|
||||
*/
|
||||
void coap_digest_free(coap_digest_ctx_t *digest_ctx);
|
||||
|
||||
/**
|
||||
* Update the coap_digest information with the next chunk of data
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param digest_ctx The coap_digest context.
|
||||
* @param data Pointer to data.
|
||||
* @param data_len Number of bytes.
|
||||
*
|
||||
* @return @c 1 success, @c 0 failure.
|
||||
*/
|
||||
int coap_digest_update(coap_digest_ctx_t *digest_ctx,
|
||||
const uint8_t *data,
|
||||
size_t data_len
|
||||
);
|
||||
|
||||
/**
|
||||
* Finalize the coap_digest information into the provided
|
||||
* @p digest_buffer.
|
||||
*
|
||||
* Internal function.
|
||||
*
|
||||
* @param digest_ctx The coap_digest context.
|
||||
* @param digest_buffer Pointer to digest buffer to update
|
||||
*
|
||||
* @return @c 1 success, @c 0 failure.
|
||||
*/
|
||||
int coap_digest_final(coap_digest_ctx_t *digest_ctx,
|
||||
coap_digest_t *digest_buffer);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_CACHE_INTERNAL_H_ */
|
||||
@@ -1,9 +1,3 @@
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#define COAP_SUPPORT_SOCKET_BROADCAST 1
|
||||
#define COAP_USER_DEFAULT_PORT 5684
|
||||
|
||||
/* coap_config.h. Generated from coap_config.h.in by configure. */
|
||||
/* coap_config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
@@ -13,10 +7,11 @@
|
||||
/* Define if the system has small stack size */
|
||||
/* #undef COAP_CONSTRAINED_STACK */
|
||||
|
||||
/* Define to 1 to build without TCP support. */
|
||||
#define COAP_DISABLE_TCP 1
|
||||
|
||||
/* Define if the system has epoll support */
|
||||
#ifdef COAP_EPOLL_SUPPORT
|
||||
#undef COAP_EPOLL_SUPPORT
|
||||
#endif
|
||||
/* #undef COAP_EPOLL_SUPPORT */
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#define HAVE_ARPA_INET_H 1
|
||||
@@ -30,6 +25,12 @@
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#define HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the `getrandom' function. */
|
||||
/* #undef HAVE_GETRANDOM 1 */
|
||||
|
||||
/* Define to 1 if you have the `if_nametoindex' function. */
|
||||
#define HAVE_IF_NAMETOINDEX 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
@@ -48,6 +49,9 @@
|
||||
/* Define to 1 if you have the `malloc' function. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define if the system has libmbedtls2.7.10 */
|
||||
/* #undef HAVE_MBEDTLS */
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
@@ -60,6 +64,9 @@
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#define HAVE_NETINET_IN_H 1
|
||||
|
||||
/* Define to 1 if you have the <net/if.h> header file. */
|
||||
#define HAVE_NET_IF_H 1
|
||||
|
||||
/* Define if the system has libssl1.1 */
|
||||
/* #undef HAVE_OPENSSL */
|
||||
|
||||
@@ -97,7 +104,7 @@
|
||||
#define HAVE_STRRCHR 1
|
||||
|
||||
/* Define to 1 if the system has the type `struct cmsghdr'. */
|
||||
/* #undef HAVE_STRUCT_CMSGHDR */
|
||||
// #define HAVE_STRUCT_CMSGHDR 1
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#define HAVE_SYSLOG_H 1
|
||||
@@ -130,7 +137,7 @@
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
||||
/* Define to 1 if assertions should be disabled. */
|
||||
/* #undef NDEBUG */
|
||||
#define NDEBUG 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net"
|
||||
@@ -139,7 +146,7 @@
|
||||
#define PACKAGE_NAME "libcoap"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libcoap 4.2.1"
|
||||
#define PACKAGE_STRING "libcoap 4.3.0"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libcoap"
|
||||
@@ -148,11 +155,14 @@
|
||||
#define PACKAGE_URL "https://libcoap.net/"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "4.2.1"
|
||||
#define PACKAGE_VERSION "4.3.0"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to build without support for separate responses. */
|
||||
/* #undef WITHOUT_ASYNC */
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
@@ -173,4 +183,3 @@
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
#endif /* _CONFIG_H_ */
|
||||
@@ -3,6 +3,8 @@
|
||||
*
|
||||
* Copyright (C) 2010-2011,2014 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
@@ -41,9 +43,11 @@ typedef short coap_log_t;
|
||||
Use COAP_LOG_CIPHERS to output Cipher Info in OpenSSL etc.
|
||||
*/
|
||||
#define COAP_LOG_CIPHERS (LOG_DEBUG+2)
|
||||
#else
|
||||
#else /* !HAVE_SYSLOG_H */
|
||||
/** Pre-defined log levels akin to what is used in \b syslog
|
||||
with LOG_CIPHERS added. */
|
||||
|
||||
#if !defined(RIOT_VERSION)
|
||||
typedef enum {
|
||||
LOG_EMERG=0, /**< Emergency */
|
||||
LOG_ALERT, /**< Alert */
|
||||
@@ -55,7 +59,26 @@ typedef enum {
|
||||
LOG_DEBUG, /**< Debug */
|
||||
COAP_LOG_CIPHERS=LOG_DEBUG+2 /**< CipherInfo */
|
||||
} coap_log_t;
|
||||
#endif
|
||||
#else /* RIOT_VERSION */
|
||||
/* RIOT defines a subset of the syslog levels in log.h with different
|
||||
* numeric values. The remaining levels are defined here. Note that
|
||||
* output granularity differs from what would be expected when
|
||||
* adhering to the syslog levels.
|
||||
*/
|
||||
#include <log.h>
|
||||
typedef short coap_log_t;
|
||||
#define LOG_EMERG (0)
|
||||
#define LOG_ALERT (1)
|
||||
#define LOG_CRIT (2)
|
||||
#define LOG_ERR (3)
|
||||
/* LOG_WARNING (4) */
|
||||
#define LOG_NOTICE (5)
|
||||
/* LOG_INFO (6) */
|
||||
/* LOG_DEBUG (7) */
|
||||
#define COAP_LOG_CIPHERS (9)
|
||||
#endif /* RIOT_VERSION */
|
||||
|
||||
#endif /* !HAVE_SYSLOG_H */
|
||||
|
||||
/**
|
||||
* Get the current logging level.
|
||||
@@ -72,7 +95,7 @@ coap_log_t coap_get_log_level(void);
|
||||
void coap_set_log_level(coap_log_t level);
|
||||
|
||||
/**
|
||||
* Logging call-back handler definition.
|
||||
* Logging callback handler definition.
|
||||
*
|
||||
* @param level One of the LOG_* values.
|
||||
* @param message Zero-terminated string message to log.
|
||||
@@ -170,7 +193,15 @@ void coap_show_tls_version(coap_log_t level);
|
||||
*/
|
||||
char *coap_string_tls_version(char *buffer, size_t bufsize);
|
||||
|
||||
struct coap_address_t;
|
||||
/**
|
||||
* Build a string containing the current (D)TLS library support
|
||||
*
|
||||
* @param buffer The buffer to put the string into.
|
||||
* @param bufsize The size of the buffer to put the string into.
|
||||
*
|
||||
* @return A pointer to the provided buffer.
|
||||
*/
|
||||
char *coap_string_tls_support(char *buffer, size_t bufsize);
|
||||
|
||||
/**
|
||||
* Print the address into the defined buffer.
|
||||
@@ -183,7 +214,7 @@ struct coap_address_t;
|
||||
*
|
||||
* @return The amount written into the buffer.
|
||||
*/
|
||||
size_t coap_print_addr(const struct coap_address_t *address,
|
||||
size_t coap_print_addr(const coap_address_t *address,
|
||||
unsigned char *buffer, size_t size);
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
* coap_dtls.h -- (Datagram) Transport Layer Support for libcoap
|
||||
*
|
||||
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2017 Jean-Claude Michelou <jcm@spinetix.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_DTLS_H_
|
||||
#define COAP_DTLS_H_
|
||||
|
||||
#include "coap_time.h"
|
||||
#include "str.h"
|
||||
|
||||
/**
|
||||
* @defgroup dtls DTLS Support
|
||||
* API functions for interfacing with DTLS libraries.
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct coap_dtls_pki_t coap_dtls_pki_t;
|
||||
|
||||
#ifndef COAP_DTLS_HINT_LENGTH
|
||||
#define COAP_DTLS_HINT_LENGTH 128
|
||||
#endif
|
||||
|
||||
typedef enum coap_dtls_role_t {
|
||||
COAP_DTLS_ROLE_CLIENT, /**< Internal function invoked for client */
|
||||
COAP_DTLS_ROLE_SERVER /**< Internal function invoked for server */
|
||||
} coap_dtls_role_t;
|
||||
|
||||
#define COAP_DTLS_RPK_CERT_CN "RPK"
|
||||
|
||||
/**
|
||||
* Check whether DTLS is available.
|
||||
*
|
||||
* @return @c 1 if support for DTLS is enabled, or @c 0 otherwise.
|
||||
*/
|
||||
int coap_dtls_is_supported(void);
|
||||
|
||||
/**
|
||||
* Check whether TLS is available.
|
||||
*
|
||||
* @return @c 1 if support for TLS is enabled, or @c 0 otherwise.
|
||||
*/
|
||||
int coap_tls_is_supported(void);
|
||||
|
||||
typedef enum coap_tls_library_t {
|
||||
COAP_TLS_LIBRARY_NOTLS = 0, /**< No DTLS library */
|
||||
COAP_TLS_LIBRARY_TINYDTLS, /**< Using TinyDTLS library */
|
||||
COAP_TLS_LIBRARY_OPENSSL, /**< Using OpenSSL library */
|
||||
COAP_TLS_LIBRARY_GNUTLS, /**< Using GnuTLS library */
|
||||
COAP_TLS_LIBRARY_MBEDTLS, /**< Using Mbed TLS library */
|
||||
} coap_tls_library_t;
|
||||
|
||||
/**
|
||||
* The structure used for returning the underlying (D)TLS library
|
||||
* information.
|
||||
*/
|
||||
typedef struct coap_tls_version_t {
|
||||
uint64_t version; /**< (D)TLS runtime Library Version */
|
||||
coap_tls_library_t type; /**< Library type. One of COAP_TLS_LIBRARY_* */
|
||||
uint64_t built_version; /**< (D)TLS Built against Library Version */
|
||||
} coap_tls_version_t;
|
||||
|
||||
/**
|
||||
* Determine the type and version of the underlying (D)TLS library.
|
||||
*
|
||||
* @return The version and type of library libcoap was compiled against.
|
||||
*/
|
||||
coap_tls_version_t *coap_get_tls_library_version(void);
|
||||
|
||||
/**
|
||||
* Additional Security setup handler that can be set up by
|
||||
* coap_context_set_pki().
|
||||
* Invoked when libcoap has done the validation checks at the TLS level,
|
||||
* but the application needs to do some additional checks/changes/updates.
|
||||
*
|
||||
* @param tls_session The security session definition - e.g. SSL * for OpenSSL.
|
||||
* NULL if server callback.
|
||||
* This will be dependent on the underlying TLS library -
|
||||
* see coap_get_tls_library_version()
|
||||
* @param setup_data A structure containing setup data originally passed into
|
||||
* coap_context_set_pki() or coap_new_client_session_pki().
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
typedef int (*coap_dtls_security_setup_t)(void* tls_session,
|
||||
coap_dtls_pki_t *setup_data);
|
||||
|
||||
/**
|
||||
* CN Validation callback that can be set up by coap_context_set_pki().
|
||||
* Invoked when libcoap has done the validation checks at the TLS level,
|
||||
* but the application needs to check that the CN is allowed.
|
||||
* CN is the SubjectAltName in the cert, if not present, then the leftmost
|
||||
* Common Name (CN) component of the subject name.
|
||||
* NOTE: If using RPK, then the Public Key does not contain a CN, but the
|
||||
* content of COAP_DTLS_RPK_CERT_CN is presented for the @p cn parameter.
|
||||
*
|
||||
* @param cn The determined CN from the certificate
|
||||
* @param asn1_public_cert The ASN.1 DER encoded X.509 certificate
|
||||
* @param asn1_length The ASN.1 length
|
||||
* @param coap_session The CoAP session associated with the certificate update
|
||||
* @param depth Depth in cert chain. If 0, then client cert, else a CA
|
||||
* @param validated TLS layer can find no issues if 1
|
||||
* @param arg The same as was passed into coap_context_set_pki()
|
||||
* in setup_data->cn_call_back_arg
|
||||
*
|
||||
* @return @c 1 if accepted, else @c 0 if to be rejected.
|
||||
*/
|
||||
typedef int (*coap_dtls_cn_callback_t)(const char *cn,
|
||||
const uint8_t *asn1_public_cert,
|
||||
size_t asn1_length,
|
||||
coap_session_t *coap_session,
|
||||
unsigned int depth,
|
||||
int validated,
|
||||
void *arg);
|
||||
|
||||
/**
|
||||
* The enum used for determining the provided PKI ASN.1 (DER) Private Key
|
||||
* formats.
|
||||
*/
|
||||
typedef enum coap_asn1_privatekey_type_t {
|
||||
COAP_ASN1_PKEY_NONE, /**< NONE */
|
||||
COAP_ASN1_PKEY_RSA, /**< RSA type */
|
||||
COAP_ASN1_PKEY_RSA2, /**< RSA2 type */
|
||||
COAP_ASN1_PKEY_DSA, /**< DSA type */
|
||||
COAP_ASN1_PKEY_DSA1, /**< DSA1 type */
|
||||
COAP_ASN1_PKEY_DSA2, /**< DSA2 type */
|
||||
COAP_ASN1_PKEY_DSA3, /**< DSA3 type */
|
||||
COAP_ASN1_PKEY_DSA4, /**< DSA4 type */
|
||||
COAP_ASN1_PKEY_DH, /**< DH type */
|
||||
COAP_ASN1_PKEY_DHX, /**< DHX type */
|
||||
COAP_ASN1_PKEY_EC, /**< EC type */
|
||||
COAP_ASN1_PKEY_HMAC, /**< HMAC type */
|
||||
COAP_ASN1_PKEY_CMAC, /**< CMAC type */
|
||||
COAP_ASN1_PKEY_TLS1_PRF, /**< TLS1_PRF type */
|
||||
COAP_ASN1_PKEY_HKDF /**< HKDF type */
|
||||
} coap_asn1_privatekey_type_t;
|
||||
|
||||
/**
|
||||
* The enum used for determining the PKI key formats.
|
||||
*/
|
||||
typedef enum coap_pki_key_t {
|
||||
COAP_PKI_KEY_PEM = 0, /**< The PKI key type is PEM file */
|
||||
COAP_PKI_KEY_ASN1, /**< The PKI key type is ASN.1 (DER) buffer */
|
||||
COAP_PKI_KEY_PEM_BUF, /**< The PKI key type is PEM buffer */
|
||||
COAP_PKI_KEY_PKCS11, /**< The PKI key type is PKCS11 (DER) */
|
||||
} coap_pki_key_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI PEM definitions.
|
||||
*/
|
||||
typedef struct coap_pki_key_pem_t {
|
||||
const char *ca_file; /**< File location of Common CA in PEM format */
|
||||
const char *public_cert; /**< File location of Public Cert */
|
||||
const char *private_key; /**< File location of Private Key in PEM format */
|
||||
} coap_pki_key_pem_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI PEM buffer definitions.
|
||||
* The certificates and private key data must be in PEM format.
|
||||
*
|
||||
* Note: The Certs and Key should be NULL terminated strings for
|
||||
* performance reasons (to save a potential buffer copy) and the length include
|
||||
* this NULL terminator. It is not a requirement to have the NULL terminator
|
||||
* though and the length must then reflect the actual data size.
|
||||
*/
|
||||
typedef struct coap_pki_key_pem_buf_t {
|
||||
const uint8_t *ca_cert; /**< PEM buffer Common CA Cert */
|
||||
const uint8_t *public_cert; /**< PEM buffer Public Cert, or Public Key if RPK */
|
||||
const uint8_t *private_key; /**< PEM buffer Private Key
|
||||
If RPK and 'EC PRIVATE KEY' this can be used
|
||||
for both the public_cert and private_key */
|
||||
size_t ca_cert_len; /**< PEM buffer CA Cert length */
|
||||
size_t public_cert_len; /**< PEM buffer Public Cert length */
|
||||
size_t private_key_len; /**< PEM buffer Private Key length */
|
||||
} coap_pki_key_pem_buf_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI ASN.1 (DER) definitions.
|
||||
*/
|
||||
typedef struct coap_pki_key_asn1_t {
|
||||
const uint8_t *ca_cert; /**< ASN1 (DER) Common CA Cert */
|
||||
const uint8_t *public_cert; /**< ASN1 (DER) Public Cert, or Public Key if RPK */
|
||||
const uint8_t *private_key; /**< ASN1 (DER) Private Key */
|
||||
size_t ca_cert_len; /**< ASN1 CA Cert length */
|
||||
size_t public_cert_len; /**< ASN1 Public Cert length */
|
||||
size_t private_key_len; /**< ASN1 Private Key length */
|
||||
coap_asn1_privatekey_type_t private_key_type; /**< Private Key Type */
|
||||
} coap_pki_key_asn1_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI PKCS11 definitions.
|
||||
*/
|
||||
typedef struct coap_pki_key_pkcs11_t {
|
||||
const char *ca; /**< pkcs11: URI for Common CA Certificate */
|
||||
const char *public_cert; /**< pkcs11: URI for Public Cert */
|
||||
const char *private_key; /**< pkcs11: URI for Private Key */
|
||||
const char *user_pin; /**< User pin to access PKCS11. If NULL, then
|
||||
pin-value= parameter must be set in
|
||||
pkcs11: URI as a query. */
|
||||
} coap_pki_key_pkcs11_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the PKI key information.
|
||||
*/
|
||||
typedef struct coap_dtls_key_t {
|
||||
coap_pki_key_t key_type; /**< key format type */
|
||||
union {
|
||||
coap_pki_key_pem_t pem; /**< for PEM file keys */
|
||||
coap_pki_key_pem_buf_t pem_buf; /**< for PEM memory keys */
|
||||
coap_pki_key_asn1_t asn1; /**< for ASN.1 (DER) memory keys */
|
||||
coap_pki_key_pkcs11_t pkcs11; /**< for PKCS11 keys */
|
||||
} key;
|
||||
} coap_dtls_key_t;
|
||||
|
||||
/**
|
||||
* Server Name Indication (SNI) Validation callback that can be set up by
|
||||
* coap_context_set_pki().
|
||||
* Invoked if the SNI is not previously seen and prior to sending a certificate
|
||||
* set back to the client so that the appropriate certificate set can be used
|
||||
* based on the requesting SNI.
|
||||
*
|
||||
* @param sni The requested SNI
|
||||
* @param arg The same as was passed into coap_context_set_pki()
|
||||
* in setup_data->sni_call_back_arg
|
||||
*
|
||||
* @return New set of certificates to use, or @c NULL if SNI is to be rejected.
|
||||
*/
|
||||
typedef coap_dtls_key_t *(*coap_dtls_pki_sni_callback_t)(const char *sni,
|
||||
void* arg);
|
||||
|
||||
|
||||
#define COAP_DTLS_PKI_SETUP_VERSION 1 /**< Latest PKI setup version */
|
||||
|
||||
/**
|
||||
* The structure used for defining the PKI setup data to be used.
|
||||
*/
|
||||
struct coap_dtls_pki_t {
|
||||
uint8_t version; /** Set to COAP_DTLS_PKI_SETUP_VERSION
|
||||
to support this version of the struct */
|
||||
|
||||
/* Options to enable different TLS functionality in libcoap */
|
||||
uint8_t verify_peer_cert; /**< 1 if peer cert is to be verified */
|
||||
uint8_t check_common_ca; /**< 1 if peer cert is to be signed by
|
||||
* the same CA as the local cert */
|
||||
uint8_t allow_self_signed; /**< 1 if self-signed certs are allowed.
|
||||
* Ignored if check_common_ca set */
|
||||
uint8_t allow_expired_certs; /**< 1 if expired certs are allowed */
|
||||
uint8_t cert_chain_validation; /**< 1 if to check cert_chain_verify_depth */
|
||||
uint8_t cert_chain_verify_depth; /**< recommended depth is 3 */
|
||||
uint8_t check_cert_revocation; /**< 1 if revocation checks wanted */
|
||||
uint8_t allow_no_crl; /**< 1 ignore if CRL not there */
|
||||
uint8_t allow_expired_crl; /**< 1 if expired crl is allowed */
|
||||
uint8_t allow_bad_md_hash; /**< 1 if unsupported MD hashes are allowed */
|
||||
uint8_t allow_short_rsa_length; /**< 1 if small RSA keysizes are allowed */
|
||||
uint8_t is_rpk_not_cert; /**< 1 is RPK instead of Public Certificate.
|
||||
* If set, PKI key format type cannot be
|
||||
* COAP_PKI_KEY_PEM */
|
||||
uint8_t reserved[3]; /**< Reserved - must be set to 0 for
|
||||
future compatibility */
|
||||
/* Size of 3 chosen to align to next
|
||||
* parameter, so if newly defined option
|
||||
* it can use one of the reserverd slot so
|
||||
* no need to change
|
||||
* COAP_DTLS_PKI_SETUP_VERSION and just
|
||||
* decrement the reserved[] count.
|
||||
*/
|
||||
|
||||
/** CN check callback function.
|
||||
* If not NULL, is called when the TLS connection has passed the configured
|
||||
* TLS options above for the application to verify if the CN is valid.
|
||||
*/
|
||||
coap_dtls_cn_callback_t validate_cn_call_back;
|
||||
void *cn_call_back_arg; /**< Passed in to the CN callback function */
|
||||
|
||||
/** SNI check callback function.
|
||||
* If not @p NULL, called if the SNI is not previously seen and prior to
|
||||
* sending a certificate set back to the client so that the appropriate
|
||||
* certificate set can be used based on the requesting SNI.
|
||||
*/
|
||||
coap_dtls_pki_sni_callback_t validate_sni_call_back;
|
||||
void *sni_call_back_arg; /**< Passed in to the sni callback function */
|
||||
|
||||
/** Additional Security callback handler that is invoked when libcoap has
|
||||
* done the standard, defined validation checks at the TLS level,
|
||||
* If not @p NULL, called from within the TLS Client Hello connection
|
||||
* setup.
|
||||
*/
|
||||
coap_dtls_security_setup_t additional_tls_setup_call_back;
|
||||
|
||||
char* client_sni; /**< If not NULL, SNI to use in client TLS setup.
|
||||
Owned by the client app and must remain valid
|
||||
during the call to coap_new_client_session_pki() */
|
||||
|
||||
coap_dtls_key_t pki_key; /**< PKI key definition */
|
||||
};
|
||||
|
||||
/**
|
||||
* The structure that holds the Client PSK information.
|
||||
*/
|
||||
typedef struct coap_dtls_cpsk_info_t {
|
||||
coap_bin_const_t identity;
|
||||
coap_bin_const_t key;
|
||||
} coap_dtls_cpsk_info_t;
|
||||
|
||||
/**
|
||||
* Identity Hint Validation callback that can be set up by
|
||||
* coap_new_client_session_psk2().
|
||||
* Invoked when libcoap has done the validation checks at the TLS level,
|
||||
* but the application needs to check that the Identity Hint is allowed,
|
||||
* and thus needs to use the appropriate PSK information for the Identity
|
||||
* Hint for the (D)TLS session.
|
||||
* Note: Identity Hint is not supported in (D)TLS1.3.
|
||||
*
|
||||
* @param hint The server provided Identity Hint
|
||||
* @param coap_session The CoAP session associated with the Identity Hint
|
||||
* @param arg The same as was passed into coap_new_client_session_psk2()
|
||||
* in setup_data->ih_call_back_arg
|
||||
*
|
||||
* @return New coap_dtls_cpsk_info_t object or @c NULL on error.
|
||||
*/
|
||||
typedef const coap_dtls_cpsk_info_t *(*coap_dtls_ih_callback_t)(
|
||||
coap_str_const_t *hint,
|
||||
coap_session_t *coap_session,
|
||||
void *arg);
|
||||
|
||||
#define COAP_DTLS_CPSK_SETUP_VERSION 1 /**< Latest CPSK setup version */
|
||||
|
||||
/**
|
||||
* The structure used for defining the Client PSK setup data to be used.
|
||||
*/
|
||||
typedef struct coap_dtls_cpsk_t {
|
||||
uint8_t version; /** Set to COAP_DTLS_CPSK_SETUP_VERSION
|
||||
to support this version of the struct */
|
||||
|
||||
/* Options to enable different TLS functionality in libcoap */
|
||||
uint8_t reserved[7]; /**< Reserved - must be set to 0 for
|
||||
future compatibility */
|
||||
/* Size of 7 chosen to align to next
|
||||
* parameter, so if newly defined option
|
||||
* it can use one of the reserverd slot so
|
||||
* no need to change
|
||||
* COAP_DTLS_CPSK_SETUP_VERSION and just
|
||||
* decrement the reserved[] count.
|
||||
*/
|
||||
|
||||
/** Identity Hint check callback function.
|
||||
* If not NULL, is called when the Identity Hint (TLS1.2 or earlier) is
|
||||
* provided by the server.
|
||||
* The appropriate Identity and Pre-shared Key to use can then be returned.
|
||||
*/
|
||||
coap_dtls_ih_callback_t validate_ih_call_back;
|
||||
void *ih_call_back_arg; /**< Passed in to the Identity Hint callback
|
||||
function */
|
||||
|
||||
char* client_sni; /**< If not NULL, SNI to use in client TLS setup.
|
||||
Owned by the client app and must remain valid
|
||||
during the call to coap_new_client_session_psk2()
|
||||
Note: Not supported by TinyDTLS. */
|
||||
|
||||
coap_dtls_cpsk_info_t psk_info; /**< Client PSK definition */
|
||||
} coap_dtls_cpsk_t;
|
||||
|
||||
/**
|
||||
* The structure that holds the Server Pre-Shared Key and Identity
|
||||
* Hint information.
|
||||
*/
|
||||
typedef struct coap_dtls_spsk_info_t {
|
||||
coap_bin_const_t hint;
|
||||
coap_bin_const_t key;
|
||||
} coap_dtls_spsk_info_t;
|
||||
|
||||
|
||||
/**
|
||||
* Identity Validation callback that can be set up by
|
||||
* coap_context_set_psk2().
|
||||
* Invoked when libcoap has done the validation checks at the TLS level,
|
||||
* but the application needs to check that the Identity is allowed,
|
||||
* and needs to use the appropriate Pre-Shared Key for the (D)TLS session.
|
||||
*
|
||||
* @param identity The client provided Identity
|
||||
* @param coap_session The CoAP session associated with the Identity Hint
|
||||
* @param arg The value as passed into coap_context_set_psk2()
|
||||
* in setup_data->id_call_back_arg
|
||||
*
|
||||
* @return New coap_bin_const_t object containing the Pre-Shared Key or
|
||||
@c NULL on error.
|
||||
* Note: This information will be duplicated into an internal
|
||||
* structure.
|
||||
*/
|
||||
typedef const coap_bin_const_t *(*coap_dtls_id_callback_t)(
|
||||
coap_bin_const_t *identity,
|
||||
coap_session_t *coap_session,
|
||||
void *arg);
|
||||
/**
|
||||
* PSK SNI callback that can be set up by coap_context_set_psk2().
|
||||
* Invoked when libcoap has done the validation checks at the TLS level
|
||||
* and the application needs to:-
|
||||
* a) check that the SNI is allowed
|
||||
* b) provide the appropriate PSK information for the (D)TLS session.
|
||||
*
|
||||
* @param sni The client provided SNI
|
||||
* @param coap_session The CoAP session associated with the SNI
|
||||
* @param arg The same as was passed into coap_context_set_psk2()
|
||||
* in setup_data->sni_call_back_arg
|
||||
*
|
||||
* @return New coap_dtls_spsk_info_t object or @c NULL on error.
|
||||
*/
|
||||
typedef const coap_dtls_spsk_info_t *(*coap_dtls_psk_sni_callback_t)(
|
||||
const char *sni,
|
||||
coap_session_t *coap_session,
|
||||
void *arg);
|
||||
|
||||
#define COAP_DTLS_SPSK_SETUP_VERSION 1 /**< Latest SPSK setup version */
|
||||
|
||||
/**
|
||||
* The structure used for defining the Server PSK setup data to be used.
|
||||
*/
|
||||
typedef struct coap_dtls_spsk_t {
|
||||
uint8_t version; /** Set to COAP_DTLS_SPSK_SETUP_VERSION
|
||||
to support this version of the struct */
|
||||
|
||||
/* Options to enable different TLS functionality in libcoap */
|
||||
uint8_t reserved[7]; /**< Reserved - must be set to 0 for
|
||||
future compatibility */
|
||||
/* Size of 7 chosen to align to next
|
||||
* parameter, so if newly defined option
|
||||
* it can use one of the reserverd slot so
|
||||
* no need to change
|
||||
* COAP_DTLS_SPSK_SETUP_VERSION and just
|
||||
* decrement the reserved[] count.
|
||||
*/
|
||||
|
||||
/** Identity check callback function.
|
||||
* If not @p NULL, is called when the Identity is provided by the client.
|
||||
* The appropriate Pre-Shared Key to use can then be returned.
|
||||
*/
|
||||
coap_dtls_id_callback_t validate_id_call_back;
|
||||
void *id_call_back_arg; /**< Passed in to the Identity callback function */
|
||||
|
||||
/** SNI check callback function.
|
||||
* If not @p NULL, called if the SNI is not previously seen and prior to
|
||||
* sending PSK information back to the client so that the appropriate
|
||||
* PSK information can be used based on the requesting SNI.
|
||||
*/
|
||||
coap_dtls_psk_sni_callback_t validate_sni_call_back;
|
||||
void *sni_call_back_arg; /**< Passed in to the SNI callback function */
|
||||
|
||||
coap_dtls_spsk_info_t psk_info; /**< Server PSK definition */
|
||||
} coap_dtls_spsk_t;
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Sets the (D)TLS logging level to the specified @p level.
|
||||
* Note: coap_log_level() will influence output if at a specified level.
|
||||
*
|
||||
* @param level The logging level to use - LOG_*
|
||||
*/
|
||||
void coap_dtls_set_log_level(int level);
|
||||
|
||||
/**
|
||||
* @ingroup logging
|
||||
* Get the current (D)TLS logging.
|
||||
*
|
||||
* @return The current log level (one of LOG_*).
|
||||
*/
|
||||
int coap_dtls_get_log_level(void);
|
||||
|
||||
|
||||
#endif /* COAP_DTLS_H */
|
||||
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* coap_dtls_internal.h -- (Datagram) Transport Layer Support for libcoap
|
||||
*
|
||||
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2017 Jean-Claude Michelou <jcm@spinetix.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef COAP_DTLS_INTERNAL_H_
|
||||
#define COAP_DTLS_INTERNAL_H_
|
||||
|
||||
/**
|
||||
* @defgroup dtls_internal DTLS Support (Internal)
|
||||
* CoAP DTLS Structures, Enums and Functions that are not exposed to
|
||||
* applications
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* https://tools.ietf.org/html/rfc6347#section-4.2.4.1 */
|
||||
#ifndef COAP_DTLS_RETRANSMIT_MS
|
||||
#define COAP_DTLS_RETRANSMIT_MS 1000
|
||||
#endif
|
||||
#ifndef COAP_DTLS_RETRANSMIT_TOTAL_MS
|
||||
#define COAP_DTLS_RETRANSMIT_TOTAL_MS 60000
|
||||
#endif
|
||||
|
||||
#define COAP_DTLS_RETRANSMIT_COAP_TICKS (COAP_DTLS_RETRANSMIT_MS * COAP_TICKS_PER_SECOND / 1000)
|
||||
|
||||
/**
|
||||
* Creates a new DTLS context for the given @p coap_context. This function
|
||||
* returns a pointer to a new DTLS context object or @c NULL on error.
|
||||
*
|
||||
* @param coap_context The CoAP context where the DTLS object shall be used.
|
||||
*
|
||||
* @return A DTLS context object or @c NULL on error.
|
||||
*/
|
||||
void *
|
||||
coap_dtls_new_context(coap_context_t *coap_context);
|
||||
|
||||
/**
|
||||
* Set the DTLS context's default server PSK information.
|
||||
* This does the PSK specifics following coap_dtls_new_context().
|
||||
*
|
||||
* @param coap_context The CoAP context.
|
||||
* @param setup_data A structure containing setup data originally passed into
|
||||
* coap_context_set_psk2().
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
|
||||
int
|
||||
coap_dtls_context_set_spsk(coap_context_t *coap_context,
|
||||
coap_dtls_spsk_t *setup_data);
|
||||
|
||||
/**
|
||||
* Set the DTLS context's default client PSK information.
|
||||
* This does the PSK specifics following coap_dtls_new_context().
|
||||
*
|
||||
* @param coap_context The CoAP context.
|
||||
* @param setup_data A structure containing setup data originally passed into
|
||||
* coap_new_client_session_psk2().
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
|
||||
int
|
||||
coap_dtls_context_set_cpsk(coap_context_t *coap_context,
|
||||
coap_dtls_cpsk_t *setup_data);
|
||||
|
||||
/**
|
||||
* Set the DTLS context's default server PKI information.
|
||||
* This does the PKI specifics following coap_dtls_new_context().
|
||||
* If @p COAP_DTLS_ROLE_SERVER, then the information will get put into the
|
||||
* TLS library's context (from which sessions are derived).
|
||||
* If @p COAP_DTLS_ROLE_CLIENT, then the information will get put into the
|
||||
* TLS library's session.
|
||||
*
|
||||
* @param coap_context The CoAP context.
|
||||
* @param setup_data Setup information defining how PKI is to be setup.
|
||||
* Required parameter. If @p NULL, PKI will not be
|
||||
* set up.
|
||||
* @param role One of @p COAP_DTLS_ROLE_CLIENT or @p COAP_DTLS_ROLE_SERVER
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
|
||||
int
|
||||
coap_dtls_context_set_pki(coap_context_t *coap_context,
|
||||
const coap_dtls_pki_t *setup_data,
|
||||
const coap_dtls_role_t role);
|
||||
|
||||
/**
|
||||
* Set the dtls context's default Root CA information for a client or server.
|
||||
*
|
||||
* @param coap_context The current coap_context_t object.
|
||||
* @param ca_file If not @p NULL, is the full path name of a PEM encoded
|
||||
* file containing all the Root CAs to be used.
|
||||
* @param ca_dir If not @p NULL, points to a directory containing PEM
|
||||
* encoded files containing all the Root CAs to be used.
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0.
|
||||
*/
|
||||
|
||||
int
|
||||
coap_dtls_context_set_pki_root_cas(coap_context_t *coap_context,
|
||||
const char *ca_file,
|
||||
const char *ca_dir);
|
||||
|
||||
/**
|
||||
* Check whether one of the coap_dtls_context_set_{psk|pki}() functions have
|
||||
* been called.
|
||||
*
|
||||
* @param coap_context The current coap_context_t object.
|
||||
*
|
||||
* @return @c 1 if coap_dtls_context_set_{psk|pki}() called, else @c 0.
|
||||
*/
|
||||
|
||||
int coap_dtls_context_check_keys_enabled(coap_context_t *coap_context);
|
||||
|
||||
/**
|
||||
* Releases the storage allocated for @p dtls_context.
|
||||
*
|
||||
* @param dtls_context The DTLS context as returned by coap_dtls_new_context().
|
||||
*/
|
||||
void coap_dtls_free_context(void *dtls_context);
|
||||
|
||||
/**
|
||||
* Create a new client-side session. This should send a HELLO to the server.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the session.
|
||||
*/
|
||||
void *coap_dtls_new_client_session(coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Create a new DTLS server-side session.
|
||||
* Called after coap_dtls_hello() has returned @c 1, signalling that a validated
|
||||
* HELLO was received from a client.
|
||||
* This should send a HELLO to the server.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the DTLS session.
|
||||
*/
|
||||
void *coap_dtls_new_server_session(coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Terminates the DTLS session (may send an ALERT if necessary) then frees the
|
||||
* underlying TLS library object containing security parameters for the session.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_dtls_free_session(coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Notify of a change in the CoAP session's MTU, for example after
|
||||
* a PMTU update.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_dtls_session_update_mtu(coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Send data to a DTLS peer.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data pointer to data.
|
||||
* @param data_len Number of bytes to send.
|
||||
*
|
||||
* @return @c 0 if this would be blocking, @c -1 if there is an error or the
|
||||
* number of cleartext bytes sent.
|
||||
*/
|
||||
int coap_dtls_send(coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
|
||||
/**
|
||||
* Check if timeout is handled per CoAP session or per CoAP context.
|
||||
*
|
||||
* @return @c 1 of timeout and retransmit is per context, @c 0 if it is
|
||||
* per session.
|
||||
*/
|
||||
int coap_dtls_is_context_timeout(void);
|
||||
|
||||
/**
|
||||
* Do all pending retransmits and get next timeout
|
||||
*
|
||||
* @param dtls_context The DTLS context.
|
||||
*
|
||||
* @return @c 0 if no event is pending or date of the next retransmit.
|
||||
*/
|
||||
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context);
|
||||
|
||||
/**
|
||||
* Get next timeout for this session.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param now The current time in ticks.
|
||||
*
|
||||
* @return @c 0 If no event is pending or ticks time of the next retransmit.
|
||||
*/
|
||||
coap_tick_t coap_dtls_get_timeout(coap_session_t *coap_session,
|
||||
coap_tick_t now);
|
||||
|
||||
/**
|
||||
* Handle a DTLS timeout expiration.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_dtls_handle_timeout(coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Handling incoming data from a DTLS peer.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Encrypted datagram.
|
||||
* @param data_len Encrypted datagram size.
|
||||
*
|
||||
* @return Result of coap_handle_dgram on the decrypted CoAP PDU
|
||||
* or @c -1 for error.
|
||||
*/
|
||||
int coap_dtls_receive(coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
|
||||
/**
|
||||
* Handling client HELLO messages from a new candiate peer.
|
||||
* Note that session->tls is empty.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Encrypted datagram.
|
||||
* @param data_len Encrypted datagram size.
|
||||
*
|
||||
* @return @c 0 if a cookie verification message has been sent, @c 1 if the
|
||||
* HELLO contains a valid cookie and a server session should be created,
|
||||
* @c -1 if the message is invalid.
|
||||
*/
|
||||
int coap_dtls_hello(coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
|
||||
/**
|
||||
* Get DTLS overhead over cleartext PDUs.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*
|
||||
* @return Maximum number of bytes added by DTLS layer.
|
||||
*/
|
||||
unsigned int coap_dtls_get_overhead(coap_session_t *coap_session);
|
||||
|
||||
/**
|
||||
* Create a new TLS client-side session.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param connected Updated with whether the connection is connected yet or not.
|
||||
* @c 0 is not connected, @c 1 is connected.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the session.
|
||||
*/
|
||||
void *coap_tls_new_client_session(coap_session_t *coap_session, int *connected);
|
||||
|
||||
/**
|
||||
* Create a TLS new server-side session.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param connected Updated with whether the connection is connected yet or not.
|
||||
* @c 0 is not connected, @c 1 is connected.
|
||||
*
|
||||
* @return Opaque handle to underlying TLS library object containing security
|
||||
* parameters for the session.
|
||||
*/
|
||||
void *coap_tls_new_server_session(coap_session_t *coap_session, int *connected);
|
||||
|
||||
/**
|
||||
* Terminates the TLS session (may send an ALERT if necessary) then frees the
|
||||
* underlying TLS library object containing security parameters for the session.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
*/
|
||||
void coap_tls_free_session( coap_session_t *coap_session );
|
||||
|
||||
/**
|
||||
* Send data to a TLS peer, with implicit flush.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Pointer to data.
|
||||
* @param data_len Number of bytes to send.
|
||||
*
|
||||
* @return @c 0 if this should be retried, @c -1 if there is an error
|
||||
* or the number of cleartext bytes sent.
|
||||
*/
|
||||
ssize_t coap_tls_write(coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len
|
||||
);
|
||||
|
||||
/**
|
||||
* Read some data from a TLS peer.
|
||||
*
|
||||
* @param coap_session The CoAP session.
|
||||
* @param data Pointer to data.
|
||||
* @param data_len Maximum number of bytes to read.
|
||||
*
|
||||
* @return @c 0 if this should be retried, @c -1 if there is an error
|
||||
* or the number of cleartext bytes read.
|
||||
*/
|
||||
ssize_t coap_tls_read(coap_session_t *coap_session,
|
||||
uint8_t *data,
|
||||
size_t data_len
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialize the underlying (D)TLS Library layer.
|
||||
*
|
||||
*/
|
||||
void coap_dtls_startup(void);
|
||||
|
||||
/**
|
||||
* Close down the underlying (D)TLS Library layer.
|
||||
*
|
||||
*/
|
||||
void coap_dtls_shutdown(void);
|
||||
|
||||
/**
|
||||
* Get the actual (D)TLS object for the session.
|
||||
*
|
||||
* @param session The session.
|
||||
* @param tls_lib Updated with the library type.
|
||||
*
|
||||
* @return The TLS information.
|
||||
*/
|
||||
void *coap_dtls_get_tls(const coap_session_t *session,
|
||||
coap_tls_library_t *tls_lib);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_DTLS_INTERNAL_H */
|
||||
@@ -3,6 +3,8 @@
|
||||
*
|
||||
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
@@ -12,9 +14,6 @@
|
||||
|
||||
#include "libcoap.h"
|
||||
|
||||
struct coap_context_t;
|
||||
struct coap_session_t;
|
||||
|
||||
/**
|
||||
* @defgroup events Event API
|
||||
* API functions for event delivery from lower-layer library functions.
|
||||
@@ -49,17 +48,20 @@ struct coap_session_t;
|
||||
#define COAP_EVENT_SESSION_CLOSED 0x2002
|
||||
#define COAP_EVENT_SESSION_FAILED 0x2003
|
||||
|
||||
/**
|
||||
* BLOCK2 receive errors
|
||||
*/
|
||||
#define COAP_EVENT_PARTIAL_BLOCK 0x3001
|
||||
|
||||
/**
|
||||
* Type for event handler functions that can be registered with a CoAP
|
||||
* context using the unction coap_set_event_handler(). When called by
|
||||
* the library, the first argument will be the coap_context_t object
|
||||
* where the handler function has been registered. The second argument
|
||||
* is the event type that may be complemented by event-specific data
|
||||
* passed as the third argument.
|
||||
* the library, the first argument will be the current coap_session_t object
|
||||
* which is associated with the original CoAP context. The second parameter
|
||||
* is the event type.
|
||||
*/
|
||||
typedef int (*coap_event_handler_t)(struct coap_context_t *,
|
||||
coap_event_t event,
|
||||
struct coap_session_t *session);
|
||||
typedef int (*coap_event_handler_t)(coap_session_t *session,
|
||||
const coap_event_t event);
|
||||
|
||||
/**
|
||||
* Registers the function @p hnd as callback for events from the given
|
||||
@@ -70,9 +72,11 @@ typedef int (*coap_event_handler_t)(struct coap_context_t *,
|
||||
* @param hnd The event handler to be registered. @c NULL if to be
|
||||
* de-registered.
|
||||
*/
|
||||
void coap_register_event_handler(struct coap_context_t *context,
|
||||
void coap_register_event_handler(coap_context_t *context,
|
||||
coap_event_handler_t hnd);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Registers the function @p hnd as callback for events from the given
|
||||
* CoAP context @p context. Any event handler that has previously been
|
||||
@@ -84,7 +88,7 @@ void coap_register_event_handler(struct coap_context_t *context,
|
||||
* @param hnd The event handler to be registered.
|
||||
*/
|
||||
COAP_DEPRECATED
|
||||
void coap_set_event_handler(struct coap_context_t *context,
|
||||
void coap_set_event_handler(coap_context_t *context,
|
||||
coap_event_handler_t hnd);
|
||||
|
||||
/**
|
||||
@@ -95,8 +99,6 @@ void coap_set_event_handler(struct coap_context_t *context,
|
||||
* @param context The CoAP context whose event handler is to be removed.
|
||||
*/
|
||||
COAP_DEPRECATED
|
||||
void coap_clear_event_handler(struct coap_context_t *context);
|
||||
|
||||
/** @} */
|
||||
void coap_clear_event_handler(coap_context_t *context);
|
||||
|
||||
#endif /* COAP_EVENT_H */
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* coap_forward_decls.h -- Forward declarations of structures that are
|
||||
* opaque to application programming that use libcoap.
|
||||
*
|
||||
* Copyright (C) 2019-2021 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_forward_decls.h
|
||||
* @brief COAP forward definitions
|
||||
*/
|
||||
|
||||
#ifndef COAP_FORWARD_DECLS_H_
|
||||
#define COAP_FORWARD_DECLS_H_
|
||||
|
||||
/*
|
||||
* Define the forward declations for the structures (even non-opaque)
|
||||
* so that applications (using coap.h) as well as libcoap builds
|
||||
* can reference them (and makes .h file dependencies a lot simpler).
|
||||
*/
|
||||
struct coap_address_t;
|
||||
struct coap_bin_const_t;
|
||||
struct coap_dtls_pki_t;
|
||||
struct coap_str_const_t;
|
||||
struct coap_string_t;
|
||||
|
||||
/*
|
||||
* typedef all the opaque structures that are defined in coap_*_internal.h
|
||||
*/
|
||||
|
||||
/* ************* coap_async_internal.h ***************** */
|
||||
|
||||
/**
|
||||
* Async Entry information.
|
||||
*/
|
||||
typedef struct coap_async_t coap_async_t;
|
||||
|
||||
/* ************* coap_block_internal.h ***************** */
|
||||
|
||||
/*
|
||||
* Block handling information.
|
||||
*/
|
||||
typedef struct coap_lg_xmit_t coap_lg_xmit_t;
|
||||
typedef struct coap_lg_crcv_t coap_lg_crcv_t;
|
||||
typedef struct coap_lg_srcv_t coap_lg_srcv_t;
|
||||
|
||||
/* ************* coap_cache_internal.h ***************** */
|
||||
|
||||
/*
|
||||
* Cache Entry information.
|
||||
*/
|
||||
typedef struct coap_cache_entry_t coap_cache_entry_t;
|
||||
typedef struct coap_cache_key_t coap_cache_key_t;
|
||||
|
||||
/* ************* coap_io_internal.h ***************** */
|
||||
|
||||
/**
|
||||
* coap_socket_t and coap_packet_t information.
|
||||
*/
|
||||
typedef struct coap_packet_t coap_packet_t;
|
||||
typedef struct coap_socket_t coap_socket_t;
|
||||
|
||||
/* ************* coap_net_internal.h ***************** */
|
||||
|
||||
/*
|
||||
* Net information.
|
||||
*/
|
||||
typedef struct coap_context_t coap_context_t;
|
||||
typedef struct coap_queue_t coap_queue_t;
|
||||
|
||||
/* ************* coap_pdu_internal.h ***************** */
|
||||
|
||||
/**
|
||||
* PDU information.
|
||||
*/
|
||||
typedef struct coap_pdu_t coap_pdu_t;
|
||||
|
||||
/* ************* coap_resource_internal.h ***************** */
|
||||
|
||||
/*
|
||||
* Resource information.
|
||||
*/
|
||||
typedef struct coap_attr_t coap_attr_t;
|
||||
typedef struct coap_resource_t coap_resource_t;
|
||||
|
||||
/* ************* coap_session_internal.h ***************** */
|
||||
|
||||
/*
|
||||
* Session information.
|
||||
*/
|
||||
typedef struct coap_addr_hash_t coap_addr_hash_t;
|
||||
typedef struct coap_endpoint_t coap_endpoint_t;
|
||||
typedef struct coap_session_t coap_session_t;
|
||||
|
||||
/* ************* coap_subscribe_internal.h ***************** */
|
||||
|
||||
/*
|
||||
* Observe subscriber information.
|
||||
*/
|
||||
typedef struct coap_subscription_t coap_subscription_t;
|
||||
|
||||
#endif /* COAP_FORWARD_DECLS_H_ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user