remove libcoap 4.3.1

Signed-off-by: wanghan985406 <wanghan76@huawei.com>
This commit is contained in:
wanghan985406
2023-12-21 06:37:49 +00:00
parent f2b16b9922
commit c3f959c04c
235 changed files with 0 additions and 75531 deletions
-8
View File
@@ -1,8 +0,0 @@
Olaf Bergmann
Carsten Schönert
Jon Shallow
Jean-Claude Michelou
Christian Amsüss
For additional contributors, see
https://github.com/obgm/libcoap/graphs/contributors
-93
View File
@@ -1,93 +0,0 @@
cflags = [
"-DCOAP_SUPPORT_SOCKET_BROADCAST",
"-DCOAP_USER_DEFAULT_PORT=5684",
"-Wall",
"-fPIC",
]
cflags_cc = cflags
config("libcoap_config") {
include_dirs = [
"include",
"//third_party/bounds_checking_function/include",
]
if (defined(ohos_lite)) {
defines = [ "_GNU_SOURCE" ]
}
}
src = [
"src/coap_address.c",
"src/coap_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_io.c",
"src/coap_notls.c",
"src/coap_prng.c",
"src/coap_session.c",
"src/coap_tcp.c",
"src/coap_time.c",
"src/encode.c",
"src/mem.c",
"src/net.c",
"src/coap_option.c",
"src/pdu.c",
"src/resource.c",
"src/str.c",
"src/coap_subscribe.c",
"src/uri.c",
]
source_set("libcoap_src") {
sources = src
configs += [ ":libcoap_config" ]
}
deps_with_static = [
":libcoap_src",
"//third_party/bounds_checking_function:libsec_static",
]
deps_with_shared = [
":libcoap_src",
"//third_party/bounds_checking_function:libsec_shared",
]
if (defined(ohos_lite)) {
print("[libcoap build] in ohos_lite branch") # check position
import("//build/lite/config/component/lite_component.gni")
static_library("libcoap_static") {
deps = deps_with_static
public_configs = [ ":libcoap_config" ]
}
shared_library("libcoap") {
deps = deps_with_shared
public_configs = [ ":libcoap_config" ]
}
} else {
print("[libcoap build] in other branch") # check position
import("//build/ohos.gni")
ohos_static_library("libcoap_static") {
deps = deps_with_static
public_configs = [ ":libcoap_config" ]
}
ohos_shared_library("libcoap") {
deps = deps_with_shared
public_configs = [ ":libcoap_config" ]
subsystem_name = "thirdparty"
innerapi_tags = [ "platformsdk_indirect" ]
if (!defined(oem_commercial_build) || !oem_commercial_build) {
defines = [ "STANDARD_SYSTEM_ENABLE" ]
}
part_name = "libcoap"
}
}
-157
View File
@@ -1,157 +0,0 @@
For Windows builds - see the Windows Section
Obtaining the Libcoap Source
============================
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 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
* Change into the top level directory of the unpackaged files
or alternatively, clone the libcoap git repository from github
* Change to the directory that you want to install the libcoap sub-directory
into.
* 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 main branch:-
git checkout main
Building Libcoap Libraries and Examples
=======================================
Follow the appropriate sections below
TinyDTLS Only
=============
It is possible that you may need to execute the following two commands once to
get the TinyDTLS code into your project, so the TinyDTLS library can be used.
git submodule init
git submodule update
General Building with cmake for linux/windows/macos/android (not for LwIP or Contiki - 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
./configure
make
sudo make install
./autogen.sh will fail if there is a required package for buildling libcoap
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 library to use as well as
disable some building of documentation.
General configure instructions can be found in INSTALL, which is built
by ./autogen.sh
./configure --help
gives the specific options available to libcoap.
Some examples are:-
# No DTLS
./configure --enable-tests --disable-documentation --enable-examples --disable-dtls --enable-shared
# With TinyDTLS
./configure --enable-tests --disable-documentation --enable-examples --with-tinydtls --enable-shared
Note: FreeBSD requires gmake instead of make when building TinyDTLS - i.e.
gmake
sudo gmake install
# With OpenSSL
./configure --with-openssl --enable-tests --enable-shared
# With GnuTLS
./configure --with-gnutls --enable-tests --enable-shared
Note: --disable-documentation disables the building of doxygen and man page
files. If you want to only disable one of them, use --disable-doxygen or
--disable-manpages. Doxygen requires the program doxygen and man pages require
the program a2x to build the appropriate files.
If you need to rebuild the libcoap-*.{map,sym} files to update any exposed
function changes, run
make update-map-file
prior to running 'make'.
LwIP
====
./autogen.sh
./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
cd examples/lwip
make
Executable is ./server. See examples/lwip/README for further information
Contiki
=======
./autogen.sh
./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
cd examples/contiki
make
Executable is ./server.minimal-net. See examples/contiki/README for further
information
Windows
=======
Install OpenSSL (minimum version 1.1.0) including the development libraries if
not already installed.
Within Visual Studio, "Clone or check out code" using the repository
https://github.com/obgm/libcoap.git
You may need to update the SDK version of the libcoap Windows Project files to
match that of the SDK version of the Visual Studio you are using. In Solution
Explorer with the view set to libcoap.sln, right click "Solution 'libcoap'"
and then "Retarget solution".
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.
-723
View File
@@ -1,723 +0,0 @@
# CMakeLists.txt for libcoap
#
# Copyright (C) 2020 Carlos Gomes Martinho <carlos.gomes_martinho@siemens.com>
# Copyright (C) 2020-2022 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.1
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(
ENABLE_CLIENT_MODE
"compile with support for client mode code"
ON)
option(
ENABLE_SERVER_MODE
"compile with support for server mode code"
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()
if(APPLE)
add_definitions(-D__APPLE_USE_RFC_3542=1)
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(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_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)
# check for symbols
if(WIN32)
set(HAVE_STRUCT_CMSGHDR 1)
else()
check_symbol_exists(
CMSG_FIRSTHDR
sys/socket.h
HAVE_STRUCT_CMSGHDR)
endif()
if(${ENABLE_CLIENT_MODE})
set(COAP_CLIENT_SUPPORT "1")
message(STATUS "compiling with client support")
else()
message(STATUS "compiling without client support")
endif()
if(${ENABLE_SERVER_MODE})
set(COAP_SERVER_SUPPORT "1")
message(STATUS "compiling with server support")
else()
message(STATUS "compiling without server support")
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()
execute_process(COMMAND git describe --tags --dirty --always
RESULT_VARIABLE USING_GIT
OUTPUT_VARIABLE LIBCOAP_PACKAGE_BUILD
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(NOT ${USING_GIT} EQUAL 0)
set(LIBCOAP_PACKAGE_BUILD ${PROJECT_VERSION})
else()
set(LIBCOAP_PACKAGE_BUILD "${LIBCOAP_PACKAGE_BUILD}")
endif()
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(PACKAGE_BUGREPORT "libcoap-developers@lists.sourceforge.net")
set(LIBCOAP_PACKAGE_VERSION "${PACKAGE_VERSION}")
set(LIBCOAP_PACKAGE_URL "${PACKAGE_URL}")
set(LIBCOAP_PACKAGE_NAME "${PACKAGE_NAME}")
set(LIBCOAP_PACKAGE_STRING "${PACKAGE_STRING}")
set(LIBCOAP_PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}")
message(STATUS "PACKAGE VERSION..................${PACKAGE_VERSION}")
message(STATUS "PACKAGE BUILD....................${LIBCOAP_PACKAGE_BUILD}")
message(STATUS "ENABLE_DTLS:.....................${ENABLE_DTLS}")
message(STATUS "ENABLE_TCP:......................${ENABLE_TCP}")
message(STATUS "ENABLE_CLIENT_MODE:..............${ENABLE_CLIENT_MODE}")
message(STATUS "ENABLE_SERVER_MODE:..............${ENABLE_SERVER_MODE}")
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 "WITH_EPOLL:......................${WITH_EPOLL}")
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(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/coap_address.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_asn1.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_async.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_option.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_prng.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_session.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_subscribe.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_tcp.c
${CMAKE_CURRENT_LIST_DIR}/src/coap_time.c
${CMAKE_CURRENT_LIST_DIR}/src/block.c
${CMAKE_CURRENT_LIST_DIR}/src/encode.c
${CMAKE_CURRENT_LIST_DIR}/src/mem.c
${CMAKE_CURRENT_LIST_DIR}/src/net.c
${CMAKE_CURRENT_LIST_DIR}/src/pdu.c
${CMAKE_CURRENT_LIST_DIR}/src/resource.c
${CMAKE_CURRENT_LIST_DIR}/src/str.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}/coap.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_address.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_async.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_hashkey.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_io.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_option.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_prng.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_session.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_subscribe.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/coap_time.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/block.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/encode.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/libcoap.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/lwippools.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/mem.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/net.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/pdu.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/resource.h
${CMAKE_CURRENT_LIST_DIR}/include/coap${LIBCOAP_API_VERSION}/str.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_MBEDTLS}>:${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}>)
target_compile_options(
${COAP_LIBRARY_NAME}
PUBLIC -DLIBCOAP_PACKAGE_BUILD="${LIBCOAP_PACKAGE_BUILD}")
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 "uthash.h" EXCLUDE
PATTERN "*_internal.h" EXCLUDE)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
FILES_MATCHING
PATTERN "*.h")
if(ENABLE_EXAMPLES)
install(
TARGETS coap-server coap-client coap-rd
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT dev)
if(NOT WIN32)
install(
TARGETS etsi_iot_01 tiny
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT dev)
endif()
endif()
-218
View File
@@ -1,218 +0,0 @@
#######################################################
# Developer information for contributing to libcoap #
#######################################################
1. The basics
~~~~~~~~~~~~~
The libcoap project is a FOSS project that is dual licensed. The maintainer
for the libcoap is Olaf Bergmann <bergmann@tzi.org>.
Any contributions have to be made under the terms of the
license
* BSD 2-Clause (The BSD 2-Clause License)
Contributions made up to 2017-06-01 have been made under the dual
license model BSD 2-Clause and GPL v2+ (The GNU General Public License
2.0 or later).
The used VCS for libcoap is Git, the main repository is living on GitHub.
You can clone (or fork directly on GitHub) on the repository site:
https://github.com/obgm/libcoap
Please refer also to the libcoap website for additional information
https://libcoap.net/
The build environment is grounded on the classical autotools, the GNU GCC and
the LLVM C-compiler (CLang) are supported. The Windows systems are not
currently supported (until someone is creating support for it).
Doxygen is used for creating a HTML based online documentation of the
libcoap library.
2. Communications
~~~~~~~~~~~~~~~~~
The main discussion and development platform for libcoap is the mailing list
on Sourceforge.
No matter if you just have a simple question, some specific problem or
want to discuss some patches, please write it to the mailing list. Please
avoid personal mailings to the maintainer (or some other contributor) if
your questions will probably be in the interest of other users too.
You can subscribe to the list here:
https://lists.sourceforge.net/lists/listinfo/libcoap-developers
The archive of the list can be found on:
https://sourceforge.net/p/libcoap/mailman/libcoap-developers
3. Starting contributing
~~~~~~~~~~~~~~~~~~~~~~~~
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 '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
repository on GitHub:
git clone https://github.com/obgm/libcoap.git
4. Working on the source
~~~~~~~~~~~~~~~~~~~~~~~~
As one golden rule you should work on improvements within *your* own local
development branch! To do so you have to first checkout the 'develop' branch
as local branch and then start on top on this branch your own branch. So
create (or better say checkout) the local 'develop' branch:
cd libcoap
git checkout develop origin/develop
Now you can simply start your own local branch (for example 'my-develop')
with the 'origin/develop' as parent so you can later create the patches
against the the upstream development branch:
git checkout -b my-develop
At this point you can now work as known with git, modify the source, commit
the changes, amend if needed and test your work.
At some point you will have to generate patches to post them on the mailing
list (and/or push your changes into your public Git tree). It's a good idea to
post your patch series on the mailing list so other contributors will see your
work and give further suggestions or discuss your work.
To be able to send a patch series you will now create the series itself as
single patches, this will be going easy with the 'git format-patch' command
against the 'develop' branch, remind this is the upstream main development
branch.
To not mix up your series with probably unrelated patches let git place the
patches within a defined directory. Also, while create the patches, tell git to
create a cover letter patch so you can append some introducing words that will
hold probably explanations why you create the patches in the way you have done.
git format-patch --cover-letter -o ../patches4libcoap
This command will create a patch series in ../patches4libcoap where you find a
patch named '0000-cover-letter.patch'. Please modify this patch with some
useful information's for the mailing list. After finish this you now can send
your patches to libcoap-developers@lists.sourceforge.net
git send-email ../patches4libcoap/* --to=libcoap-developers@lists.sourceforge.net
5. Coding rules
~~~~~~~~~~~~~~~
As every FOSS project the libcoap project needs also some rules for coding.
There are loss but the main of them are important!
5.1 License and Copyright
-------------------------
Every new file must contain a license and the copyright holder(s). Please
take a look into existing files and adopt the needed changes to your new
file(s).
5.2 Source Code Indentation
---------------------------
* For better reading the indentation is set to 2 characters as spaces, this
is depended on the often used nested functions like 'if-else'. Don't use
TABs any there! Avoid trailing white spaces at the end of a line.
It's appropriate to set up a modline like this one at first line within
the source file:
--8<----
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
--->8--
* Single lines within the source code should not be longer then 78
characters.
* If there a functions with a lot of parameters that do not fit into the above
rule split the declaration (in the *.h) and the implementation (in the *.c)
into single lines per parameter. For example like this (from src/block.c):
--8<----
int
coap_add_block(coap_pdu_t *pdu,
unsigned int len,
const unsigned char *data,
unsigned int block_num,
unsigned char block_szx);
--->8--
5.3 Source Code Documentation
-----------------------------
* A useful source code documentation is mandatory. Mostly to be done within the
source code files, but more complex description should be done in extra
README files.
* Please set up/adjust the doxygen documentation if you create new functions or
change existing functions. The doxygen documentation has to be done in the
header files as they are the public part of the libcoap and only use the
@-syntax for doxygen commands (akin to javadoc).
5.4 API Changes
---------------
* Never break the API!
Don't remove old functions and if there some changes are needed in some kind
always provide a wrapper for the old call to let the library be backward
compatible and mark the old function as @deprecated in the doxygen comment.
Please discuss needed changes on the mailing list.
5.5 Patches and Commits
-----------------------
* Git commits must be atomic and contain a declarative subject line (max 50
characters if possible) and a body for a statement if needed.
Use the possibility to write a good explanation why your patch/commit is
handle the changes in the way you have done. Remind that other user can
read your code but not necessary understand why the code is written this
way. Don't use something to generic like "bugfix commit".
* A patch/commit or a series of patches/commits have to ensure that the
whole project is able to build up every thing, in short: Do not break
any make target and test your work.
* Every patch/commit should handle one single logical change. If more than
one patch/commit is needed for a change explain it, respect the point
above. If your subject line become much larger than 50 characters then
typically your patch is to big for one single commit.
* Commit message should begin with a submodule or unit the commit is for. By
this your commit message helps to find thematic other changes. If you have
to search and find something with 'git log | grep [foo]' you will see why
this is useful. Examples:
rd.c: Fixed type-specifier warning
Makefile.am: Added missing src/address.c
address.[hc]: make coap_address_equals() not inline on POSIX
6. Where to start contributing?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are various things you could starting on to contribute, the best
is you simply pick up an issue you blindly see and just improve the
situation. Please take also a look into the file TODO and choose a point
from there or point the maintainer to add other things here too.
* Documentation
We are always lacking on a better documentation on the source code, so
maybe you can improve the doxygen documentation.
Also a good documentation on the usage of the libcoap and the example
binaries is always improvable. So we appreciate any help on this.
* Manual Pages
The source is providing some example binaries which originally just should show
how the libcoap can be used. Right now these binaries are fully usable and
quite more than simple examples on a system. There are man pages for these
binaries available, if you found there is a improvement needed please do so and
write to the mailing list explained in section 2.
Maybe you can write up some good HowTo's on the usage for these binaries.
* HowTo's
The libcoap library has now a lot of functions you can use.
Unfortunately there is no good user guide on how to use the libcoap in
any external project. This means there is no HowTo or CheatSheet for a
programming person available. You want to write up something?
* Missing functionality
There are some features that are still missing inside the libcoap. For
example some DTLS implementations and proxy functionality.
-6
View File
@@ -1,6 +0,0 @@
libcoap is published as open-source software without any warranty of any kind.
Use is permitted under the terms of the simplified BSD 2-Clause license.
It includes public domain software. libcoap binaries may also
include open-source software with their respective licensing terms.
Please refer to LICENSE for further details.
-332
View File
@@ -1,332 +0,0 @@
2022-08-17 Olaf Bergmann <bergmann@tzi.org>
Change summary for version 4.3.1:
* Support for Server only and Client only libcoap builds.
* Add support for repeating requests in coap-client.
* Add in support for defining resources that support multicast.
* Add in more support for async delayed requests.
* Add in support for not closing down Observe when closing session.
* Support for RFC7390, RFC8516 and RFC9175.
* Warn when Tokens are re-used.
* Warn when Options are repeated that are not defined as being
repeatable.
* Support for TLS when using Mbed TLS library.
* support for Mbed TLS 3.1
* Add in BERT support for block handling.
* More rigorous error handling for Block transfers.
* Support for using external or submodule TinyDTLS.
* Cmake - add in Apple build support.
* Source files renamed to be more consistent in naming.
* Update native Windows VC builds to use libcoap-3 instead of libcoap-2.
* Reported bugs fixed.
* Example applications Help report include build version.
* Documentation added and updated (Doxygen and man).
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:
* DTLS support improvements (OpenSSL, GnuTLS, tinydtls)
* Pre-shared keys, X.509 certificates
* new session abstraction
* TCP and TLS support
* improved documentation; manual pages
* changes in internal PDU structure
* improved examples (DTLS usage, block-wise transfer)
* docker images for continuous integration
* support for Google OSS fuzzer
* MS Visual Studio project for Windows builds
2017-07-10 Olaf Bergmann <bergmann@tzi.org>
* DTLS support (OpenSSL, tinyDTLS) by Jean-Claude Michelou
* Win32 support by Jean-Claude Michelou
* New Session API by Jean-Claude Michelou
2016-02-16 Olaf Bergmann <bergmann@tzi.org>
* Fixed build for Contiki3 and LwIP
* .travis.yml: Enabled continuous integration for platforms
POSIX and Contiki
2015-03-11 Olaf Bergmann <bergmann@tzi.org>
* include/coap/resource.h: Replaced custom list structures by
utlist macros.
2015-03-09 Olaf Bergmann <bergmann@tzi.org>
* src/uri.c (coap_split_path): Fixed URI parser bug and
removed broken parse iterator.
2015-03-05 Olaf Bergmann <bergmann@tzi.org>
* src/coap_time.c (coap_ticks): Changed POSIX implementation
to fixed point arithmetic and removed clock_offset.
2015-02-21 Olaf Bergmann <bergmann@tzi.org>
* net.c (coap_send_confirmed): Use fixed point arithmetic
to calculate retransmission timeout.
2015-02-20 Olaf Bergmann <bergmann@tzi.org>
* coap_list.[hc]: Moved old list implementation into
sub-directory examples and replaced by linked lists
from utlist.h. As a result, the list must be sorted
explicitly with LL_SORT).
2015-02-19 Olaf Bergmann <bergmann@tzi.org>
* net.c (coap_send_confirmed): Fixed retransmission timeout
calculation and renamed transmission parameters according to
Section 4.8 of RFC 7252.
2015-02-17 Olaf Bergmann <bergmann@tzi.org>
* major rework to get Contiki and lwip running
* many fixed bugs and warnings
2014-06-18 Olaf Bergmann <bergmann@tzi.org>
* mem.c (coap_malloc_type): New functions for allocating memory.
On POSIX systems, coap_malloc_type() and coap_free_type() are just
wrapper functions for malloc() and free(), while on Contiki and
LWIP distinct arrays are used for each type.
2014-03-09 Olaf Bergmann <bergmann@tzi.org>
* net.c (coap_cancel): Removed 7.31 again and implemented new
method for cancelling observe relationships.
2014-02-25 Olaf Bergmann <bergmann@tzi.org>
* net.c (coap_cancel): Handling of 7.31 responses to cancel
notifications (see Section 4.6 of draft-ietf-core-observe-12)
2014-02-04 Olaf Bergmann <bergmann@tzi.org>
* resource.c (coap_print_link): This function now takes an offset
where printing starts. This is used for generating blocks on the
fly.
* net.c (wellknown_response): Added support for Block2 options
when generating a response for .well-known/core.
* block.h (coap_opt_block_num): Fixed handling of zero-length
options. COAP_OPT_BLOCK_LAST now returns NULL when the option
value's length is zero.
2014-01-07 Olaf Bergmann <bergmann@tzi.org>
* resource.c (coap_print_link): Output partial resource
descriptions. The function now provides a sliding window over the
textual representation of the resource. Output starts at the given
offset and ends at the buffer's upper bound. The meaning of the
return value has changed to allow distinguishing whether or not
the resource description has been truncated at the buffer's upper
bound.
(print_wellknown): Support for the new coap_print_link(). An
additional parameter now is used to provide the offset into the
resource description. The meaning of the return value has been
adjusted accordingly.
2013-12-23 Olaf Bergmann <bergmann@tzi.org>
* configure.in: merged with LWIP port from chrysn
<https://git.gitorious.org/coap-lwip/coap-lwip.git>. This
introduces new compiler flags WITH_POSIX and WITH_LWIP to
distinguish target platforms.
2013-09-03 Olaf Bergmann <bergmann@tzi.org>
* option.h (coap_option_setb): increased size of option type
argument
* tests/test_error_response.c (t_init_error_response_tests): new
tests for error response generation
* tests/test_pdu.c (t_encode_pdu5): fixed number for option Accept
* net.c (coap_new_error_response): fixed option size calculation
2013-07-04 Olaf Bergmann <bergmann@tzi.org>
* net.c (coap_new_context): register critical Accept option
* pdu.c: option codes for Accept and Size1 according to coap-18
2013-02-01 Olaf Bergmann <bergmann@tzi.org>
* coap_time.h (coap_clock_init_impl): fix invalid preprocessor
directive. #warning is now only used for gcc only (close sf bug #15)
* net.c (wellknown_response): applied patch from chrysn to
fix bug in generation of .well-known/core representation
2013-01-21 Olaf Bergmann <bergmann@tzi.org>
* option.h: renamed option field in coap_opt_iterator_t to
next_option to detect erroneous use in old code
2013-01-18 Olaf Bergmann <bergmann@tzi.org>
* configure.in: new option --with-tests to enable unit tests
* tests/testdriver.c: unit tests for parser functions
* pdu.c (coap_pdu_parse): new PDU parser for Klaus-encoding
according to coap-13
* net.c (coap_read): call coap_pdu_parse() to check PDU integrity
* option.c: Klaus-encoding for coap-13, including new option
iterator interface
2012-11-20 Olaf Bergmann <bergmann@tzi.org>
* net.c (next_option_safe): made option parsing more robust in
presence of option jumps
* pdu.h: new option codes from draft-ietf-core-coap-12
* option.c (coap_opt_setlength): new function to set option length
* uri.c (make_decoded_option): use coap_opt_setlength() instead of
obsolete macro COAP_OPT_SETLENGTH.
2012-11-19 Olaf Bergmann <bergmann@tzi.org>
* uri.c (make_decoded_option): use coap_opt_encode() instead of writing
2012-11-03 Olaf Bergmann <bergmann@tzi.org>
* net.c (coap_read): read new option encoding
2012-11-01 Olaf Bergmann <bergmann@tzi.org>
* option.c (coap_opt_size, coap_opt_value, coap_opt_length):
several functions to access fields of options (possibly preceeded
by option jump)
2012-10-25 Olaf Bergmann <bergmann@tzi.org>
* option.c (coap_opt_encode): new function for option encoding
with option jumps
2012-03-23 Olaf Bergmann <bergmann@tzi.org>
* examples/client.c (clear_obs): clear observation relationship after
user-specified duration
2012-03-21 Olaf Bergmann <bergmann@tzi.org>
* resource.c (print_wellknown): filtering by attributes
2012-03-19 Olaf Bergmann <bergmann@tzi.org>
* pdu.c (coap_add_option): allow more than 15 options.
2012-03-15 Olaf Bergmann <bergmann@tzi.org>
* examples/client.c (cmdline_uri): split path and query here to
make it easier to include these options in subsequent requests for
block transfer.
2012-03-14 Olaf Bergmann <bergmann@tzi.org>
* examples/etsi_iot_01.c: Support for POST, PUT, DELETE on /test
2012-03-13 Olaf Bergmann <bergmann@tzi.org>
* encode.c (coap_encode_var_bytes): more efficient coding for 0
2012-03-11 Olaf Bergmann <bergmann@tzi.org>
* examples/etsi_iot_01.c: Test cases for 1st ETSI CoAP Plugtest,
March 24/25, 2012 in Paris, France.
2012-03-10 Olaf Bergmann <bergmann@tzi.org>
* block.c: support for block transfer.
2012-03-07 Olaf Bergmann <bergmann@tzi.org>
* examples/client.c (usage): new command line options
-B to set timeout after which the main loop is left.
-e to specify a payload (incompatible with -f)
(message_handler): bugfixes
* resource.h: (coap_method_handler_t): new API for method handlers.
Copyright 2012 Olaf Bergmann, TZI
Copying and distribution of this file, with or without modification, are
permitted provided the copyright notice and this notice are preserved.
-7
View File
@@ -1,7 +0,0 @@
FROM obgm/libcoap:build-env
ENV libcoap_dir=/libcoap
ADD . $libcoap_dir
WORKDIR $libcoap_dir
RUN ./autogen.sh --clean && ./autogen.sh
-98
View File
@@ -1,98 +0,0 @@
############################################################################
#
# 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 ..
-50
View File
@@ -1,50 +0,0 @@
############################################################################
#
# 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 ..
-90
View File
@@ -1,90 +0,0 @@
############################################################################
#
# 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
View File
@@ -1,129 +0,0 @@
#
# 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]
-85
View File
@@ -1,85 +0,0 @@
Copyright (c) 2010--2022, Olaf Bergmann and others
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================
getopt.c
License information for getopt.c. This file is only used on Windows
builds of the executables in the examples folder:
/*
* This file was copied from the following newsgroup posting:
*
* Newsgroups: mod.std.unix
* Subject: public domain AT&T getopt source
* Date: 3 Nov 85 19:34:15 GMT
*
* Here's something you've all been waiting for: the AT&T public domain
* source for getopt(3). It is the code which was given out at the 1985
* UNIFORUM conference in Dallas. I obtained it by electronic mail
* directly from AT&T. The people there assure me that it is indeed
* 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
Binaries that are linked against OpenSSL include software developed
by the OpenSSL Project for use in the OpenSSL Toolkit.
(http://www.openssl.org/). Please consult the OpenSSL license
(https://www.openssl.org/source/license.html) for licensing terms.
========================================================================
GnuTLS
When compiled with GnuTLS support, this software includes components
that are licensed under the terms of the the GNU Lesser General Public
License, version 2.1
(https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
========================================================================
tinyDTLS
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).
-281
View File
@@ -1,281 +0,0 @@
# Makefile.am for libcoap
#
# Copyright (C) 2010-2022 Olaf Bergmann <bergmann@tzi.org>
# Copyright (C) 2015-2017 Carsten Schoenert <c.schoenert@t-online.de>
# Copyright (C) 2018-2022 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.
## Place generated object files (.o) into the same directory as their source
## files, in order to avoid collisions when non-recursive make is used.
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
LIBCOAP_PACKAGE_BUILD = @DOLLAR_SIGN@(shell git describe --tags --dirty --always 2>/dev/null || echo @PACKAGE_VERSION@)
## 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 \
tests/test_pdu.h \
tests/test_sendqueue.h \
tests/test_session.h \
tests/test_tls.h \
tests/test_uri.h \
tests/test_wellknown.h \
win32/coap-client/coap-client.vcxproj \
win32/coap-client/coap-client.vcxproj.filters \
win32/coap-rd/coap-rd.vcxproj \
win32/coap-rd/coap-rd.vcxproj.filters \
win32/coap-server/coap-server.vcxproj \
win32/coap-server/coap-server.vcxproj.filters \
win32/libcoap.sln \
win32/libcoap.vcxproj \
win32/libcoap.vcxproj.filters \
win32/testdriver/testdriver.vcxproj \
win32/testdriver/testdriver.vcxproj.filters \
win32/testdriver/testdriver.vcxproj.user
AM_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include $(WARNING_CFLAGS) \
$(DTLS_CFLAGS) -std=c99 $(EXTRA_CFLAGS) \
-DLIBCOAP_PACKAGE_BUILD='"$(LIBCOAP_PACKAGE_BUILD)"'
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
## time.
## The libtool archive file (.la) will be installed into the directory named
## by the predefined variable $(bindir), along with the actual shared library
## file (.so).
lib_LTLIBRARIES = libcoap-@LIBCOAP_NAME_SUFFIX@.la
libcoap_@LIBCOAP_NAME_SUFFIX@_la_CFLAGS = \
-fPIC \
-fPIE \
$(AM_CFLAGS)
## Define the source file list for the "libcoap.la" target.
## Note that it is not necessary to list header files which are already listed
## elsewhere in a _HEADERS variable assignment.
libcoap_@LIBCOAP_NAME_SUFFIX@_la_SOURCES = \
src/block.c \
src/coap_address.c \
src/coap_asn1.c \
src/coap_async.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_option.c \
src/coap_prng.c \
src/coap_session.c \
src/coap_subscribe.c \
src/coap_tcp.c \
src/coap_time.c \
src/coap_tinydtls.c \
src/encode.c \
src/mem.c \
src/net.c \
src/pdu.c \
src/resource.c \
src/str.c \
src/uri.c
## Define the list of public header files and their install location.
## The API version is appended to the install folder to being able to
## co-install various versions of libcoap.
libcoap_includedir = $(includedir)/coap$(LIBCOAP_API_VERSION)/
# If there is a API change to something $(LIBCOAP_API_VERSION) > 1 the install
# prefix for the header files has to change to not conflict the older version
# if the user want's to install both versions. There will be something used like
# libcoap_include_HEADERS = \
# $(top_srcdir)/include/coap-$(LIBCOAP_API_VERSION)/*
libcoap_include_HEADERS = \
$(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_address.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_async.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 \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_forward_decls.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_hashkey.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_io.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_mutex.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_option.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_session.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_subscribe.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_time.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/encode.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/libcoap.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/mem.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/net.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/pdu.h \
$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION)/coap_prng.h \
$(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)/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,
## so that all version information is kept in one place.
libcoap_@LIBCOAP_NAME_SUFFIX@_la_LDFLAGS = \
-version-info $(LT_LIBCOAP_CURRENT):$(LT_LIBCOAP_REVISION):$(LT_LIBCOAP_AGE) \
@libcoap_SYMBOLS@ \
$(DTLS_LIBS) \
-pie
## 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_pdu_from_pbuf \
"
# This helper is called by libcoap-$(LIBCOAP_API_VERSION).{map,sym} to see if
# configure has detected a usable version of the ctags program and aborts if not.
check_ctags:
@if [ "$(CTAGS_PROG)" = "" ]; then \
echo ;\
echo "There was no ctags program found by the configure script!" ;\
echo "ctags is needed for running this target! Please note the warning about the missed ctags program of the configure script." ;\
echo ;\
exit 1;\
fi
## Helper target to generate the symbol table needed by libtool.
## The .map format is used when ld supports linker scripts, otherwise
## it must fall back to a plain symbol file.
update-map-file: libcoap-$(LIBCOAP_API_VERSION).map libcoap-$(LIBCOAP_API_VERSION).sym
libcoap-$(LIBCOAP_API_VERSION).map: check_ctags $(libcoap_include_HEADERS)
( echo "VER_$(LIBCOAP_API_VERSION) {" ; \
echo "global:" ; \
$(CTAGS_PROG) $(CTAGS_IGNORE) -f - --c-kinds=p $(libcoap_include_HEADERS) | awk '/^coap_/ { print " " $$1 ";" }' | sort -u ; \
echo "local:" ; \
echo " *;" ; \
echo "};" ) > $(top_builddir)/$@.new
mv $(top_builddir)/$@.new $(top_builddir)/$@
libcoap-$(LIBCOAP_API_VERSION).sym: check_ctags $(libcoap_include_HEADERS)
( $(CTAGS_PROG) $(CTAGS_IGNORE) -f - --c-kinds=p $(libcoap_include_HEADERS) | awk '/^coap_/ { print $$1 }' | sort -u ) \
> $(top_builddir)/$@.new
mv $(top_builddir)/$@.new $(top_builddir)/$@
## Install the generated pkg-config file (.pc) into the expected location for
## architecture-dependent package configuration information. Occasionally,
## pkg-config files are also used for architecture-independent data packages,
## in which case the correct install location would be $(datadir)/pkgconfig.
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libcoap-$(LIBCOAP_NAME_SUFFIX).pc
## Define an independent executable script for inclusion in the distribution
## archive. However, it will not be installed on an end user's system due to
## 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
## need to call the target update-map-file after the configure script was
## running!
clean-local:
-find \( -name '*.gcda' -o -name '*.gcno' -o -name '*.gcov' \) -delete
distclean-local:
@rm -f src/*.o src/*.lo
rm -f libcoap-$(LIBCOAP_API_VERSION).map
rm -f libcoap-$(LIBCOAP_API_VERSION).sym
rm -f libcoap-$(LIBCOAP_NAME_SUFFIX).pc
@echo
@echo " ---> Please note the following important advice! <---"
@echo " The files libcoap-$(LIBCOAP_API_VERSION).{map,sym} are removed by the distclean target!"
@echo " To regenerate this two files you need to call 'make update-map-file' first before any"
@echo " other Make target. Otherwise the build of libcoap will fail!"
@echo
## Ensure we have actual *.{map,sym} files if we create a release tarball.
dist-local: update-map-file
## Finaly some phony targets, just to ensure those targets are always buildable
## no matter if the user has created same called files.
.PHONY: update-map-file check_ctags
-7
View File
@@ -1,7 +0,0 @@
libcoap_src = pdu.c net.c coap_cache.c coap_debug.c encode.c uri.c coap_subscribe.c resource.c str.c coap_option.c coap_async.c block.c mem.c coap_io.c coap_session.c coap_notls.c coap_hashkey.c coap_address.c coap_tcp.c
libcoap_dir := $(filter %libcoap,$(APPDS))
vpath %c $(libcoap_dir)/src
# set include path for coap sources
CFLAGS += -I$(libcoap_dir)/include
View File
-103
View File
@@ -1,103 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- OAT(OSS Audit Tool) configuration guide:
basedir: Root dir, the basedir + project path is the real source file location.
licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
tasklist(only for batch mode):
1. task: Define oat check thread, each task will start a new thread.
2. task name: Only an name, no practical effect.
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
5. task project: Projects to be checked, the path field define the source root dir of the project.
policyList:
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type:
"compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules.
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
Note:If the text contains special characters, please escape them according to the following rules:
" == &gt;
& == &gt;
' == &gt;
< == &gt;
> == &gt;
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<filefilterlist>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filteritem type="filename" name="CONTRIBUTE" desc="Contributions made up to 2017-06-01 have been made under the dual license model BSD 2-Clause and GPL v2+ (The GNU General Public License 2.0 or later). We just use use BSD."/>
<filteritem type="filename" name="COPYING" desc="We just use use BSD. getopt.c, OpenSSL, GnuTLS or tinyDTLS are not be used."/>
<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."/>
<filteritem type="filepath" name="m4/ax_check_link_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."/>
<filteritem type="filepath" name="doc/Doxyfile.in" desc="无license头。该文件为API文档生产脚本。"/>
<filteritem type="filepath" name="AUTHORS" desc="无license头。该文件为作者名单列表信息。"/>
</filefilter>
</filefilterlist>
<licensematcherlist>
<licensematcher name="BSD 2-Clause License" desc="如果工具扫描是InvalidLicense,可在此定义匹配规则,注意引号要转义" >
<licensetext name="
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED" desc="匹配此条目的为BSD 2-Clause License"/>
</licensematcher>
<licensematcher name="BSD 3-Clause License" desc="如果工具扫描是InvalidLicense,可在此定义匹配规则,注意引号要转义" >
<licensetext name="
Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED" desc="匹配此条目的为BSD 3-Clause License"/>
</licensematcher>
</licensematcherlist>
</oatconfig>
</configuration>
-1
View File
@@ -1 +0,0 @@
README.md
-11
View File
@@ -1,11 +0,0 @@
[
{
"Name": "libcoap: C-Implementation of CoAP",
"License": "BSD 2-Clause License",
"License File": "LICENSE",
"Version Number": "4.3.1",
"Owner": "wanghan76@huawei.com",
"Upstream URL": "https://github.com/obgm/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."
}
]
-89
View File
@@ -1,89 +0,0 @@
# libcoap: A C implementation of the Constrained Application Protocol (RFC 7252)
[![Build Status: main](https://github.com/obgm/libcoap/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/obgm/libcoap/actions?query=branch:main)
[![Build Status: develop](https://github.com/obgm/libcoap/actions/workflows/main.yml/badge.svg?branch=develop)](https://github.com/obgm/libcoap/actions?query=branch:develop)
[![Static Analysis](https://scan.coverity.com/projects/10970/badge.svg?flat=1)](https://scan.coverity.com/projects/obgm-libcoap)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/libcoap.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:libcoap)
Copyright (C) 2010—2022 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)
* RFC7390: Group Communication for 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]
* RFC8516: "Too Many Requests" Response Code for the Constrained Application Protocol
* RFC8768: Constrained Application Protocol (CoAP) Hop-Limit Option
* RFC9175: CoAP: Echo, Request-Tag, and Token Processing
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]
* 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.
-27
View File
@@ -1,27 +0,0 @@
This is a simple file for all kinds of stuff related on development for
libcoap. Please append (and remove) any issue you think its worthy.
Classification of issues:
Critical -> Break the library in some kind or a missing feature, maybe not
directly but later
Serious -> No regression on the user side, more likly on the libcoap
development
Minor -> Things that are nice to have, but they are not time critical
=================
* CRITICAL ISSUES
=================
================
* SERIOUS ISSUES
================
-> Create some development rules like:
--> How to submit patches? What about pull requests?
--> How to implement/change platform related code?
-> Further improve the API documentation
==============
* MINOR ISSUES
==============
-> Adding a logo for libcoap
-142
View File
@@ -1,142 +0,0 @@
#!/bin/sh -e
# uncomment the set command for debugging
#set -x
# function to check for needed helper tools
check_helper() {
#echo "Checking for $1 ..."
TOOL=`which "$1" || echo none`
if [ "$TOOL" = "none" ]; then
echo
echo "Couldn't find '$1'!"
RET=1
else
RET=0
fi
}
PROJECT="libcoap"
AUTOGEN_FILES="
INSTALL
aclocal.m4 ar-lib
coap_config.h coap_config.h.in* compile config.guess config.h* config.log config.status config.sub configure
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/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/test_common.h
tests/oss-fuzz/Makefile.ci
m4/libtool.m4 m4/lt~obsolete.m4 m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4
"
AUTOGEN_DIRS="
.deps
.libs autom4te.cache/
doc/html/
examples/.deps/ examples/.libs
man/.deps
man/tmp
src/.deps/ src/.libs/
tests/.deps/
"
# checking for cleaner argument
echo
if [ "$1" = "--clean" ]; then
echo "removing autogenerated files ..."
rm -rf $AUTOGEN_FILES $AUTOGEN_DIRS
echo "done"
exit
else
echo "[HINT] You can run 'autogen.sh --clean' to remove all generated files by the autotools."
echo
fi
# checking for autoreconf
check_helper autoconf
if [ "$RET" = "1" ]; then
echo "You probably need to install the package 'autoconf'."
ERROR=1
else
echo "Found 'autoconf'."
fi
# checking for aclocal
check_helper aclocal
if [ "$RET" = "1" ]; then
echo "You probably need to install the package 'automake'."
ERROR=1
else
echo "Found 'aclocal'."
fi
# checking for pkg-config
check_helper pkg-config
if [ "$RET" = "1" ]; then
echo "You probably need to install the package 'pkg-config|pkgconf'."
ERROR=1
else
echo "Found 'pkg-config'."
fi
# checking for libtool
# The libtool helper maybe installed as 'libtoolize', checking for 'libtool' first.
check_helper libtool
if [ "$RET" = "1" ]; then
# O.k. libtool not found, searching for libtoolize.
check_helper libtoolize
if [ "$RET" = "1" ]; then
echo "You probably need to install the package 'libtool'."
# That's bad, we found nothing!
ERROR=1
else
echo "Found 'libtoolize'."
break
fi
else
echo "Found 'libtool'."
fi
# exit if one tool isn't available
if [ "$ERROR" = "1" ]; then
echo
echo "One or more needed tools are missing, exiting ..."
echo "Please install the needed software packages and restart 'autogen.sh' again."
echo
exit 1
fi
echo
echo " ---> Found all needed tools! That's fine."
echo
# countinue otherwise
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.
# Creating the directory m4 before calling autoreconf to
# not struggle with old versions of aclocal.
mkdir -p $srcdir/m4
# create ar-lib if not present to avoid autoreconf throwing an error
# when the file is missing. As autoreconf is called with --force
# the file will get updated with the proper contents afterwards.
touch ar-lib
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 "Otherwise process the configure script to create the makefiles and generated helper files."
echo
-5
View File
@@ -1,5 +0,0 @@
imagename
build.sh
*~
.*.swp
\#*#
-7
View File
@@ -1,7 +0,0 @@
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 libmbedtls-dev exuberant-ctags git valgrind \
graphviz doxygen libxml2-utils xsltproc docbook-xml docbook-xsl asciidoc
RUN apt-get clean
-36
View File
@@ -1,36 +0,0 @@
FROM obgm/libcoap:build-env
RUN apt-get update && apt-get install -y cmake git g++
RUN apt-get clean
ENV libcoap_dir=/home/libcoap
ADD . $libcoap_dir
WORKDIR $libcoap_dir
RUN ./autogen.sh --clean && ./autogen.sh
RUN ./configure --disable-documentation --enable-tests --enable-examples --with-openssl && make install clean
WORKDIR /home
RUN git clone --depth 1 https://github.com/cabo/cn-cbor.git && cd cn-cbor && ./build.sh all doc install
# The image for development with libcoap
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 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/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
RUN echo "/usr/local/lib" >>/etc/ld.so.conf.d/usr_local.conf && ldconfig /usr/local/lib
ARG user=user
RUN adduser --disabled-password --gecos '' $user
RUN chown -R $user:$user /home/$user
WORKDIR /home/$user
USER $user
EXPOSE 5683 5684
-16
View File
@@ -1,16 +0,0 @@
#! /usr/bin/env bash
pushd $(dirname $0)
. ./imagename
# see https://stackoverflow.com/a/2924755 for switching boldface on/off
bold=$(tput bold)
normal=$(tput sgr0)
echo "${bold}**** Creating build-env image ****${normal}"
docker build -f Dockerfile.build-env -t $USER/$IMAGE:build-env .
echo "${bold}**** Creating develop image ****${normal}"
docker build -f Dockerfile.develop -t $USER/$IMAGE:develop ..
popd
-2
View File
@@ -1,2 +0,0 @@
USER=obgm
IMAGE=libcoap
-30
View File
@@ -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.",
"version": "4.3.1",
"license": "Apache License V2.0, OpenSSL License, BSD 3-Clause License, GPL V1.0, BSD 2-Clause License, GPL V2.0, GPL V3.0, BSD-1-Clause License",
"publishAs": "code-segment",
"segment": {
"destPath": "third_party/libcoap"
},
"dirs": {},
"scripts": {},
"component": {
"name": "libcoap",
"subsystem": "thirdparty",
"syscap": [],
"features": [],
"adapted_system_type": [ "mini", "small", "standard" ],
"deps": {
"components": [],
"third_party": [
"bounds_checking_function"
]
},
"build": {
"sub_component": [],
"inner_kits": [],
"test": []
}
}
}
-25
View File
@@ -1,25 +0,0 @@
# 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
-4
View File
@@ -1,4 +0,0 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@")
-35
View File
@@ -1,35 +0,0 @@
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}")
-88
View File
@@ -1,88 +0,0 @@
# 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}")
-177
View File
@@ -1,177 +0,0 @@
/*
* cmake_coap_config.h -- cmake configuration for libcoap
*
* Copyright (C) 2020 Carlos Gomes Martinho <carlos.gomes_martinho@siemens.com>
* Copyright (C) 2021-2022 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.
*/
#ifndef COAP_CONFIG_H_
#define COAP_CONFIG_H_
#if ! defined(_WIN32)
#define _GNU_SOURCE
#endif
/* 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 library has client support */
#cmakedefine COAP_CLIENT_SUPPORT @COAP_CLIENT_SUPPORT@
/* Define if the library has server support */
#cmakedefine COAP_SERVER_SUPPORT @COAP_SERVER_SUPPORT@
/* 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 `if_nametoindex' function. */
#cmakedefine HAVE_IF_NAMETOINDEX @HAVE_IF_NAMETOINDEX@
/* 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_ */
-215
View File
@@ -1,215 +0,0 @@
#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 255.
*/
#ifndef COAP_OBS_MAX_NON
#define COAP_OBS_MAX_NON 5
#endif /* COAP_OBS_MAX_NON */
#if COAP_OBS_MAX_NON > 255
#error COAP_OBS_MAX_NON is too large
#endif /* COAP_OBS_MAX_NON > 255 */
/**
* Number of different confirmable notifications that may fail (i.e. those
* that have hit MAX_RETRANSMIT multiple times) before an observer is removed.
* The maximum value for COAP_OBS_MAX_FAIL is @c 255.
*/
#ifndef COAP_OBS_MAX_FAIL
#define COAP_OBS_MAX_FAIL 1
#endif /* COAP_OBS_MAX_FAIL */
#if COAP_OBS_MAX_FAIL > 255
#error COAP_OBS_MAX_FAIL is too large
#endif /* COAP_OBS_MAX_FAIL > 255 */
#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_ */
-42
View File
@@ -1,42 +0,0 @@
/*
* coap_config.h.lwip -- LwIP configuration for libcoap
*
* Copyright (C) 2021-2022 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.1"
#define PACKAGE_STRING "libcoap 4.3.1"
#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_ */
-42
View File
@@ -1,42 +0,0 @@
/*
* coap_config.h.lwip -- LwIP configuration for libcoap
*
* Copyright (C) 2021-2022 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_ */
-143
View File
@@ -1,143 +0,0 @@
/*
* coap_config.h.riot -- RIOT configuration for libcoap
*
* Copyright (C) 2021-2022 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.1"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libcoap 4.3.1"
/* 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_ */
-143
View File
@@ -1,143 +0,0 @@
/*
* coap_config.h.riot -- RIOT configuration for libcoap
*
* Copyright (C) 2021-2022 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_ */
-118
View File
@@ -1,118 +0,0 @@
#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 "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.1"
/* 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.1"
/* 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_ */
-118
View File
@@ -1,118 +0,0 @@
#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_ */
-1106
View File
File diff suppressed because it is too large Load Diff
-2612
View File
File diff suppressed because it is too large Load Diff
-288
View File
@@ -1,288 +0,0 @@
# doc/Makefile.am
#
# Copyright (C) 2015-2018 Carsten Schoenert <c.schoenert@t-online.de>
# 2018-2022 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.
CLEANFILES = \
doxygen_sqlite3.db
EXTRA_DIST = \
docbook.local.css \
upgrade_4.2.1_4.3.0.txt \
upgrade_4.3.0_4.3.1.txt \
main.md \
module_api_wrap.h
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
man-page-prepare: man-page-cleanup
@$(MKDIR_P) $(top_builddir)/doc/man_tmp
@$(MKDIR_P) $(top_builddir)/doc/man_html
man-page-start: man-page-prepare
## Setup the man page tab
@echo '' > $(top_builddir)/doc/scratch_insert_file
@echo ' <tab type="usergroup" visible="yes" url="@ref manpage" title="Manual Pages">' > $(top_builddir)/doc/insert_file
@echo ' <tab type="usergroup" visible="yes" url="@ref man_summary" title="Man Pages Summary">' >> $(top_builddir)/doc/insert_file
##
@echo '/** @page manpage Manual Pages' > $(top_builddir)/doc/man_tmp/manpage.dox
@echo ' Here are the libcoap API and Example manual pages:' >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo ' <table class="directory">' >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo " <tr>" >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo " <td class=\"entry\" align=\"left\"> @ref man_summary </td><td class=\"desc\" align=\"left\">Man Pages Summary</td>" >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo " </tr>" >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo " <tr class=\"even\">" >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo " <td class=\"entry\" align=\"left\"> @ref man_individual </td><td class=\"desc\" align=\"left\">Individual Man Pages</td>" >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo " </tr>" >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo " </table>" >> $(top_builddir)/doc/man_tmp/manpage.dox
@echo ' */' >> $(top_builddir)/doc/man_tmp/manpage.dox
##
@echo '/** @page man_summary Manual Pages Summary' > $(top_builddir)/doc/man_tmp/man_summary.dox
@echo ' Here are a list of libcoap API summary man pages, some of which have code examples, and Examples:' >> $(top_builddir)/doc/man_tmp/man_summary.dox
@echo ' <table class="directory">' >> $(top_builddir)/doc/man_tmp/man_summary.dox
##
@echo '/** @page man_individual Individual Manual Pages' > $(top_builddir)/doc/man_tmp/man_individual.dox
@echo ' Here are a list of libcoap API individual man pages, some of which have code examples:' >> $(top_builddir)/doc/man_tmp/man_individual.dox
@echo ' <table class="directory">' >> $(top_builddir)/doc/man_tmp/man_individual.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: 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` ;\
## We need the HTML files from the Asciidoc source files, check if they around, otherwise build them.
if [ "$${COUNT_MAN_FILES}" != "$${COUNT_HTML_FILES}" ]; then \
$(MAKE) -C ../man ;\
fi ;\
##
## Build the summary man pages
##
for FILE in $${MAN_FILES} ; do \
BASE=`basename $${FILE} | cut -d. -f 1` ;\
MANUAL=`egrep -B 1 "^====" $${FILE} | head -1` ;\
SUMMARY=`egrep -B 2 "^SYNOPSIS" $${FILE} | ${SED} 's/coap-//g' | cut -d\- -f2 | cut -c2- | head -1` ;\
##
## Fix and copy .html file across
##
if [ -f $(top_builddir)/man/$${BASE}.html ]; then \
## Correct case sensitive Name and Synopsis on master (used later)
$(SED) -i 's^<h2>Name</h2>^<h2>NAME</h2>^g' $(top_builddir)/man/$${BASE}.html ;\
$(SED) -i 's^<h2>Synopsis</h2>^<h2>SYNOPSIS</h2>^g' $(top_builddir)/man/$${BASE}.html ;\
cp -f $(top_builddir)/man/$${BASE}.html $(top_builddir)/doc/man_html/$${BASE}.html ;\
else \
echo "ERROR: $(top_builddir)/man/$${BASE}.html not found!";\
exit 1 ;\
fi ;\
## Build the manual insert page
echo "/// @page man_$${BASE} $${MANUAL}" > $(top_builddir)/doc/man_tmp/$${MANUAL}.dox ;\
echo "/// @htmlinclude $${BASE}.html $${MANUAL}" >> $(top_builddir)/doc/man_tmp/$${MANUAL}.dox ;\
## Update insert_file (the list is sorted appropriately)
echo " <tab type=\"user\" visible=\"yes\" url=\"@ref man_$${BASE}\" title=\"$${MANUAL} - $${SUMMARY}\" intro=\"\"/>" >> $(top_builddir)/doc/insert_file ;\
## Update the summary man page
echo " <tr$${ROW_EVEN}>" >> $(top_builddir)/doc/man_tmp/man_summary.dox ;\
echo " <td class=\"entry\" align=\"left\"> @ref man_$${BASE} </td><td class=\"desc\" align=\"left\">$${SUMMARY}</td>" >> $(top_builddir)/doc/man_tmp/man_summary.dox ;\
echo " </tr>" >> $(top_builddir)/doc/man_tmp/man_summary.dox ;\
if [ -z "$${ROW_EVEN}" ] ; then \
ROW_EVEN=" class=\"even\"" ;\
else \
ROW_EVEN= ;\
fi \
done ;\
##
## Close off the man page summary file
##
echo ' </table>' >> $(top_builddir)/doc/man_tmp/man_summary.dox ;\
echo ' */' >> $(top_builddir)/doc/man_tmp/man_summary.dox ;\
echo ' </tab>' >> $(top_builddir)/doc/insert_file ;\
##
## Build the individual man pages
##
echo ' <tab type="usergroup" visible="yes" url="@ref man_individual" title="Individual Man Pages">' >> $(top_builddir)/doc/insert_file ;\
for FILE in $${MAN_FILES} ; do \
BASE=`basename $${FILE} | cut -d. -f 1` ;\
LIST=`${SED} -ne '/^NAME/,/^SYNOPSIS/p;/^SYNOPSIS/q' $${FILE} | ${SED} -ne '/coap_/{ s/ *, *//g ; p }' | egrep -v "^$${BASE}$$"` ;\
for ENTRY in $${LIST} ; do \
MANUAL="$${ENTRY}(3)" ;\
## Build the manual insert page
echo "/// @page man_$${ENTRY} $${MANUAL}" > $(top_builddir)/doc/man_tmp/$${MANUAL}.dox ;\
echo "/// @htmlinclude $${ENTRY}.html $${MANUAL}" >> $(top_builddir)/doc/man_tmp/$${MANUAL}.dox ;\
## Create html file
cat $(top_builddir)/man/$${BASE}.html | ${SED} "s/Function: $${ENTRY}(/<a class=\"anchor\" id=\"$${ENTRY}\"><\/a>\0/" > $(top_builddir)/doc/man_html/$${ENTRY}.html ;\
## Update scratch_insert_file for sorting later
echo "$${ENTRY}" >> $(top_builddir)/doc/scratch_insert_file ;\
done ;\
done ;\
##
## Process the (sorted) list of individual man pages
##
for ENTRY in `cat $(top_builddir)/doc/scratch_insert_file | ALL=C sort -u` ; do \
## Update the individual man page
MANUAL="$${ENTRY}(3)" ;\
echo " <tab type=\"user\" visible=\"yes\" url=\"@ref man_$${ENTRY}\" title=\"$${MANUAL}\" intro=\"\"/>" >> $(top_builddir)/doc/insert_file ;\
echo " <tr$${ROW_EVEN}>" >> $(top_builddir)/doc/man_tmp/man_individual.dox ;\
echo " <td class=\"entry\" align=\"left\"> @ref man_$${ENTRY} </td><td class=\"desc\" align=\"left\"></td>" >> $(top_builddir)/doc/man_tmp/man_individual.dox ;\
echo " </tr>" >> $(top_builddir)/doc/man_tmp/man_individual.dox ;\
if [ -z "$${ROW_EVEN}" ] ; then \
ROW_EVEN=" class=\"even\"" ;\
else \
ROW_EVEN= ;\
fi \
done ;\
##
## Close off the individual man pages
##
echo ' </table>' >> $(top_builddir)/doc/man_tmp/man_individual.dox ;\
echo ' */' >> $(top_builddir)/doc/man_tmp/man_individual.dox ;\
echo ' </tab>' >> $(top_builddir)/doc/insert_file ;\
##
## Close off the man page top level
##
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$${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 ;\
##
## Close off the insert file list
##
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 ;\
$(SED) -i '/<tab type="examples" visible=.*/r insert_file' $(top_builddir)/doc/DoxygenLayout.xml ;\
##
## Fix up man html files, adding links
##
for FILE in $${MAN_FILES} `cat $(top_builddir)/doc/scratch_insert_file` ; do \
ENTRY=`basename $${FILE} | cut -d . -f1` ;\
## Functions defined in the body
$(SED) -i "s^\(<span class=\"strong\"><strong>\)\(coap[_-][0-9a-z_]*\)\(</strong></span>(\|(\)^\1<a class=\"st-desc\" href=\"man_\2.html#\2\" target=\"_self\">\2</a>\3^g" $(top_builddir)/doc/man_html/$${ENTRY}.html ;\
## The SYNOPSIS entries
$(SED) -i "s^\(<p><span class=\"strong\"><strong>[a-z0-9_ \*]*\)\(coap_[0-9a-z_]*\)\([(;]\)^\1<a class=\"st-synopsis\" href=\"man_\2.html#\2\" target=\"_self\">\2</a>\3^g" $(top_builddir)/doc/man_html/$${ENTRY}.html ;\
## Function in NAME and Examples
$(SED) -i "s^\([ =,] \|[(!>]\|\^\)\(coap_[0-9a-z_]*\)\([(,]\| \-\| \xe2\x80\x94\)^\1<a href=\"man_\2.html#\2\" target=\"_self\">\2</a>\3^g" $(top_builddir)/doc/man_html/$${ENTRY}.html ;\
## Do for a second time in case of overlaps
$(SED) -i "s^\([ =,] \|[(!>]\|\^\)\(coap_[0-9a-z_]*\)\([(,]\| \-\| \xe2\x80\x94\)^\1<a href=\"man_\2.html#\2\" target=\"_self\">\2</a>\3^g" $(top_builddir)/doc/man_html/$${ENTRY}.html ;\
done ;\
##
## Do the highlighting
##
for ENTRY in `cat $(top_builddir)/doc/scratch_insert_file` ; do \
${SED} -i "s/\($${ENTRY}\)\([<(\*, ]\)/<span class=\"man-highlight\">\1<\/span>\2/g" $(top_builddir)/doc/man_html/$${ENTRY}.html ;\
done
if BUILD_MANPAGES
UPG_LIST = upgrade_4.2.1_4.3.0.txt upgrade_4.3.0_4.3.1.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
@$(RM) $(top_builddir)/doc/insert_file $(top_builddir)/doc/scratch_insert_file
@cp -f $(top_srcdir)/doc/docbook.local.css $(top_builddir)/doc/html/docbook-xsl.css
else
#
# Need to make sure the man directories are in place, but empty
all: man-page-prepare
$(DOXYGEN) Doxyfile
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 $(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
-47
View File
@@ -1,47 +0,0 @@
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;
}
span.man-highlight { background: yellow; }
a.st-desc {
font-weight: bold;
color: black;
text-decoration: none;
}
a.st-desc:visited {
font-weight: bold;
color: black;
text-decoration: none;
}
a.st-desc:hover {
text-decoration: underline;
}
a.st-synopsis {
font-weight: bold;
color: black;
text-decoration: none;
}
a.st-synopsis:visited {
font-weight: bold;
color: black;
text-decoration: none;
}
a.st-synopsis:hover {
text-decoration: underline;
}
-69
View File
@@ -1,69 +0,0 @@
libcoap {#mainpage}
=======
A C implementation of the Constrained Application Protocol (RFC 7252)
=====================================================================
Copyright (C) 2010--2022 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.
The following RFCs are supported
* RFC7252: The Constrained Application Protocol (CoAP)
* RFC7390: Group Communication for 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]
* RFC8516: "Too Many Requests" Response Code for the Constrained Application Protocol
* RFC8768: Constrained Application Protocol (CoAP) Hop-Limit Option
* RFC9175: CoAP: Echo, Request-Tag, and Token Processing
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]
* TinyDTLS [PSK and RPK] [DTLS Only]
Documentation
=============
This set of pages contains the current set of documention for the libcoap APIs.
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 in the source.
-21
View File
@@ -1,21 +0,0 @@
/* doc/module_api_wrap.h
*
* Copyright (C) 2021-2022 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.
*/
/**
* @file module_api_wrap.h
* @brief Doxygen specific wrapper for Modules layout
*/
/**
* @defgroup application_api Application API
* Application API Structures, Macros, Typedefs, Enums and Functions
* @defgroup internal_api Libcoap Internal API
* libcoap Internal API Structures, Macros, Typedefs, Enums and Functions
*/
-431
View File
@@ -1,431 +0,0 @@
= 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.
-6
View File
@@ -1,6 +0,0 @@
= Upgrade from 4.3.0 to 4.3.1
== Summary
The source and binary APIs are the same for 4.3.0 and 4.3.1 with just extra
functionality making it forward, but not necessarily backward compatible.
-129
View File
@@ -1,129 +0,0 @@
# examples/Makefile.am
#
# Copyright (C) 2015 Carsten Schoenert <c.schoenert@t-online.de>
# Copyright (C) 2018-2022 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 \
$(WARNING_CFLAGS) $(DTLS_CFLAGS) -std=c99 $(EXTRA_CFLAGS)
#
bin_PROGRAMS =
noinst_PROGRAMS =
check_PROGRAMS =
if HAVE_CLIENT_SUPPORT
bin_PROGRAMS += coap-client@LIBCOAP_DTLS_LIB_EXTENSION_NAME@
check_PROGRAMS += coap-tiny
if BUILD_ADD_DEFAULT_NAMES
noinst_PROGRAMS += coap-client
endif # BUILD_ADD_DEFAULT_NAMES
endif # HAVE_CLIENT_SUPPORT
if HAVE_SERVER_SUPPORT
bin_PROGRAMS += coap-server@LIBCOAP_DTLS_LIB_EXTENSION_NAME@ \
coap-rd@LIBCOAP_DTLS_LIB_EXTENSION_NAME@
check_PROGRAMS += coap-etsi_iot_01
if BUILD_ADD_DEFAULT_NAMES
noinst_PROGRAMS += coap-server coap-rd
endif # BUILD_ADD_DEFAULT_NAMES
if ! HAVE_CLIENT_SUPPORT
coap_server_CPPFLAGS=-DSERVER_CAN_PROXY=0
coap_server@LIBCOAP_DTLS_LIB_EXTENSION_NAME@_CPPFLAGS=-DSERVER_CAN_PROXY=0
endif # HAVE_CLIENT_SUPPORT
endif # HAVE_SERVER_SUPPORT
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_rd_SOURCES = coap-rd.c
coap_rd_LDADD = $(DTLS_LIBS) \
$(top_builddir)/.libs/libcoap-$(LIBCOAP_NAME_SUFFIX).la
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_tiny_SOURCES = tiny.c
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
-43
View File
@@ -1,43 +0,0 @@
This README documents the test cases supported for the 1st ETSI CoAP
plugtest on March 24/25 in Paris, France.
<http://www.etsi.org/plugtests/coap/coap.htm>
Legend:
[+] full support
[o] partial support
[-] no support
[?] needs check
[ ] has open issues
Mandatory Tests
[+] TD_COAP_CORE_01 Perform GET transaction (CON mode)
[+] TD_COAP_CORE_02 Perform POST transaction (CON mode)
[+] TD_COAP_CORE_03 Perform PUT transaction (CON mode)
[+] TD_COAP_CORE_04 Perform DELETE transaction (CON mode)
[+] TD_COAP_CORE_05 Perform GET transaction (NON mode)
[+] TD_COAP_CORE_06 Perform POST transaction (NON mode)
[+] TD_COAP_CORE_07 Perform PUT transaction (NON mode)
[+] TD_COAP_CORE_08 Perform DELETE transaction (NON mode)
[+] TD_COAP_CORE_09 Perform GET transaction with delayed response (CON mode, no piggyback)
[+] TD_COAP_CORE_10 Handle request containing Token option
[+] TD_COAP_CORE_11 Handle request not containing Token option
[+] TD_COAP_CORE_12 Handle request containing several Uri-Path options
[+] TD_COAP_CORE_13 Handle request containing several Uri-Query options
[?] TD_COAP_CORE_14 Interoperate in lossy context (CON mode, piggybacked response)
[?] TD_COAP_CORE_15 Interoperate in lossy context (CON mode, delayed response)
Optional Tests
[ ] TD_COAP_LINK_01 Access to well-known interface for resource discovery
[-] TD_COAP_LINK_02 Use filtered requests for limiting discovery results
[+] TD_COAP_BLOCK_01 Handle GET blockwise transfer for large resource (early negotiation)
[+] TD_COAP_BLOCK_02 Handle GET blockwise transfer for large resource (late negotiation)
[-] TD_COAP_BLOCK_03 Handle PUT blockwise transfer for large resource
[-] TD_COAP_BLOCK_04 Handle POST blockwise transfer for large resource
[-] TD_COAP_OBS_01 Handle resource observation
[-] TD_COAP_OBS_02 Stop resource observation
[-] TD_COAP_OBS_03 Client detection of deregistration (Max-Age)
[-] TD_COAP_OBS_04 Server detection of deregistration (client OFF)
[-] TD_COAP_OBS_05 Server detection of deregistration (explicit RST)
File diff suppressed because it is too large Load Diff
-879
View File
@@ -1,879 +0,0 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 * -*- */
/* coap -- simple implementation of the Constrained Application Protocol (CoAP)
* as defined in RFC 7252
*
* Copyright (C) 2010--2015,2022 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-rd.c
* @brief CoRE resource directory
*
* @see https://tools.ietf.org/html/draft-ietf-core-resource-directory
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <signal.h>
#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>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <dirent.h>
#endif
#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 {
size_t etag_len; /**< actual length of @c etag */
unsigned char etag[8]; /**< ETag for current description */
coap_string_t data; /**< points to the resource description */
} rd_t;
rd_t *resources = NULL;
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) {
rd_t *rd;
rd = (rd_t *)coap_malloc(sizeof(rd_t));
if (rd)
memset(rd, 0, sizeof(rd_t));
return rd;
}
static void
rd_delete(rd_t *rd) {
if (rd) {
coap_free(rd->data.s);
coap_free(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 COAP_UNUSED) {
quit = 1;
}
static void
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 = coap_resource_get_userdata(resource);
unsigned char buf[3];
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_APPLICATION_LINK_FORMAT),
buf);
if (rd && rd->etag_len)
coap_add_option(response, COAP_OPTION_ETAG, rd->etag_len, rd->etag);
if (rd && rd->data.s)
coap_add_data(response, rd->data.length, rd->data.s);
}
static void
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
coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_IMPLEMENTED);
#else /* FIXME */
coap_opt_iterator_t opt_iter;
coap_opt_t *token, *etag;
coap_pdu_t *response;
size_t size = sizeof(coap_hdr_t);
int type = (request->hdr->type == COAP_MESSAGE_CON)
? COAP_MESSAGE_ACK : COAP_MESSAGE_NON;
rd_t *rd = NULL;
unsigned char code; /* result code */
const uint8_t *data;
coap_string_t tmp;
HASH_FIND(hh, resources, resource->uri_path.s, resource->uri_path.length, rd);
if (rd) {
/* found resource object, now check Etag */
etag = coap_check_option(request, COAP_OPTION_ETAG, &opt_iter);
if (!etag || (COAP_OPT_LENGTH(etag) != rd->etag_len)
|| memcmp(COAP_OPT_VALUE(etag), rd->etag, rd->etag_len) != 0) {
if (coap_get_data(request, &tmp.length, &data)) {
tmp.s = (unsigned char *)coap_malloc(tmp.length);
if (!tmp.s) {
coap_log(LOG_DEBUG,
"hnd_put_rd: cannot allocate storage for new rd\n");
code = COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE;
goto finish;
}
coap_free(rd->data.s);
rd->data.s = tmp.s;
rd->data.length = tmp.length;
memcpy(rd->data.s, data, rd->data.length);
}
}
if (etag) {
rd->etag_len = min(COAP_OPT_LENGTH(etag), sizeof(rd->etag));
memcpy(rd->etag, COAP_OPT_VALUE(etag), rd->etag_len);
}
code = COAP_RESPONSE_CODE_CHANGED;
/* FIXME: update lifetime */
} else {
code = COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE;
}
finish:
/* FIXME: do not create a new response but use the old one instead */
response = coap_pdu_init(type, code, request->hdr->id, size);
if (!response) {
coap_log(LOG_DEBUG, "cannot create response for mid=0x%x\n",
request->hdr->id);
return;
}
if (request->hdr->token_length)
coap_add_token(response, request->hdr->token_length, request->hdr->token);
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_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 = coap_resource_get_userdata(resource);
if (rd) {
rd_delete(rd);
}
/* FIXME: link attributes for resource have been created dynamically
* using coap_malloc() and must be released. */
coap_delete_resource(NULL, resource);
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
}
static void
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];
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_APPLICATION_LINK_FORMAT),
buf);
coap_add_option(response,
COAP_OPTION_MAXAGE,
coap_encode_var_safe(buf, sizeof(buf), 0x2ffff), buf);
}
static int
parse_param(const uint8_t *search,
size_t search_len,
unsigned char *data,
size_t data_len,
coap_string_t *result) {
if (result)
memset(result, 0, sizeof(coap_string_t));
if (!search_len)
return 0;
while (search_len <= data_len) {
/* handle parameter if found */
if (memcmp(search, data, search_len) == 0) {
data += search_len;
data_len -= search_len;
/* key is only valid if we are at end of string or delimiter follows */
if (!data_len || *data == '=' || *data == '&') {
while (data_len && *data != '=') {
++data; --data_len;
}
if (data_len > 1 && result) {
/* value begins after '=' */
result->s = ++data;
while (--data_len && *data != '&') {
++data; result->length++;
}
}
return 1;
}
}
/* otherwise proceed to next */
while (--data_len && *data++ != '&')
;
}
return 0;
}
static void
add_source_address(coap_resource_t *resource,
const coap_address_t *peer) {
#define BUFSIZE 64
char *buf;
size_t n = 1;
coap_str_const_t attr_val;
buf = (char *)coap_malloc(BUFSIZE);
if (!buf)
return;
buf[0] = '"';
switch(peer->addr.sa.sa_family) {
case AF_INET:
/* FIXME */
break;
case AF_INET6:
n += snprintf(buf + n, BUFSIZE - n,
"[%02x%02x:%02x%02x:%02x%02x:%02x%02x" \
":%02x%02x:%02x%02x:%02x%02x:%02x%02x]",
peer->addr.sin6.sin6_addr.s6_addr[0],
peer->addr.sin6.sin6_addr.s6_addr[1],
peer->addr.sin6.sin6_addr.s6_addr[2],
peer->addr.sin6.sin6_addr.s6_addr[3],
peer->addr.sin6.sin6_addr.s6_addr[4],
peer->addr.sin6.sin6_addr.s6_addr[5],
peer->addr.sin6.sin6_addr.s6_addr[6],
peer->addr.sin6.sin6_addr.s6_addr[7],
peer->addr.sin6.sin6_addr.s6_addr[8],
peer->addr.sin6.sin6_addr.s6_addr[9],
peer->addr.sin6.sin6_addr.s6_addr[10],
peer->addr.sin6.sin6_addr.s6_addr[11],
peer->addr.sin6.sin6_addr.s6_addr[12],
peer->addr.sin6.sin6_addr.s6_addr[13],
peer->addr.sin6.sin6_addr.s6_addr[14],
peer->addr.sin6.sin6_addr.s6_addr[15]);
if (peer->addr.sin6.sin6_port != htons(COAP_DEFAULT_PORT)) {
n +=
snprintf(buf + n, BUFSIZE - n, ":%d", peer->addr.sin6.sin6_port);
}
break;
default:
;
}
if (n < BUFSIZE)
buf[n++] = '"';
attr_val.s = (const uint8_t *)buf;
attr_val.length = n;
coap_add_attr(resource,
coap_make_str_const("A"),
&attr_val,
0);
coap_free(buf);
#undef BUFSIZE
}
static rd_t *
make_rd(const coap_pdu_t *pdu) {
rd_t *rd;
const uint8_t *data;
coap_opt_iterator_t opt_iter;
coap_opt_t *etag;
rd = rd_new();
if (!rd) {
coap_log(LOG_DEBUG, "hnd_get_rd: cannot allocate storage for rd\n");
return NULL;
}
if (coap_get_data(pdu, &rd->data.length, &data)) {
rd->data.s = (unsigned char *)coap_malloc(rd->data.length);
if (!rd->data.s) {
coap_log(LOG_DEBUG, "hnd_get_rd: cannot allocate storage for rd->data\n");
rd_delete(rd);
return NULL;
}
memcpy(rd->data.s, data, rd->data.length);
}
etag = coap_check_option(pdu, COAP_OPTION_ETAG, &opt_iter);
if (etag) {
rd->etag_len = min(coap_opt_length(etag), sizeof(rd->etag));
memcpy(rd->etag, coap_opt_value(etag), rd->etag_len);
}
return rd;
}
static void
hnd_post_rd(coap_resource_t *resource COAP_UNUSED,
coap_session_t *session,
const coap_pdu_t *request,
const coap_string_t *query COAP_UNUSED,
coap_pdu_t *response) {
coap_resource_t *r;
#define LOCSIZE 68
unsigned char *loc;
size_t loc_size;
coap_string_t h = {0, NULL}, ins = {0, NULL}, rt = {0, NULL}, lt = {0, NULL}; /* store query parameters */
unsigned char *buf;
coap_str_const_t attr_val;
coap_str_const_t resource_val;
loc = (unsigned char *)coap_malloc(LOCSIZE);
if (!loc) {
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
return;
}
memcpy(loc, RD_ROOT_STR, RD_ROOT_SIZE);
loc_size = RD_ROOT_SIZE;
loc[loc_size++] = '/';
/* store query parameters for later use */
if (query) {
parse_param((const uint8_t *)"h", 1, query->s, query->length, &h);
parse_param((const uint8_t *)"ins", 3, query->s, query->length, &ins);
parse_param((const uint8_t *)"lt", 2, query->s, query->length, &lt);
parse_param((const uint8_t *)"rt", 2, query->s, query->length, &rt);
}
if (h.length) { /* client has specified a node name */
memcpy(loc + loc_size, h.s, min(h.length, LOCSIZE - loc_size - 1));
loc_size += min(h.length, LOCSIZE - loc_size - 1);
if (ins.length && loc_size > 1) {
loc[loc_size++] = '-';
memcpy((char *)(loc + loc_size),
ins.s, min(ins.length, LOCSIZE - loc_size - 1));
loc_size += min(ins.length, LOCSIZE - loc_size - 1);
}
} else { /* generate node identifier */
loc_size +=
snprintf((char *)(loc + loc_size), LOCSIZE - loc_size - 1,
"%x", coap_pdu_get_mid(request));
if (loc_size > 1) {
if (ins.length) {
loc[loc_size++] = '-';
memcpy((char *)(loc + loc_size),
ins.s,
min(ins.length, LOCSIZE - loc_size - 1));
loc_size += min(ins.length, LOCSIZE - loc_size - 1);
} else {
coap_tick_t now;
coap_ticks(&now);
loc_size += snprintf((char *)(loc + loc_size),
LOCSIZE - loc_size - 1,
"-%x",
(unsigned int)(now & (unsigned int)-1));
}
}
}
/* TODO:
* - use lt to check expiration
*/
resource_val.s = loc;
resource_val.length = loc_size;
r = coap_resource_init(&resource_val, 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_resource);
coap_register_request_handler(r, COAP_REQUEST_PUT, hnd_put_resource);
coap_register_request_handler(r, COAP_REQUEST_DELETE, hnd_delete_resource);
if (ins.s) {
buf = (unsigned char *)coap_malloc(ins.length + 2);
if (buf) {
/* add missing quotes */
buf[0] = '"';
memcpy(buf + 1, ins.s, ins.length);
buf[ins.length + 1] = '"';
attr_val.s = buf;
attr_val.length = ins.length + 2;
coap_add_attr(r,
coap_make_str_const("ins"),
&attr_val,
0);
coap_free(buf);
}
}
if (rt.s) {
buf = (unsigned char *)coap_malloc(rt.length + 2);
if (buf) {
/* add missing quotes */
buf[0] = '"';
memcpy(buf + 1, rt.s, rt.length);
buf[rt.length + 1] = '"';
attr_val.s = buf;
attr_val.length = rt.length + 2;
coap_add_attr(r,
coap_make_str_const("rt"),
&attr_val,
0);
coap_free(buf);
}
}
add_source_address(r, coap_session_get_addr_remote(session));
{
rd_t *rd;
rd = make_rd(request);
if (rd) {
coap_resource_set_userdata(r, rd);
} else {
/* FIXME: send error response and delete r */
}
}
coap_add_resource(coap_session_get_context(session), r);
/* create response */
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CREATED);
{ /* split path into segments and add Location-Path options */
unsigned char _b[LOCSIZE];
unsigned char *b = _b;
size_t buflen = sizeof(_b);
int nseg;
nseg = coap_split_path(loc, loc_size, b, &buflen);
while (nseg--) {
coap_add_option(response,
COAP_OPTION_LOCATION_PATH,
coap_opt_length(b),
coap_opt_value(b));
b += coap_opt_size(b);
}
}
coap_free(loc);
}
static void
init_resources(coap_context_t *ctx) {
coap_resource_t *r;
r = coap_resource_init(coap_make_str_const(RD_ROOT_STR), 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_rd);
coap_register_request_handler(r, COAP_REQUEST_POST, hnd_post_rd);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("40"), 0);
coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("\"core.rd\""), 0);
coap_add_attr(r, coap_make_str_const("ins"), coap_make_str_const("\"default\""), 0);
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[72];
const char *lib_build = coap_package_build();
p = strrchr( program, '/' );
if ( p )
program = ++p;
fprintf( stderr, "%s v%s -- CoRE Resource Directory implementation\n"
"(c) 2011-2012,2019-2022 Olaf Bergmann <bergmann@tzi.org> and others\n\n"
"Build: %s\n"
"%s\n"
, program, version, lib_build,
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;
int s;
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 */
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
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, addrs;
coap_endpoint_t *ep_udp = NULL, *ep_dtls = NULL, *ep_tcp = NULL, *ep_tls = NULL;
if (rp->ai_addrlen <= (socklen_t)sizeof(addr.addr)) {
coap_address_init(&addr);
addr.size = (socklen_t)rp->ai_addrlen;
memcpy(&addr.addr, rp->ai_addr, rp->ai_addrlen);
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:
freeaddrinfo(result);
return ctx;
}
int
main(int argc, char **argv) {
coap_context_t *ctx;
int result;
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: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';
break;
case 'v' :
log_level = strtol(optarg, NULL, 10);
break;
default:
usage( argv[0], LIBCOAP_PACKAGE_VERSION );
exit( 1 );
}
}
coap_startup();
coap_dtls_set_log_level(log_level);
coap_set_log_level(log_level);
ctx = get_context(addr_str, port_str);
if (!ctx)
return -1;
if (group)
coap_join_mcast_group_intf(ctx, group, group_if);
init_resources(ctx);
#ifdef _WIN32
signal(SIGINT, handle_sigint);
#else
memset (&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = handle_sigint;
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
#endif
while ( !quit ) {
result = coap_io_process( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
if ( result >= 0 ) {
/* coap_check_resource_list( ctx ); */
}
}
coap_free_context( ctx );
coap_cleanup();
return 0;
}
File diff suppressed because it is too large Load Diff
-67
View File
@@ -1,67 +0,0 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 * -*- */
/* coap_list.c -- CoAP list structures
*
* 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.
*/
/*
* examples/coap_list.[ch] are DEPRECATED. You should be using
* struct coap_optlist_t instead with the following functions which are a part
* of libcoap.
*
* coap_new_optlist()
* coap_insert_optlist()
* coap_delete_optlist()
* coap_add_optlist_pdu()
*
* See 'man coap_pdu_setup' for further information.
*
* examples/coap_list.[ch] files will be removed in a future release
* They are left here to support building backward compatability of old versions
* of coap-client
*/
#include <stdio.h>
#include <string.h>
#include <coap3/coap.h>
int
coap_insert(coap_list_t **head, coap_list_t *node) {
if (!node) {
coap_log(LOG_WARNING, "cannot create option Proxy-Uri\n");
} else {
/* must append at the list end to avoid re-ordering of
* options during sort */
LL_APPEND((*head), node);
}
return node != NULL;
}
int
coap_delete(coap_list_t *node) {
if (node) {
coap_free(node);
}
return 1;
}
void
coap_delete_list(coap_list_t *queue) {
coap_list_t *elt, *tmp;
if (!queue)
return;
LL_FOREACH_SAFE(queue, elt, tmp) {
coap_delete(elt);
}
}
-52
View File
@@ -1,52 +0,0 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 * -*- */
/* coap_list.h -- CoAP list structures
*
* 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.
*/
/*
* examples/coap_list.[ch] are DEPRECATED. You should be using
* struct coap_optlist_t instead with the following functions which are a part
* of libcoap.
*
* coap_new_optlist()
* coap_insert_optlist()
* coap_delete_optlist()
* coap_add_optlist_pdu()
*
* See 'man coap_pdu_setup' for further information.
*
* examples/coap_list.[ch] files will be removed in a future release
* They are left here to support building backward compatibility of old versions
* of coap-client
*/
#ifndef COAP_LIST_H_
#define COAP_LIST_H_
#include <coap3/utlist.h>
typedef struct coap_list_t {
struct coap_list_t *next;
char data[];
} coap_list_t;
/**
* Adds node to given queue, ordered by specified order function. Returns 1
* when insert was successful, 0 otherwise.
*/
int coap_insert(coap_list_t **queue, coap_list_t *node);
/* destroys specified node */
int coap_delete(coap_list_t *node);
/* removes all items from given queue and frees the allocated storage */
void coap_delete_list(coap_list_t *queue);
#endif /* COAP_LIST_H_ */
-7
View File
@@ -1,7 +0,0 @@
contiki-minimal-net.a
contiki-minimal-net.map
contiki/
obj_minimal-net/
server.minimal-net
symbols.c
symbols.h
-15
View File
@@ -1,15 +0,0 @@
CONTIKI=contiki
TARGET?=minimal-net
all: server
$(CONTIKI):
git clone --depth 1 https://github.com/contiki-os/contiki.git $@
cd $(CONTIKI)/apps && ln -s ../../../.. libcoap
server: $(CONTIKI)
$(MAKE) -f Makefile.contiki V=1 CONTIKI=$(CONTIKI) TARGET=$(TARGET) NODE_ADDR=0x1000 server
clean:
$(MAKE) -f Makefile.contiki V=1 CONTIKI=$(CONTIKI) TARGET=$(TARGET) clean
rm -f server.minimal-net symbols.c symbols.h
-33
View File
@@ -1,33 +0,0 @@
########################################################################
# platform-specific options
ifeq ($(TARGET), econotag)
CONTIKI_WITH_RPL=0
CFLAGS += -DUIP_CONF_TCP=0 -DCOAP_MAX_BLOCK_SZX=1
endif
ifeq ($(TARGET), mbxxx)
CFLAGS += -DUIP_CONF_TCP=0 -DCOAP_MAX_BLOCK_SZX=1 -DHAVE_ASSERT_H -DHAVE_LIMITS_H
STM32W_CPUREV=CC
#STM32W_CPUREV=xB
endif
# usually, you should not need changing anything beyond this line
########################################################################
CONTIKI?=../../../..
ifneq ($(NODE_ADDR),)
CFLAGS += -DNODE_ADDR=$(NODE_ADDR)
endif
all: server
CFLAGS += -Os -ffunction-sections
LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__
CFLAGS += #-DSHORT_ERROR_RESPONSE -DNDEBUG
APPS += libcoap
include $(CONTIKI)/Makefile.include
-30
View File
@@ -1,30 +0,0 @@
Example of libcoap running on contiki
=====================================
To run the example, do
$ make
$ sudo ./server.minimal-net
(and in a second terminal)
$ sudo ip -6 a a aaaa::1/64 dev tap0
and query `coap://[aaaa::1000]/time?ticks` with any coap tool,
or query `coap://[aaaa::1000]/.well-known/core`
This will
* download contiki from the upstream git sources
* build the server application
* run the server application, creating a virtual network device tap0 (unless
that exists)
* configure your network interface to make the server accessible.
* return the appropriate response from the server to the client.
The server creates a resource for 'time' with a query 'ticks'. This is
reported for `.well-known/core`. The work flow for adding more resources does
not differ from regular libcoap usage. If you seem to run out of memory
creating the resources, tweak the number of pre-allocated resources
in `coap_config.h.contiki`.
-186
View File
@@ -1,186 +0,0 @@
/* coap-server.c -- Example CoAP server using Contiki and libcoap
*
* Copyright (C) 2011,2015,2018-2019 Olaf Bergmann <bergmann@tzi.org> and others
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#include "coap_config.h"
#include "net/uip-debug.h"
#include <string.h>
#include "coap3/coap.h"
static coap_context_t *coap_context;
/* Where the resource to subscribe is hosted */
static coap_address_t dst;
/* The resource to observe */
static char resource[] = "/s/light";
/* when did the last notify arrive? (0 == never) */
static coap_tick_t last_seen = 0;
PROCESS(coap_server_process, "CoAP server process");
AUTOSTART_PROCESSES(&coap_server_process);
/*---------------------------------------------------------------------------*/
void
init_coap() {
coap_address_t listen_addr;
coap_address_init(&listen_addr);
listen_addr.port = UIP_HTONS(COAP_DEFAULT_PORT);
#ifdef WITH_CONTIKI
/* initialize uIP address for SLAAC */
uip_ip6addr(&listen_addr.addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&listen_addr.addr, &uip_lladdr);
uip_ds6_addr_add(&listen_addr.addr, 0, ADDR_AUTOCONF);
uip_debug_lladdr_print(&uip_lladdr);
printf("\r\n");
uip_debug_ipaddr_print(&listen_addr.addr);
printf("\r\n");
#endif /* WITH_CONTIKI */
#ifdef WITH_CONTIKI
printf("tentative address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
listen_addr.addr.u8[0], listen_addr.addr.u8[1],
listen_addr.addr.u8[2], listen_addr.addr.u8[3],
listen_addr.addr.u8[4], listen_addr.addr.u8[5],
listen_addr.addr.u8[6], listen_addr.addr.u8[7],
listen_addr.addr.u8[8], listen_addr.addr.u8[9],
listen_addr.addr.u8[10], listen_addr.addr.u8[11],
listen_addr.addr.u8[12], listen_addr.addr.u8[13],
listen_addr.addr.u8[14], listen_addr.addr.u8[15] ,
uip_ntohs(listen_addr.port));
#endif
coap_context = coap_new_context(&listen_addr);
coap_set_log_level(LOG_DEBUG);
if (!coap_context)
coap_log(LOG_CRIT, "cannot create CoAP context\r\n");
}
void
message_handler(coap_context_t *ctx,
const coap_address_t *remote,
coap_pdu_t *sent,
coap_pdu_t *received,
const coap_tid_t id) {
/* send ACK if received message is confirmable (i.e. a separate response) */
coap_send_ack(ctx, remote, received);
coap_log(LOG_DEBUG, "** process incoming %d.%02d response:\n",
(received->hdr->code >> 5), received->hdr->code & 0x1F);
coap_show_pdu(LOG_WARNING, received);
coap_ticks(&last_seen);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_server_process, ev, data)
{
coap_pdu_t *request;
coap_uri_t uri;
PROCESS_BEGIN();
init_coap();
if (!coap_context) {
coap_log(LOG_EMERG, "cannot create context\n");
PROCESS_EXIT();
}
coap_register_response_handler(coap_context, message_handler);
/* setup subscription request */
coap_address_init(&dst);
dst.port = uip_htons(COAP_DEFAULT_PORT);
uip_ip6addr(&dst.addr, 0xaaaa, 0, 0, 0, 0x206, 0x98ff, 0xfe00, 0x232);
/* uip_ip6addr(&dst.addr, 0xfe80, 0, 0, 0, 0x206, 0x98ff, 0xfe00, 0x232); */
request = coap_pdu_init(COAP_MESSAGE_CON, COAP_REQUEST_GET,
coap_new_message_id(coap_context),
COAP_DEFAULT_MTU);
coap_split_uri((unsigned char *)resource, strlen(resource), &uri);
if (uri.port != COAP_DEFAULT_PORT) {
unsigned char portbuf[2];
coap_add_option(request, COAP_OPTION_URI_PORT,
coap_encode_var_safe(portbuf, sizeof(portbuf),
uri.port),
portbuf);
}
if (uri.path.length) {
#define BUFSIZE 20
unsigned char _buf[BUFSIZE];
unsigned char *buf = _buf;
size_t buflen;
int res;
buflen = BUFSIZE;
#undef BUFSIZE
res = coap_split_path(uri.path.s, uri.path.length, buf, &buflen);
while (res--) {
coap_add_option(request, COAP_OPTION_URI_PATH,
coap_opt_length(buf), coap_opt_value(buf));
buf += coap_opt_size(buf);
}
}
coap_add_option(request, COAP_OPTION_OBSERVE, 0, NULL);
{
unsigned char buf[2];
coap_prng(buf, 2);
coap_add_option(request, COAP_OPTION_TOKEN, 2, buf);
}
if (COAP_INVALID_TID == coap_send_confirmed(coap_context, &dst, request))
coap_delete_pdu(request);
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
coap_io_do_io(coap_context); /* read received data */
coap_dispatch(coap_context); /* and dispatch PDUs from receivequeue */
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
-1
View File
@@ -1 +0,0 @@
../../coap_config.h.contiki
-14
View File
@@ -1,14 +0,0 @@
interface tap0
{
AdvSendAdvert on;
MinRtrAdvInterval 3;
MaxRtrAdvInterval 20;
prefix aaaa::/64
{
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
};
};
-222
View File
@@ -1,222 +0,0 @@
/* coap-server.c -- Example CoAP server using Contiki and libcoap
*
* Copyright (C) 2011 Olaf Bergmann <bergmann@tzi.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#include "coap_config.h"
#define DEBUG DEBUG_PRINT
#include "net/ip/uip-debug.h"
#include "net/net-debug.h"
#include <string.h>
#include "coap3/coap.h"
static coap_context_t *coap_context;
static clock_time_t clock_offset;
/* changeable clock base (see handle_put_time()) */
static clock_time_t my_clock_base = 0;
static coap_resource_t *time_resource = NULL; /* just for testing */
PROCESS(coap_server_process, "CoAP server process");
AUTOSTART_PROCESSES(&coap_server_process);
/*---------------------------------------------------------------------------*/
void
init_coap_server(coap_context_t **ctx) {
coap_address_t listen_addr;
uip_ipaddr_t gw_addr;
assert(ctx);
coap_set_log_level(LOG_DEBUG);
coap_address_init(&listen_addr);
listen_addr.port = UIP_HTONS(COAP_DEFAULT_PORT);
uip_ip6addr(&listen_addr.addr, 0xaaaa, 0, 0, 0, 0, 0, 0, NODE_ADDR);
#ifndef CONTIKI_TARGET_MINIMAL_NET
uip_ds6_prefix_add(&listen_addr.addr, 64, 0, 0, 0, 0);
#endif /* not CONTIKI_TARGET_MINIMAL_NET */
uip_ds6_addr_add(&listen_addr.addr, 0, ADDR_MANUAL);
/* set default route to gateway aaaa::1 */
uip_ip6addr(&gw_addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0x0001);
uip_ds6_defrt_add(&gw_addr, 0);
PRINTLLADDR(&uip_lladdr);
printf("\r\n");
PRINT6ADDR(&listen_addr.addr);
printf("\r\n");
*ctx = coap_new_context(&listen_addr);
if (!*ctx) {
coap_log(LOG_CRIT, "cannot create CoAP context\r\n");
}
}
/*---------------------------------------------------------------------------*/
#ifndef min
# define min(a,b) ((a) < (b) ? (a) : (b))
#endif
void
hnd_get_time(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query,
coap_pdu_t *response) {
unsigned char buf[40];
size_t len;
coap_tick_t now;
coap_tick_t t;
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);
} 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);
}
}
void
init_coap_resources(coap_context_t *ctx) {
coap_resource_t *r;
#if 0
r = coap_resource_init(NULL, 0, 0);
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_index);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_attr(r, coap_make_str_const("title"), coap_make_str_const("\"General Info\""), 0);
coap_add_resource(ctx, r);
#endif
/* store clock base to use in /time */
my_clock_base = clock_offset;
r = coap_resource_init(coap_make_str_const("time"), 0);
if (!r)
goto error;
coap_resource_set_get_observable(r, 1);
time_resource = r;
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_time);
#if 0
coap_register_handler(r, COAP_REQUEST_PUT, hnd_put_time);
coap_register_handler(r, COAP_REQUEST_DELETE, hnd_delete_time);
#endif
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
/* coap_add_attr(r, coap_make_str_const("title"), coap_make_str_const("\"Internal Clock\""), 0); */
coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("\"ticks\""), 0);
coap_add_attr(r, coap_make_str_const("if"), coap_make_str_const("\"clock\""), 0);
coap_add_resource(ctx, r);
#if 0
#ifndef WITHOUT_ASYNC
r = coap_resource_init(coap_make_str_const("async"), 0);
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_async);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_resource(ctx, r);
#endif /* WITHOUT_ASYNC */
#endif
return;
error:
coap_log(LOG_CRIT, "cannot create resource\n");
}
/* struct etimer notify_timer; */
struct etimer dirty_timer;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_server_process, ev, data)
{
PROCESS_BEGIN();
clock_offset = clock_time();
init_coap_server(&coap_context);
if (!coap_context) {
coap_log(LOG_EMERG, "cannot create context\n");
PROCESS_EXIT();
}
init_coap_resources(coap_context);
if (!coap_context) {
coap_log(LOG_EMERG, "cannot create context\n");
PROCESS_EXIT();
}
/* etimer_set(&notify_timer, 5 * CLOCK_SECOND); */
etimer_set(&dirty_timer, 30 * CLOCK_SECOND);
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
/* There is something to read on the endpoint */
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);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
-210
View File
@@ -1,210 +0,0 @@
#!/bin/bash
# test coap implementation for the ETSI CoAP Plugtest in March 2012
# with test cases described in Plugtests Guide First Draft V0.0.16
COAP_CLIENT=./coap-client
tcpdump=/usr/sbin/tcpdump
DEFAULTPORT=5683
CLIENTPORT=61701
# directory for logging
LOGDIR=logs
# set client's verbose level
callopts=" -v 5"
longtimeout=180
clienttimeout=$longtimeout
timeoutcmd=/usr/bin/timeout
#URIREGEX=.*\/.*
# resembles approximately an ip address
IPADDRREGEX="^[1-2]?[0-9]{1,2}\.[1-2]?[0-9]{1,2}\.[1-2]?[0-9]{1,2}\.[1-2]?[0-9]{1,2}"
# FIXME IPV6 address
IP6REGEX=".*:.*:.*"
# Testcase groups
CORE=( TD_COAP_CORE_01 TD_COAP_CORE_02 TD_COAP_CORE_03
TD_COAP_CORE_04 TD_COAP_CORE_05 TD_COAP_CORE_06 TD_COAP_CORE_07
TD_COAP_CORE_08 TD_COAP_CORE_09 TD_COAP_CORE_10 TD_COAP_CORE_11
TD_COAP_CORE_12 TD_COAP_CORE_13 TD_COAP_CORE_14 TD_COAP_CORE_15 )
LINK=( TD_COAP_LINK_01 TD_COAP_LINK_02 )
BLOCK=( TD_COAP_BLOCK_01 TD_COAP_BLOCK_02 TD_COAP_BLOCK_03 TD_COAP_BLOCK_04 )
OBS=( TD_COAP_OBS_01 TD_COAP_OBS_02 TD_COAP_OBS_03 TD_COAP_OBS_04 TD_COAP_OBS_05 )
testgroups=( CORE LINK BLOCK OBS )
# if no test cases are specified, we want to run all tests
testnumber=-1
group=''
source `dirname $0`/etsi_testcases.sh
function usage {
echo "Usage: `basename $0` [-n testnumber] [-g groupname] [-t timeout] [-P server_port] [-p client port] [-d logdir] [-v] -i interface server_address" 1>&2
echo "-n test case to be accomplished" 1>&2
echo "-g group to be tested" 1>&2
echo "-t time in seconds until timout for single test" 1>&2
echo "-i interface to use for tcpdump" 1>&2
echo "-P port of server" 1>&2
echo "-p port client listens on" 1>&2
echo "-d directory for logfiles" 1>&2
echo "-v verbose level" 1>&2
}
function run_test {
tn=$1
clientopts=''
if [ -z $1 ]; then
echo "missing argument for run_test"
exit 1
fi
echo -e "running test: $tn"
if [ $(type -t $tn) ] ; then
$tn $tn
echo
else
echo "not implemented"
echo
fi
}
while getopts "n:g:t:i:P:p:d:v" OPTION;
do
# A missing argument for an option leads getopts to take the next
# option as the parameter. We want to prevent that.
case $OPTARG in
-*) echo "Missing argument for option \"-$OPTION\"."
echo $USAGE
exit 1
;;
esac
case $OPTION in
n) # number of test case
testnumber=$((OPTARG-1))
;;
g) # name of test group
# is there a group with that name?
for i in "${testgroups[@]}"
do
# group doesn't have to be case sensitive
tmpgroup=$(echo $OPTARG | tr '[:lower:]' '[:upper:]')
if [ $i == $tmpgroup ] ; then
group=$tmpgroup
break
fi
done
if [ -z $group ] ; then
echo "No such group:" $OPTARG". Available groups are: ${testgroups[@]}"
exit 1
fi
;;
t)
# add timeout to client parameters
clienttimeout=$((OPTARG))
callopts="$callopts -B $clienttimeout"
;;
i)
# interface tcpdump listens on
INTERFACE=$OPTARG
;;
P)
# port the server listens on
SERVERPORT=$((OPTARG))
;;
p)
# port the client listens on
CLIENTPORT=$((OPTARG))
;;
d)
# directory tcpdump writes the logfiles into
LOGDIR=$OPTARG
;;
v)
verbose=1
;;
?)
# any other option is invalid
echo -e $USAGE 1>&2
exit 1
;;
esac
done
# catch last argument: server address
ARGS=$(($#+1))
SERVERADDRESS=${@: -1}
if [[ ! $((ARGS-OPTIND)) -eq 1 ]]; then
echo -e "\nno server address specified"
usage
exit 1
fi
# if no port number was specified by user, the server address for the
# coap-client is $SERVERADDRESS
if [ -z $SERVERPORT ]; then
SERVERPORT=$DEFAULTPORT
if [[ $SERVERADDRESS =~ $IP6REGEX ]]; then
SERVERTUP=\[$SERVERADDRESS\]
else
SERVERTUP=$SERVERADDRESS
fi
else
if [[ $SERVERADDRESS =~ $IP6REGEX ]]; then
SERVERTUP=\[$SERVERADDRESS\]:$SERVERPORT
else
SERVERTUP=$SERVERADDRESS:$SERVERPORT
fi
fi
# create directory for logging, if it's not already there
if [[ ! -e $LOGDIR ]]; then
mkdir -p $LOGDIR
if [ $? ]; then
echo created directory \""$LOGDIR"\" for logging
fi
fi
# the interface for tcpdump is mandatory
if [ -z $INTERFACE ]; then
echo -e "\nno interface given"
exit 1
fi
# determine which tests to run
if [ -n "$group" ] ; then
echo group: $group
if [[ ! $testnumber -eq -1 ]] ; then
groupsize=$(eval "echo \${#$(echo $group)[@]}")
# is there a testcase with number $testnumber in group $group
if [ $testnumber -ge $groupsize -o $testnumber -lt 0 ] ; then
echo "No such testcase number: $OPTARG. Test cases numbers are 1 to" $groupsize
exit 1
else
# run test with group $group and number $testnumber
run_test $(eval "echo \${$(echo $group)[$testnumber]}")
fi
else
# if no testnumber was specified, we want to run all tests in that group
for i in $(eval "echo \${$(echo $group)[@]}") ; do
run_test $i
done
fi
else
# run all tests of all groups
for j in ${testgroups[@]} ; do
echo "group: $j"
for k in $(eval "echo \${$(echo $j)[@]}") ; do
run_test $k
done
done
fi
-633
View File
@@ -1,633 +0,0 @@
/* CoAP server for first ETSI CoAP plugtest, March 2012
*
* 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.
*/
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <signal.h>
#include <coap3/coap.h>
#define COAP_RESOURCE_CHECK_TIME_SEC 1
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
/* temporary storage for dynamic resource representations */
static int quit = 0;
#define COAP_OPT_BLOCK_SZX_MAX 6 /**< allowed maximum for block szx value */
#define REQUIRE_ETAG 0x01 /* flag for coap_payload_t: require ETag option */
typedef struct {
unsigned int flags; /* some flags to control behavior */
size_t max_data; /* maximum size allocated for @p data */
uint16_t media_type; /* media type for this object */
size_t length; /* length of data */
unsigned char data[]; /* the actual contents */
} coap_payload_t;
/* SIGINT handler: set quit to 1 for graceful termination */
static void
handle_sigint(int signum COAP_UNUSED) {
quit = 1;
}
#define INDEX "libcoap server for ETSI CoAP Plugtest, March 2012, Paris\n" \
"Copyright (C) 2012 Olaf Bergmann <bergmann@tzi.org>\n\n"
static coap_payload_t *
coap_new_payload(size_t size) {
coap_payload_t *p;
p = (coap_payload_t *)coap_malloc(sizeof(coap_payload_t) + size);
if (p) {
memset(p, 0, sizeof(coap_payload_t));
p->max_data = size;
}
return p;
}
static inline coap_payload_t *
coap_find_payload(coap_resource_t *resource) {
return coap_resource_get_userdata(resource);
}
static void
coap_add_payload(coap_resource_t *resource, coap_payload_t *payload){
assert(payload);
coap_resource_set_userdata(resource, payload);
}
static inline void
coap_delete_payload(coap_resource_t *resource) {
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_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];
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_add_option(response, COAP_OPTION_MAXAGE,
coap_encode_var_safe(buf, sizeof(buf), 0x2ffff), buf);
coap_add_data(response, strlen(INDEX), (const uint8_t *)INDEX);
}
#endif
static void
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) {
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
return;
}
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
coap_add_data_blocked_response(request, response,
test_payload->media_type, -1,
test_payload->length,
test_payload->data);
return;
}
/* DELETE handler for dynamic resources created by POST /test */
static void
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;
payload = coap_find_payload(resource);
if (payload)
coap_delete_payload(resource);
coap_delete_resource(NULL, resource);
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
}
static void
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;
const uint8_t *data;
#define BUFSIZE 20
int res;
unsigned char _buf[BUFSIZE];
unsigned char *buf = _buf;
size_t buflen = BUFSIZE;
coap_get_data(request, &len, &data);
/* allocate storage for resource and to hold URI */
test_payload = coap_new_payload(len);
snprintf((char *)buf, buflen, "test/%p", (void *)test_payload);
uri = coap_new_str_const(buf, strlen((char *)buf));
if (!(test_payload && uri)) {
coap_log(LOG_CRIT, "cannot allocate new resource under /test");
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
coap_free(test_payload);
coap_free(uri);
} else {
coap_resource_t *r;
test_payload->length = len;
memcpy(test_payload->data, data, len);
r = coap_resource_init(uri, COAP_RESOURCE_FLAGS_RELEASE_URI);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_resource);
coap_register_request_handler(r, COAP_REQUEST_DELETE, hnd_delete_resource);
/* set media_type if available */
option = coap_check_option(request, COAP_OPTION_CONTENT_TYPE, &opt_iter);
if (option) {
test_payload->media_type =
coap_decode_var_bytes(coap_opt_value(option), coap_opt_length(option));
}
coap_add_resource(coap_session_get_context(session), r);
coap_add_payload(r, test_payload);
/* add Location-Path */
res = coap_split_path(uri->s, uri->length, buf, &buflen);
while (res--) {
coap_add_option(response, COAP_OPTION_LOCATION_PATH,
coap_opt_length(buf), coap_opt_value(buf));
buf += coap_opt_size(buf);
}
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CREATED);
}
}
static void
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;
const uint8_t *data;
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CHANGED);
coap_get_data(request, &len, &data);
payload = coap_find_payload(resource);
if (payload && payload->max_data < len) { /* need more storage */
coap_delete_payload(resource);
payload = NULL;
/* bug: when subsequent coap_new_payload() fails, our old contents
is gone */
}
if (!payload) { /* create new payload */
payload = coap_new_payload(len);
if (!payload)
goto error;
coap_add_payload(resource, payload);
}
payload->length = len;
memcpy(payload->data, data, len);
option = coap_check_option(request, COAP_OPTION_CONTENT_TYPE, &opt_iter);
if (option) {
/* set media type given in request */
payload->media_type =
coap_decode_var_bytes(coap_opt_value(option), coap_opt_length(option));
} else {
/* set default value */
payload->media_type = COAP_MEDIATYPE_TEXT_PLAIN;
}
/* FIXME: need to change attribute ct of resource.
To do so, we need dynamic management of the attribute value
*/
return;
error:
coap_log(LOG_WARNING, "cannot modify resource\n");
coap_pdu_set_code(response, COAP_RESPONSE_CODE_INTERNAL_ERROR);
}
static void
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
coap_payload_t *payload;
payload = coap_find_payload(resource);
if (payload)
payload->length = 0;
#endif
coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);
}
static void
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;
coap_opt_t *q;
size_t len, L;
unsigned char buf[70];
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_filter_set(&f, COAP_OPTION_URI_QUERY);
coap_option_iterator_init(request, &opt_iter, &f);
len = 0;
while ((len < sizeof(buf)) && (q = coap_option_next(&opt_iter))) {
L = min(sizeof(buf) - len, 11);
memcpy(buf + len, "Uri-Query: ", L);
len += L;
L = min(sizeof(buf) - len, coap_opt_length(q));
memcpy(buf + len, coap_opt_value(q), L);
len += L;
if (len < sizeof(buf))
buf[len++] = '\n';
}
coap_add_data(response, len, buf);
}
/* handler for TD_COAP_CORE_16 */
static void
hnd_get_separate(coap_resource_t *resource COAP_UNUSED,
coap_session_t *session,
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 (request) {
coap_async_t *async;
coap_bin_const_t token = coap_pdu_get_token(request);
async = coap_find_async(session, token);
if (!async) {
/* Set up an async request to trigger delay in the future */
/* search for option delay in query list */
coap_option_filter_clear(&f);
coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
coap_option_iterator_init(request, &opt_iter, &f);
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;
}
}
/* 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);
/* async is automatically removed by libcoap */
}
static coap_payload_t *
make_large(const char *filename) {
coap_payload_t *payload;
FILE *inputfile = NULL;
struct stat statbuf;
if (!filename)
return NULL;
/* read from specified input file */
if (stat(filename, &statbuf) < 0) {
coap_log(LOG_WARNING, "cannot stat file %s\n", filename);
return NULL;
}
payload = coap_new_payload(statbuf.st_size);
if (!payload)
return NULL;
inputfile = fopen(filename, "r");
if ( !inputfile ) {
coap_log(LOG_WARNING, "cannot read file %s\n", filename);
coap_free(payload);
return NULL;
}
payload->length = fread(payload->data, 1, statbuf.st_size, inputfile);
payload->media_type = 41;
fclose(inputfile);
return payload;
}
static void
init_resources(coap_context_t *ctx) {
coap_resource_t *r;
coap_payload_t *test_payload;
test_payload = coap_new_payload(200);
if (!test_payload)
coap_log(LOG_CRIT, "cannot allocate resource /test");
else {
test_payload->length = 13;
memcpy(test_payload->data, "put data here", test_payload->length);
/* test_payload->media_type is 0 anyway */
r = coap_resource_init(coap_make_str_const("test"), 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_resource);
coap_register_request_handler(r, COAP_REQUEST_POST, hnd_post_test);
coap_register_request_handler(r, COAP_REQUEST_PUT, hnd_put_test);
coap_register_request_handler(r, COAP_REQUEST_DELETE, hnd_delete_test);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("test"), 0);
coap_add_attr(r, coap_make_str_const("if"), coap_make_str_const("core#b"), 0);
#if 0
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);
}
/* TD_COAP_BLOCK_01
* TD_COAP_BLOCK_02 */
test_payload = make_large("etsi_iot_01_largedata.txt");
if (!test_payload)
coap_log(LOG_CRIT, "cannot allocate resource /large\n");
else {
r = coap_resource_init(coap_make_str_const("large"), 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_resource);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("41"), 0);
coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("large"), 0);
coap_add_resource(ctx, r);
test_payload->flags |= REQUIRE_ETAG;
coap_add_payload(r, test_payload);
}
/* For TD_COAP_CORE_12 */
test_payload = coap_new_payload(20);
if (!test_payload)
coap_log(LOG_CRIT, "cannot allocate resource /seg1/seg2/seg3\n");
else {
test_payload->length = 10;
memcpy(test_payload->data, "segsegseg!", test_payload->length);
/* test_payload->media_type is 0 anyway */
r = coap_resource_init(coap_make_str_const("seg1/seg2/seg3"), 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_resource);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_resource(ctx, r);
coap_add_payload(r, test_payload);
}
/* For TD_COAP_CORE_13 */
r = coap_resource_init(coap_make_str_const("query"), 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_query);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_resource(ctx, r);
/* For TD_COAP_CORE_16 */
r = coap_resource_init(coap_make_str_const("separate"), 0);
coap_register_request_handler(r, COAP_REQUEST_GET, hnd_get_separate);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("seperate"), 0);
coap_add_resource(ctx, r);
}
static void
usage( const char *program, const char *version) {
const char *p;
p = strrchr( program, '/' );
if ( p )
program = ++p;
fprintf( stderr, "%s v%s -- ETSI CoAP plugtest server\n"
"(c) 2012 Olaf Bergmann <bergmann@tzi.org>\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, program );
}
static coap_context_t *
get_context(const char *node, const char *port) {
coap_context_t *ctx = NULL;
int s;
struct addrinfo hints;
struct addrinfo *result, *rp;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Coap uses UDP */
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
s = getaddrinfo(node, port, &hints, &result);
if ( s != 0 ) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
return NULL;
}
/* iterate through results until success */
for (rp = result; rp != NULL; rp = rp->ai_next) {
coap_address_t 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);
ctx = coap_new_context(&addr);
if (ctx) {
/* TODO: output address:port for successful binding */
goto finish;
}
}
}
fprintf(stderr, "no context available for interface '%s'\n", node);
finish:
freeaddrinfo(result);
return ctx;
}
int
main(int argc, char **argv) {
coap_context_t *ctx;
int result;
char addr_str[NI_MAXHOST] = "::";
char port_str[NI_MAXSERV] = "5683";
int opt;
coap_log_t log_level = LOG_WARNING;
struct sigaction sa;
while ((opt = getopt(argc, argv, "A:p:v:")) != -1) {
switch (opt) {
case 'A' :
strncpy(addr_str, optarg, NI_MAXHOST-1);
addr_str[NI_MAXHOST - 1] = '\0';
break;
case 'p' :
strncpy(port_str, optarg, NI_MAXSERV-1);
port_str[NI_MAXSERV - 1] = '\0';
break;
case 'v' :
log_level = strtol(optarg, NULL, 10);
break;
default:
usage( argv[0], LIBCOAP_PACKAGE_VERSION );
exit( 1 );
}
}
coap_set_log_level(log_level);
ctx = get_context(addr_str, port_str);
if (!ctx)
return -1;
init_resources(ctx);
memset (&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = handle_sigint;
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
while ( !quit ) {
result = coap_io_process( ctx, COAP_RESOURCE_CHECK_TIME * 1000 );
if ( result >= 0 ) {
/* coap_check_resource_list( ctx ); */
}
}
coap_free_context( ctx );
coap_cleanup();
return 0;
}
-7
View File
@@ -1,7 +0,0 @@
<large>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet sapien ac leo bibendum suscipit at sed ipsum. Aliquam in mauris nec felis dictum lobortis a et erat. Pellentesque tempus urna vulputate purus faucibus ac pretium massa volutpat. Maecenas at tellus neque, quis elementum ante. Morbi molestie, elit placerat rhoncus faucibus, urna nunc accumsan diam, vel porta eros sem vel augue. Proin metus dolor, tristique a accumsan eget, suscipit vel ante. Suspendisse feugiat, nisl non viverra convallis, ante nibh congue lectus, sodales ultrices turpis massa sed elit.
Praesent posuere laoreet nulla eu accumsan. Vestibulum consequat molestie erat, ut laoreet arcu mattis non. Maecenas viverra elementum mauris, vitae pretium elit ultrices sit amet. Sed sit amet elit sit amet dui imperdiet consequat. Donec viverra leo mollis lorem varius lacinia mollis nulla posuere. Phasellus felis odio, tempor et sodales non, facilisis fermentum eros. Duis dignissim massa at ante euismod vel laoreet mi tristique. Nulla libero dolor, pretium vitae vulputate eget, luctus at sapien. Praesent aliquam nisl ut urna pretium eu rhoncus ipsum eleifend. Sed lobortis vestibulum est eu eleifend. Sed vitae luctus erat. Sed vel dolor quam, tempor venenatis dolor.
Vivamus a est a neque condimentum fermentum sed quis dui. Maecenas rhoncus imperdiet tortor, vitae viverra lectus ornare vulputate. Nam congue pulvinar faucibus. Vivamus id mauris at tortor porta volutpat. Donec non velit a tellus placerat iaculis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse at felis ligula, vel euismod velit. Aliquam in odio urna.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ac risus ipsum. Donec vel purus risus, eu molestie nisi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse consequat libero eu augue ornare volutpat mollis sed dui. Ut sed. </large>
-765
View File
@@ -1,765 +0,0 @@
#!/bin/bash
function start_tcpdump {
testfunc=$1
logfile=$LOGDIR/"$testfunc"_$(date +%s).dump
tcpdumpcmd="$tcpdump -i $INTERFACE host $SERVERADDRESS and (udp port $SERVERPORT or icmp) -s0 -n -w $logfile"
if [ $verbose ]; then
echo "$tcpdumpcmd"
$tcpdumpcmd&
else
$tcpdumpcmd 2>/dev/null&
fi
tcpdumppid=$!
# wait until tcpdump is ready to write
for t in {0..20} ; do
if [ ! -e $logfile ] ; then
sleep 0.1
else
sleep 1
if [ $verbose ]; then
echo "tcpdump started"
fi
break
fi
done
}
function kill_tcpdump {
kill $tcpdumppid 2>/dev/null || ERROR=1
if [ $ERROR ]; then
echo "tcpdump failed."
exit 1
fi
}
function start_coap_test {
if [ -z $1 ]; then
echo "missing argument for start_coap_test"
exit 1
fi
start_tcpdump $1
if [ $verbose ]; then
echo "client command: $COAP_CLIENT $clientopts $testaddress"
fi
echo -e "\nOutput of client:"
# for OBS
if [[ ! -z $2 ]]; then
testfifo=/tmp/tmpfifo$(date +%s)
mkfifo $testfifo
$COAP_CLIENT $clientopts "$testaddress" &> $testfifo &
clientpid=$!
($timeoutcmd $clienttimeout cat $testfifo | if read -n 1 char; then echo "output: $char" ; fi) 2>/dev/null
# when client has written an output to fifo, kill client
kill $clientpid
rm $testfifo
if [[ $2 == "wait" ]] ; then
echo "Client killed. Waiting.."
sleep $longtimeout
fi
else
$COAP_CLIENT $clientopts "$testaddress"
fi
kill_tcpdump
}
##
# Perform GET (CON mode) on resource /test
#
# pre: resource /test exists and can handle GET with arbitrary payload
#
# client sends GET request with Type=0(CON) and Code=1(GET)
#
# check if sent request contains Type value indicating 0 and Code
# value indicating 1
#
# check if server sends response containing Code = 69(2.05 Content),
# the same Message ID as that of previous request, content type option
#
# verify that server displays received information
#
function TD_COAP_CORE_01 {
clientopts="$callopts -m get"
testaddress=coap://$SERVERTUP/test
echo "perform GET (CON mode) on resource $testaddress"
start_coap_test $1
}
##
# Perform POST transaction (CON mode) on resource /test: create
# resource /test
#
# pre: resource /test doesn't exist but can be created on /test
#
# client sends POST with Type=0(CON), Code=2(POST), arbitrary payload,
# Content type option
#
# check: client sends request containing Type value indicating 0 and
# Code value indicating 2
#
# verify: Server displays received information
#
# check: server sends response containing Code=69(2.01 Created), same
# message ID as that of the previous request, Content type option
#
# verify: client displays received information
#
function TD_COAP_CORE_02 {
# -t 0: content type text/plain
clientopts="$callopts -m post -t 0 -e sometext"
testaddress=coap://$SERVERTUP/test
echo "perform POST (CON) on resource $testaddress"
start_coap_test $1
}
##
# Perform PUT transaction (CON mode) on resource /test
#
# pre: resource /test exists which can handle PUT
#
# Client sends a PUT request with Type=0(CON), Code=3(PUT), arbitrary
# payload, content type option
#
# check: sent request contains Type value indicating 0 and Code value
# indicating 3
#
# verify: server displays received information
#
# check: Server sends response containing Code=68(2.04 Changed), same
# Message ID as that of the previous request
#
# verify: client displays received response
#
function TD_COAP_CORE_03 {
clientopts="$callopts -m put -t 0 -e sometext"
testaddress=coap://$SERVERTUP/test
echo "perform PUT (CON) on resource $testaddress"
start_coap_test $1
}
##
# Perform DELETE transaction (CON mode) on resource /test
#
# pre: resource /test exists which can handle DELETE
#
# Client sends a DELETE request with Type=0(CON), Code=4(DELETE)
#
# check: sent request contains Type value indicating 0 and Code value
# indicating 4
#
# check: Server sends response containing Code=66(2.02 Deleted), same
# Message ID as that of the previous request
#
# verify: client displays received response
#
function TD_COAP_CORE_04 {
clientopts="$callopts -m delete"
testaddress=coap://$SERVERTUP/test
echo "perform DELETE (CON) on resource $testaddress"
start_coap_test $1
}
##
# Perform GET transaction (NON mode) on resource /test
#
# pre: resource /test exits which can handle GET
#
# Client sends a GET request with Type=1(NON), Code=1(GET)
#
# check: sent request contains Type value indicating 1 and Code value
# indicating 1
#
# check: Server sends response containing Type=1(NON), Code=69(2.05
# Content), content type option
#
# verify: client displays received response
#
function TD_COAP_CORE_05 {
# -N: send non-confirmable message
clientopts="$callopts -m get -N"
testaddress=coap://$SERVERTUP/test
echo "perform GET (NON mode) on resource $testaddress"
start_coap_test $1
}
##
# Perform POST transaction (NON mode), create resource on /test
#
# pre: resource on /test doesn't exist but can be created
#
# Client sends a POST request with Type=1(NON), Code=2(POST),
# arbitrary payload, content type option
#
# check: sent request contains Type value indicating 1 and Code value
# indicating 2
#
# verify: Server displays the received information
#
# check: Server sends response containing Type=1(NON), Code=65(2.01
# Created)
#
# verify: client displays received response
#
function TD_COAP_CORE_06 {
clientopts="$callopts -m post -t 0 -e sometext -N"
testaddress=coap://$SERVERTUP/test
echo "perform POST (NON) on resource $testaddress"
start_coap_test $1
}
##
# Perform PUT transaction (NON mode) on resource /test
#
# pre: /test exists and can handle PUT
#
# Client sends a PUT request with Type=1(NON), Code=3(PUT),
# arbitrary payload, content type option
#
# check: sent request contains Type value indicating 1 and Code value
# indicating 3
#
# verify: Server displays the received information
#
# check: Server sends response containing Type=1(NON), Code=68(2.04
# Changed)
#
# verify: client displays received response
#
function TD_COAP_CORE_07 {
clientopts="$callopts -m put -t 0 -e sometext -N"
testaddress=coap://$SERVERTUP/test
echo "perform PUT (NON) on resource $testaddress"
start_coap_test $1
}
##
# Perform DELETE transaction (NON mode) on resource /test
#
# pre: /test exists and can handle DELETE
#
# Client sends a DELETE request with Type=1(NON), Code=4(DELETE)
#
# check: sent request contains Type value indicating 1 and Code value
# indicating 4
#
# check: Server sends response containing Type=1(NON), Code=66(2.02
# Deleted)
#
# verify: client displays received response
#
function TD_COAP_CORE_08 {
clientopts="$callopts -m delete -N"
testaddress=coap://$SERVERTUP/test
echo "perform DELETE (NON) on resource $testaddress"
start_coap_test $1
}
##
# Perform GET transaction with a separate response on resource /separate
#
# pre: resource /separate exists which cannot be served immediately and which
# cannot be acknowledged in a piggy-backed way
#
# Client sends a confirmable GET request to server's resource
#
# check: sent request contains Type=0(CON), Code=1(GET), client
# generated Message ID
#
# check: Server sends response containing Type=2(ACK), message ID same
# as the request, empty Payload
#
# check: Server sends response containing Type=0(CON), Code=69(2.05
# content), Payload=Content of the requested resource, Content type option
#
# check: Client sends response containing Type=2(ACK), message ID same
# as the response, empty Payload
#
# verify: client displays received response
#
function TD_COAP_CORE_09 {
clientopts="$callopts -m get"
testaddress=coap://$SERVERTUP/separate
echo "perform GET (CON) on resource $testaddress which cannot be served immediately"
start_coap_test $1
}
##
# Perform GET transaction with Token on resource /test
#
# pre: resource /test exists which can handle GET requests
#
# Client sends a confirmable GET request to server's resource
# including Token option
#
# check: sent request contains Type=0(CON) and Code=1(GET), client
# generated Token value, length of the token which should be between 1
# to 8 B, Option Type=Token
#
# check: Server sends response containing Code=69(2.05 content),
# length of the token should be between 1 to 8 B, Token value same as
# the requested, Payload=Content of the requested resource, Content
# type option
#
# verify: client displays received response
#
function TD_COAP_CORE_10 {
clientopts="$callopts -m get -T sometok"
testaddress=coap://$SERVERTUP/test
echo "perform GET (CON) on resource $testaddress with Token"
start_coap_test $1
}
##
# Perform GET transaction without Token on resource /test
#
# pre: resource /test exists which can handle GET requests
#
# Client sends a confirmable GET request to server's resource
# not containing Token option
#
# check: sent request contains Type=0(CON) and Code=1(GET), no Token
# option
#
# check: Server sends response containing Code=69(2.05 content), no
# Token option, Payload=Content of the requested resource, Content
# type option
#
# verify: client displays received response
#
function TD_COAP_CORE_11 {
clientopts="$callopts -m get"
testaddress=coap://$SERVERTUP/test
echo "perform GET (CON mode) without Token on resource $testaddress"
start_coap_test $1
}
##
# Perform GET transaction to resource /seg1/seg2/seg3
#
# pre: resource /seg1/seg2/seg3 exists on server
#
# Client sends a confirmable GET request to server's resource
#
# check: sent request contains Type=0(CON) and Code=1(GET), Option
# type=URI-Path (one for each path segment)
#
# check: Server sends response containing Code=69(2.05 content),
# Payload=Content of the requested resource, Content type option
#
# verify: client displays received response
#
function TD_COAP_CORE_12 {
clientopts="$callopts -m get"
testaddress=coap://$SERVERTUP/seg1/seg2/seg3
echo "perform GET (CON mode) on resource $testaddress"
start_coap_test $1
}
##
# Perform GET transaction to resource /query
#
# pre: resource /query exists on server
#
# Client sends a confirmable GET request with three Query parameters
# (e.g. ?first=1&second=2&third=3) to server's resource
#
# check: sent request contains Type=0(CON) and Code=1(GET), Option
# type=URI-Query (More than one query parameter)
#
# check: Server sends response containing Type=0/2(Con/ACK),
# Code=69(2.05 content), Payload=Content of the requested resource,
# Content type option
#
# verify: client displays received response
#
function TD_COAP_CORE_13 {
clientopts="$callopts -m get"
testaddress=coap://$SERVERTUP/query
query="?first=1&second=2&third=3"
echo -e "perform GET (CON mode) on resource $testaddress with query $query"
testaddress=$testaddress$query
start_coap_test $1
}
##
# Perform GET transaction to resource /test in lossy context
#
# pre: gateway is introduced and configured to produce packet loss,
# resource /test exists on server
#
# Configuration=CoAP_CFG_02
#
# observe: One dropped request, one dropped request ACK, one dropped
# response, one dropped response ACK and its retransmission, test
# sequence should be executed several times
#
# Client sends a confirmable GET request to server's resource
#
# check: sent request contains Type=0(CON) and Code=1(GET), Client
# generated Message ID
#
# check: Server sends response containing Type=2(ACK), Code=69(2.05
# content), Payload=Content of the requested resource, Content type
# option
#
# verify: client displays received response
#
function TD_COAP_CORE_14 {
clientopts="$callopts -m get"
#FIXME: address for lossy context?
testaddress=coap://$SERVERTUP/test
echo "perform GET (CON mode) on resource $testaddress in lossy context"
start_coap_test $1
}
##
# Perform GET transaction to resource /separate in lossy context
#
# pre: gateway is introduced and configured to produce packet loss,
# resource /separate exists which cannot be served immediately and
# which cannot be acknowledged in a piggy-backed way
#
# Configuration=CoAP_CFG_02
#
# observe: One dropped request, one dropped request ACK, one dropped
# response, one dropped response ACK and its retransmission, test
# sequence should be executed several times
#
# Client sends a confirmable GET request to server's resource
#
# check: sent request contains Type=0(CON) and Code=1(GET), Client
# generated Message ID
#
# check: server sends response containing Type=2(ACK), Message ID same
# as the request, empty Payload
#
# check: Server sends response containing Type=0(CON), Code=69(2.05
# content), Payload=Content of the requested resource, Content type
# option
#
# check: Client sends response containing Type=2(ACK), message ID same
# as the response, empty Payload
#
# verify: client displays received response
#
function TD_COAP_CORE_15 {
clientopts="$callopts -m get"
#FIXME: address for lossy context?
testaddress=coap://$SERVERTUP/separate
echo "perform GET (CON mode) on resource $testaddress in lossy context"
start_coap_test $1
}
### LINK ###
##
# Access to well-known interface for resource discovery
#
# Pre: client supports CoRE Link Format, server supports
# /.well-known/core resource and the CoRE Link Format
#
# Client retrieves Server's list of resource
#
# check: client sends GET request for /.well-known/core resource
#
# check: server sends response containing content-type option
# indicating 40 (application/link-format), payload indicating all the
# links available on Server
#
# client displays the list of resources available on Server
#
function TD_COAP_LINK_01 {
clientopts="$callopts -m get"
testaddress=coap://$SERVERTUP/.well-known/core
echo "retrieve server's list of resource"
start_tcpdump $1
if [ $verbose ]; then
echo "client command: $COAP_CLIENT $clientopts $testaddress"
fi
clientoutput=$($COAP_CLIENT $clientopts "$testaddress")
if [[ ! $(echo $clientoutput | grep rt) ]] ; then
echo "no resource with attribute rt found on server"
else
rt="${clientoutput##*rt=}"
rt="${rt%%;*}"
fi
echo -e "\nOutput of client:"
echo -e $clientoutput
echo
kill_tcpdump
}
##
# Use filtered requests for limiting discovery results
#
# Pre: client supports CoRE Link Format, server supports CoRE Link
# Format and offers different types of resources (Type 1, Type 2
# (extracted from /.well-knwon/core resource
#
# Client retrieves Server's list of resource of a specific Type 1
#
# check: client sends GET request for /.well-known/core resource
# containing URI-Query indicating "rt=Type1"
#
# check: server sends response containing content-type option
# indicating 40 (application/link-format), payload indicating only the
# links of type Type1 available on server
#
# client displays the list of resources of type Type1 available on Server
#
function TD_COAP_LINK_02 {
clientopts="$callopts -m get"
echo "retrieve server's list of resource for appropriate type"
if [[ ! -z $rt ]]; then
testaddress="coap://$SERVERTUP/.well-known/core?rt=$rt"
else
echo "no appropriate resource found. Skipping test"
return
fi
start_coap_test $1
}
### BLOCK ###
##
# Perform GET blockwise transfer for large resource (early negotiation)
#
# pre: Client supports Block transfers, Server supports Block
# transfers, Server offers a large resource /large, client knows
# /large requires block transfer
#
# Client is requested to retrieve resource /large
#
# check: client sends a GET request containing Block2 option indicating block
# number 0 and desired block size
#
# check: Each request contains Block2 option indicating block number
# of the next block and size of the last received block
#
# check: server sends further responses containing Block2 option
# indicating block number and size
#
# verify: client displays received response
#
function TD_COAP_BLOCK_01 {
clientopts="$callopts -m get -b 1024"
testaddress=coap://$SERVERTUP/large
echo "perform GET on large resource $testaddress (early negotiation)"
start_coap_test $1
}
##
# Perform GET blockwise transfer for large resource (late negotiation)
#
# pre: Client supports Block transfers, Server supports Block
# transfers, Server offers a large resource /large, client does not
# know /large requires block transfer
#
# Client is requested to retrieve resource /large
#
# check: client sends a GET request not containing Block2 option
#
# check: server sends response containing Block2 option indicating
# block number and size
#
# check: Each request contains Block2 option indicating block number
# of the next block and size of the last received block or the desired
# size of the next block
#
# check: server sends further responses containing Block2 option
# indicating block number and size
#
# verify: client displays received response
#
function TD_COAP_BLOCK_02 {
clientopts="$callopts -m get"
testaddress=coap://$SERVERTUP/large
echo "perform GET blockwise transfer for large resource (late negotiation) on resource $testaddress"
start_coap_test $1 stop
}
##
# Perform PUT blockwise transfer for large resource
#
# pre: Client supports Block transfers, Server supports Block
# transfers, Server offers a large updatable resource /large-update
#
# Client is requested to retrieve resource /large-update on server
#
# check: client sends a PUT request containing Block1 option
# indicating block number 0 and block size
#
# check: client sends further request containing Block1 option
# indicating block number and size
#
# verify: server indicates presence of the complete updated resource
# /large-update
#
function TD_COAP_BLOCK_03 {
clientopts="$callopts -m put -b 1024"
testaddress=coap://$SERVERTUP/large-update
echo "perform PUT on large resource $testaddress"
start_coap_test $1
}
##
# Perform POST blockwise transfer for large resource
#
# pre: Client supports Block transfers, Server supports Block
# transfers, Server accepts creation of new resources on /large-create
#
# Client is requested to create a new resource on server
#
# check: client sends a POST request containing Block1 option
# indicating block number 0 and block size
#
# check: client sends further requests containing Block1 option
# indicating block number and size
#
# verify: server indicates presence of the complete new resource
#
function TD_COAP_BLOCK_04 {
clientopts="$callopts -m post -b 1024"
testaddress=coap://$SERVERTUP/large-create
echo "perform POST on large resource $testaddress"
start_coap_test $1
}
# # OBS
##
# Handle observe option
#
# pre: client supports Observe option, server supports observe option,
# server offers an observable resource /obs which changes periodically
# (e.g. every 5s.)
#
# client is requested to observe resource /obs on server
#
# check: client sends a GET request containing observe option
#
# verify: client displays the received information
#
# check: server sends response containing observe option indicating
# increasing values, as resource changes
#
# verify: client displays the updated information
#
function TD_COAP_OBS_01 {
# we need some time to verify the correct behavior
clientopts="$callopts -s 0" #"-v 5 -B $longtimeout -s 0"
testaddress=coap://$SERVERTUP/obs
echo "observe resource $testaddress"
start_coap_test $1
}
##
# Stop resource observation
#
# pre: client supports Observe option, server supports observe option,
# server offers an observable resource /obs which changes periodically
# (e.g. every 5s.), client is observing /obs on server
#
# client is requested to stop observing resource /obs on server
#
# check: client sends a GET request not containing observe option
#
# verify: client displays the received information
#
# check: server does not send further response
#
# verify: client does not display the updated information
#
# function TD_COAP_OBS_02 {
# #FIXME: client does not support stopping yet
# we need some time to verify the correct behavior
# clientopts="-v 5 -B $longtimeout -s 1"
# testaddress=coap://$SERVERTUP/obs
# echo "stop observing resource $testaddress"
# start_coap_test $1
# }
##
# client detection of deregistration (Max-Age)
#
# pre: client supports Observe option, server supports observe option,
# server offers an observable resource /obs which changes periodically
# (e.g. every 5s.), client is observing /obs on server
#
# Server is rebooted
#
# check: Server does not send notifications
#
# verify: Client does not display updated information
#
# verify: After Max-Age expiration, client sends a new GET with observe
# option for Server's observable resource
#
# check: Sent request contains Observe option indicating 0
#
# check: Server sends response containing Observe option
#
# verify: client displays the received information
#
# check: Server sends response containing Observe option indicating
# increasing values, as resource changes
#
# verify: Client displays the updated information
#
function TD_COAP_OBS_03 {
clientopts="$callopts -s 0"#"-v5 -B $longtimeout -s 0"
testaddress=coap://$SERVERTUP/obs
echo "client detection of deregistration (Max-Age)"
start_coap_test $1
}
##
# Server detection of deregistration (client OFF)
#
# pre: client supports Observe option, server supports observe option,
# server offers an observable resource /obs which changes periodically
# (e.g. every 5s.), client is observing /obs on server
#
# Client is switched off
#
# check: Servers confirmable responses are not acknowledged
#
# verify: After some delay, Server does not send further responses
#
function TD_COAP_OBS_04 {
clientopts="$callopts -s 0"
#"-v 5 -B $longtimeout -s 0"
testaddress=coap://$SERVERTUP/obs
echo "server detection of deregistration (client off)"
start_coap_test $1 wait
}
##
# Server detection of deregistration (explicit RST)
#
# pre: client supports Observe option, server supports observe option,
# server offers an observable resource /obs which changes periodically
# (e.g. every 5s.), client is observing /obs on server
#
# Client is rebooted
#
# check: Server sends response containing Observe option
#
# verify: Client discards response and does not display information
#
# check: Client sends RST to Server
#
# check: Server does not send further response
#
function TD_COAP_OBS_05 {
clientopts="$callopts -s 0 -p $CLIENTPORT"
#"-v 5 -B $longtimeout -p $CLIENTPORT -s 0"
testaddress=coap://$SERVERTUP/obs
echo "server detection of deregistration (explicit RST)"
start_coap_test $1 stop
clientopts="$callopts -p $CLIENTPORT -s 0 -N"
#"-v 5 -B $clienttimeout -p $CLIENTPORT -s 0 -N"
testaddress=coap://[::1]/obs
start_coap_test $1
}
-66
View File
@@ -1,66 +0,0 @@
/*
* This file was copied from the following newsgroup posting:
*
* Newsgroups: mod.std.unix
* Subject: public domain AT&T getopt source
* Date: 3 Nov 85 19:34:15 GMT
*
* Here's something you've all been waiting for: the AT&T public domain
* source for getopt(3). It is the code which was given out at the 1985
* UNIFORUM conference in Dallas. I obtained it by electronic mail
* directly from AT&T. The people there assure me that it is indeed
* in the public domain.
*/
#include <stdio.h>
#include <string.h>
static int opterr = 1;
static int optind = 1;
static int optopt;
static char *optarg;
static int getopt(int argc, char *argv[], char *opts)
{
static int sp = 1;
int c;
char *cp;
if (sp == 1) {
if (optind >= argc ||
argv[optind][0] != '-' || argv[optind][1] == '\0')
return EOF;
else if (!strcmp(argv[optind], "--")) {
optind++;
return EOF;
}
}
optopt = c = argv[optind][sp];
if (c == ':' || !(cp = strchr(opts, c))) {
fprintf(stderr, ": illegal option -- %c\n", c);
if (argv[optind][++sp] == '\0') {
optind++;
sp = 1;
}
return '?';
}
if (*++cp == ':') {
if (argv[optind][sp+1] != '\0')
optarg = &argv[optind++][sp+1];
else if(++optind >= argc) {
fprintf(stderr, ": option requires an argument -- %c\n", c);
sp = 1;
return '?';
} else
optarg = argv[optind++];
sp = 1;
} else {
if (argv[optind][++sp] == '\0') {
sp = 1;
optind++;
}
optarg = NULL;
}
return c;
}
-7
View File
@@ -1,7 +0,0 @@
# not going for submodules here to keep things easy
lwip
lwip-contrib
# never objects, and not the resulting binary
*.o
server
-69
View File
@@ -1,69 +0,0 @@
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
# Need to determine which library clock_gettime() resides in (as found by ./autogen.sh)
LDLIBS := $(shell if [ ../../config.log ] ; then grep ac_cv_search_clock_gettime=- ../../config.log|cut -d= -f2 ; fi)
all: server
lwip:
git clone --depth 1 git://git.savannah.nongnu.org/lwip.git -b $(WITH_LWIP_BRANCH)
(cd lwip ; git checkout $(WITH_LWIP_BRANCH))
$(MAKE)
lwip-contrib:
git clone --depth 1 git://git.savannah.nongnu.org/lwip/lwip-contrib.git -b $(WITH_LWIP_CONTRIB_BRANCH)
(cd lwip-contrib ; git checkout $(WITH_LWIP_CONTRIB_BRANCH))
$(MAKE)
# lwip and coap opts (include early to shadow the lwip-contrib/ports/unix/proj/minimal/ file and any ../../config.h)
CFLAGS += -DWITH_LWIP -iquote.
# lwip library
LWIPOBJS = def.o init.o tapif.o etharp.o netif.o timeouts.o stats.o mem.o memp.o udp.o tcp.o pbuf.o ip4_addr.o ip4.o inet_chksum.o tcp_in.o tcp_out.o icmp.o raw.o ip4_frag.o sys_arch.o ethernet.o ip.o
vpath %.c lwip/src/core/ lwip-contrib/ports/unix/proj/minimal/ lwip/src/netif/ lwip/src/core/ipv4/ lwip-contrib/ports/unix/port/ lwip-contrib/ports/unix/port/netif/
# CFLAGS += -DLWIP_UNIX_LINUX
# if ipv6 is used
vpath %.c lwip/src/core/ipv6/
LWIPOBJS += mld6.o ip6.o icmp6.o ethip6.o nd6.o ip6_addr.o ip6_frag.o
# coap library
CFLAGS += -std=gnu99
# 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_cache.o coap_debug.o coap_option.o resource.o pdu.o encode.o coap_subscribe.o coap_io_lwip.o block.o uri.o str.o coap_session.o coap_notls.o coap_hashkey.o coap_address.o coap_tcp.o coap_async.o
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/
OBJS = server.o server-coap.o ${LWIPOBJS} ${COAPOBJS}
$(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 $(coap_include_dir)/coap.h
server: ${OBJS}
clean:
rm -f ${OBJS}
.PHONY: clean
-30
View File
@@ -1,30 +0,0 @@
Example of libcoap running on lwIP
==================================
To run the example, do
$ make
$ sudo ./server
(and in a second terminal)
$ sudo ip a a dev tap0 192.168.113.1/24
and query `coap://192.168.113.2/time?ticks` with any coap tool,
or query `coap://[aaaa::1000]/.well-known/core`
This will
* download lwip and lwip-contrib from the upstream git sources
* build the server application
* run the server application, creating a virtual network device tap0 (unless
that exists)
* configure your network interface to make the server accessible.
* return the appropriate response from the server to the client.
The server creates a resource for 'time' with a query 'ticks'. This is
reported for `.well-known/core`. The work flow for adding more resources does
not differ from regular libcoap usage. If you seem to run out of memory
creating the resources, tweak the number of pre-allocated resources
in `include/coap/lwippools.h`.
-1
View File
@@ -1 +0,0 @@
../../coap_config.h.lwip
-37
View File
@@ -1,37 +0,0 @@
/*
* 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
#define LWIP_SOCKET (NO_SYS==0)
#define LWIP_NETCONN (NO_SYS==0)
#define LWIP_NETIF_API (NO_SYS==0)
#define LWIP_IPV6 1
#define LWIP_IPV6_REASS 0
#ifndef LWIP_RAND
#define LWIP_RAND() ((u32_t)rand())
#endif
#ifndef netif_get_index
#define netif_get_index(netif) ((u8_t)((netif)->num + 1))
#endif
#if NO_SYS
#include <pthread.h>
extern pthread_mutex_t lwprot_mutex;
extern pthread_t lwprot_thread;
extern int lwprot_count;
#endif
#define MEMP_USE_CUSTOM_POOLS 1
-147
View File
@@ -1,147 +0,0 @@
/*
* server-coap.h -- LwIP example
*
* Copyright (C) 2013-2016 Christian Amsüss <chrysn@fsfe.org>
* Copyright (C) 2018-2022 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 <coap3/coap.h>
coap_context_t *main_coap_context;
static coap_time_t clock_offset;
/* changeable clock base (see handle_put_time()) */
static coap_time_t my_clock_base = 0;
static coap_resource_t *time_resource = NULL; /* just for testing */
#ifndef min
# define min(a,b) ((a) < (b) ? (a) : (b))
#endif
void
hnd_get_time(coap_resource_t *resource, coap_session_t *session,
const coap_pdu_t *request, const coap_string_t *query,
coap_pdu_t *response) {
unsigned char buf[40];
size_t len;
coap_tick_t now;
coap_tick_t t;
/* 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 (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);
}
}
}
void
init_coap_resources(coap_context_t *ctx) {
coap_resource_t *r;
#if 0
r = coap_resource_init(NULL, 0, 0);
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_index);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_attr(r, coap_make_str_const("title"), coap_make_str_const("\"General Info\""), 0);
coap_add_resource(ctx, r);
#endif
/* store clock base to use in /time */
my_clock_base = clock_offset;
r = coap_resource_init(coap_make_str_const("time"), 0);
if (!r)
goto error;
coap_resource_set_get_observable(r, 1);
time_resource = r;
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_time);
#if 0
coap_register_handler(r, COAP_REQUEST_PUT, hnd_put_time);
coap_register_handler(r, COAP_REQUEST_DELETE, hnd_delete_time);
#endif
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
/* coap_add_attr(r, coap_make_str_const("title"), coap_make_str_const("\"Internal Clock\""), 0); */
coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("\"ticks\""), 0);
coap_add_attr(r, coap_make_str_const("if"), coap_make_str_const("\"clock\""), 0);
coap_add_resource(ctx, r);
#if 0
#ifndef WITHOUT_ASYNC
r = coap_resource_init(coap_make_str_const("async"), 0);
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_async);
coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0);
coap_add_resource(ctx, r);
#endif /* WITHOUT_ASYNC */
#endif
return;
error:
coap_log(LOG_CRIT, "cannot create resource\n");
}
void server_coap_init(void)
{
coap_address_t listenaddress;
coap_address_init(&listenaddress);
/* looks like a server address, but is used as end point for clients too */
listenaddress.addr = *(IP_ANY_TYPE);
listenaddress.port = COAP_DEFAULT_PORT;
coap_set_log_level(LOG_DEBUG);
main_coap_context = coap_new_context(&listenaddress);
LWIP_ASSERT("Failed to initialize context", main_coap_context != NULL);
clock_offset = 1; /* Need a non-zero value */
init_coap_resources(main_coap_context);
}
void server_coap_poll(void)
{
static coap_time_t last_time = 0;
coap_tick_t ticks_now;
coap_time_t time_now;
coap_ticks(&ticks_now);
time_now = coap_ticks_to_rt(ticks_now);
if (last_time != time_now) {
/* This takes place once a second */
last_time = time_now;
coap_resource_notify_observers(time_resource, NULL);
}
coap_check_notify(main_coap_context);
}
-17
View File
@@ -1,17 +0,0 @@
/*
* 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 <coap3/coap.h>
void server_coap_init(void);
/* call this when you think that resources could be dirty */
void server_coap_poll(void);
-91
View File
@@ -1,91 +0,0 @@
/*
* Demo for libcoap on lwIP
*
* partially copied from lwip-contrib/ports/unix/proj/minimal/main.c
*
*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* Author: Adam Dunkels <adam@sics.se>
* RT timer modifications by Christiaan Simons
* lwip adaptions: chrysn <chrysn@fsfe.org>
* also, https://savannah.nongnu.org/bugs/?40245 was applied */
#include "server-coap.h"
#include <lwip/init.h>
#include <lwip/timeouts.h>
#include <netif/etharp.h>
#include <netif/tapif.h>
#include <signal.h>
static ip4_addr_t ipaddr, netmask, gw;
int
main(int argc, char **argv)
{
struct netif netif;
/* startup defaults (may be overridden by one or more opts). this is
* hard-coded v4 even in presence of v6, which does auto-discovery and
* should thus wind up with an address of fe80::12:34ff:fe56:78ab%tap0
* */
IP4_ADDR(&gw, 192,168,113,1);
IP4_ADDR(&ipaddr, 192,168,113,2);
IP4_ADDR(&netmask, 255,255,255,0);
lwip_init();
printf("TCP/IP initialized.\n");
netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input);
netif.flags |= NETIF_FLAG_ETHARP;
netif_set_default(&netif);
netif_set_up(&netif);
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&netif, 1);
#endif
/* start applications here */
server_coap_init();
printf("Applications started.\n");
while (1) {
/* poll netif, pass packet to lwIP */
tapif_select(&netif);
sys_check_timeouts();
server_coap_poll();
}
return 0;
}
-43
View File
@@ -1,43 +0,0 @@
# 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
-9
View File
@@ -1,9 +0,0 @@
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.
-183
View File
@@ -1,183 +0,0 @@
/* tiny -- tiny sender
*
* 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.
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <signal.h>
#include <coap3/coap.h>
#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))
#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 int quit = 0;
/* SIGINT handler: set quit to 1 for graceful termination */
static void
handle_sigint(int signum COAP_UNUSED) {
quit = 1;
}
static coap_pdu_t *
make_pdu( coap_session_t *session, unsigned int value ) {
coap_pdu_t *pdu;
unsigned char enc;
static unsigned char buf[20];
int len, ls;
if (!(pdu = coap_pdu_init(COAP_MESSAGE_NON, COAP_REQUEST_CODE_POST,
coap_new_message_id(session), COAP_DEFAULT_MTU)))
return NULL;
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 );
return pdu;
}
static void
usage( const char *program ) {
const char *p;
p = strrchr( program, '/' );
if ( p )
program = ++p;
fprintf( stderr, "%s -- tiny fake sensor\n"
"(c) 2010 Olaf Bergmann <bergmann@tzi.org>\n\n"
"usage: %s [group address]\n"
"\n\nSends some fake sensor values to specified multicast group\n",
program, program );
}
static coap_session_t *
get_session(coap_context_t *ctx, const char *group) {
int s;
struct addrinfo hints;
struct addrinfo *result, *rp;
coap_session_t *session;
int hops = 16;
if (!ctx)
return NULL;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Coap uses UDP */
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST | AI_NUMERICSERV | AI_ALL;
s = getaddrinfo(group, NULL, &hints, &result);
if ( s != 0 ) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
return NULL;
}
/* iterate through results until success */
for (rp = result; rp != NULL; rp = rp->ai_next) {
coap_address_t addr;
coap_address_init(&addr);
addr.size = rp->ai_addrlen;
memcpy(&addr.addr, rp->ai_addr, rp->ai_addrlen);
session = coap_new_client_session(ctx, NULL, &addr, COAP_PROTO_UDP);
if (!session)
continue;
if (IN6_IS_ADDR_MULTICAST(&addr.addr.sin6.sin6_addr) ) {
/* set socket options for multicast */
if (!coap_mcast_set_hops(session, hops))
perror("setsockopt: IPV6_MULTICAST_HOPS");
}
freeaddrinfo(result);
return session;
}
fprintf(stderr, "no session available for group '%s'\n", group);
freeaddrinfo(result);
return NULL;
}
int
main(int argc, char **argv) {
struct timeval tv;
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 );
}
ctx = coap_new_context(NULL);
if (!ctx)
return -1;
session = get_session(ctx, argc > 1 ? argv[1] : "::1");
if ( !session )
return -1;
memset (&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = handle_sigint;
sa.sa_flags = 0;
sigaction (SIGINT, &sa, NULL);
sigaction (SIGTERM, &sa, NULL);
/* So we do not exit on a SIGPIPE */
sa.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sa, NULL);
while ( !quit ) {
if (! (pdu = make_pdu( session, rand() & 0xfff ) ) )
break;
coap_send(session, pdu);
tv.tv_sec = 5; tv.tv_usec = 0;
select( 0, 0, 0, 0, &tv );
}
coap_free_context(ctx);
return 0;
}
-431
View File
@@ -1,431 +0,0 @@
/*
* block.h -- block transfer
*
* Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2022 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 block.h
* @brief CoAP Block information
*/
#ifndef COAP_BLOCK_H_
#define COAP_BLOCK_H_
#include "encode.h"
#include "coap_option.h"
#include "pdu.h"
/**
* @ingroup application_api
* @defgroup block Block Transfer
* API for handling PDUs using CoAP Block options (RFC7959)
* @{
*/
#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;
/**
* Structure of Block options with BERT support.
*/
typedef struct {
unsigned int num; /**< block number */
unsigned int m:1; /**< 1 if more blocks follow, 0 otherwise */
unsigned int szx:3; /**< block size (0-6) */
unsigned int aszx:3; /**< block size (0-7 including BERT */
unsigned int defined:1; /**< Set if block found */
unsigned int bert:1; /**< Operating as BERT */
uint32_t chunk_size; /**< > 1024 if BERT */
} coap_block_b_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 initialize.
*
* @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);
/**
* 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. BERT information is abstracted as
* appropriate.
*
* @param session THe session that the pdu is associated with,
* @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 initialize.
*
* @return @c 1 on success, @c 0 otherwise.
*/
int coap_get_block_b(const coap_session_t *session, const coap_pdu_t *pdu,
coap_option_num_t number, coap_block_b_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);
/**
* 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 session The CoAP session.
* @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_b_opt(coap_session_t *session,
coap_block_b_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);
/**
* Adds the appropriate payload data of the body to the @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 The block information (including potentially BERT)
*
* @return @c 1 on success, @c 0 otherwise.
*/
int coap_add_block_b_data(coap_pdu_t *pdu, size_t len, const uint8_t *data,
coap_block_b_t *block);
/**
* 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.
*
* This function will fail if data has aready been added to the @p pdu.
*
* 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 and Request-Tag 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 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.
*
* This function will fail if data has aready been added to the @p pdu.
*
* 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 Content-Format, Max-Age 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 content 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_ */
-67
View File
@@ -1,67 +0,0 @@
/*
* coap.h -- main header file for CoAP stack of libcoap
*
* Copyright (C) 2010-2012,2015-2022 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.1"
/* Define the home page for libcoap. */
#define LIBCOAP_PACKAGE_URL "https://libcoap.net/"
/* Define the version of libcoap this file belongs to. */
#define LIBCOAP_PACKAGE_VERSION "4.3.1"
/* Define the numeric version identifier for libcoap */
#define LIBCOAP_VERSION (4003001U)
#ifdef __cplusplus
extern "C" {
#endif
#include "coap3/libcoap.h"
#include "securec.h"
#include "coap3/coap_forward_decls.h"
#include "coap3/block.h"
#include "coap3/coap_address.h"
#include "coap3/coap_async.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_option.h"
#include "coap3/coap_subscribe.h"
#include "coap3/coap_time.h"
#include "coap3/encode.h"
#include "coap3/mem.h"
#include "coap3/net.h"
#include "coap3/pdu.h"
#include "coap3/resource.h"
#include "coap3/str.h"
#include "coap3/uri.h"
#ifdef __cplusplus
}
#endif
#endif /* COAP_H_ */
-65
View File
@@ -1,65 +0,0 @@
/*
* coap.h -- main header file for CoAP stack of libcoap
*
* Copyright (C) 2010-2012,2015-2022 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@/block.h"
#include "coap@LIBCOAP_API_VERSION@/coap_address.h"
#include "coap@LIBCOAP_API_VERSION@/coap_async.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_option.h"
#include "coap@LIBCOAP_API_VERSION@/coap_subscribe.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@/pdu.h"
#include "coap@LIBCOAP_API_VERSION@/resource.h"
#include "coap@LIBCOAP_API_VERSION@/str.h"
#include "coap@LIBCOAP_API_VERSION@/uri.h"
#ifdef __cplusplus
}
#endif
#endif /* COAP_H_ */
-65
View File
@@ -1,65 +0,0 @@
/*
* coap.h -- main header file for CoAP stack of libcoap
*
* Copyright (C) 2010-2012,2015-2022 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.1"
/* Define the home page for libcoap. */
#define LIBCOAP_PACKAGE_URL "https://libcoap.net/"
/* Define the version of libcoap this file belongs to. */
#define LIBCOAP_PACKAGE_VERSION "4.3.1"
/* Define the numeric version identifier for libcoap */
#define LIBCOAP_VERSION (4003001U)
#ifdef __cplusplus
extern "C" {
#endif
#include "coap3/libcoap.h"
#include "coap3/coap_forward_decls.h"
#include "coap3/block.h"
#include "coap3/coap_address.h"
#include "coap3/coap_async.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_option.h"
#include "coap3/coap_prng.h"
#include "coap3/coap_subscribe.h"
#include "coap3/coap_time.h"
#include "coap3/encode.h"
#include "coap3/mem.h"
#include "coap3/net.h"
#include "coap3/pdu.h"
#include "coap3/resource.h"
#include "coap3/str.h"
#include "coap3/uri.h"
#ifdef __cplusplus
}
#endif
#endif /* COAP_H_ */
-65
View File
@@ -1,65 +0,0 @@
/*
* coap.h -- main header file for CoAP stack of libcoap
*
* Copyright (C) 2010-2012,2015-2022 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@/block.h"
#include "coap@LIBCOAP_API_VERSION@/coap_address.h"
#include "coap@LIBCOAP_API_VERSION@/coap_async.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_option.h"
#include "coap@LIBCOAP_API_VERSION@/coap_prng.h"
#include "coap@LIBCOAP_API_VERSION@/coap_subscribe.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@/pdu.h"
#include "coap@LIBCOAP_API_VERSION@/resource.h"
#include "coap@LIBCOAP_API_VERSION@/str.h"
#include "coap@LIBCOAP_API_VERSION@/uri.h"
#ifdef __cplusplus
}
#endif
#endif /* COAP_H_ */
-244
View File
@@ -1,244 +0,0 @@
/*
* coap_address.h -- representation of network addresses
*
* Copyright (C) 2010-2011,2015-2016,2022 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_address.h
* @brief Representation of network addresses
*/
#ifndef COAP_ADDRESS_H_
#define COAP_ADDRESS_H_
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include "libcoap.h"
#if defined(WITH_LWIP)
#include <lwip/ip_addr.h>
typedef struct coap_address_t {
uint16_t port;
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)))
#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"
typedef struct coap_address_t {
uip_ipaddr_t addr;
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)))
/** @todo implementation of _coap_address_isany_impl() for Contiki */
#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 */
/** multi-purpose address abstraction */
typedef struct coap_address_t {
socklen_t size; /**< size of addr */
union {
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} 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
* @c NULL;
*/
int coap_address_equals(const coap_address_t *a, const coap_address_t *b);
COAP_STATIC_INLINE int
_coap_address_isany_impl(const coap_address_t *a) {
/* need to compare only relevant parts of sockaddr_in6 */
switch (a->addr.sa.sa_family) {
case AF_INET:
return a->addr.sin.sin_addr.s_addr == INADDR_ANY;
case AF_INET6:
return memcmp(&in6addr_any,
&a->addr.sin6.sin6_addr,
sizeof(in6addr_any)) == 0;
default:
;
}
return 0;
}
#endif /* WITH_LWIP || WITH_CONTIKI */
/**
* Resets the given coap_address_t object @p addr to its default values. In
* particular, the member size must be initialized to the available size for
* storing addresses.
*
* @param addr The coap_address_t object to initialize.
*/
void coap_address_init(coap_address_t *addr);
/**
* Convert the given coap_address_t object @p addr from binary to text form.
* Write the result to the destination space @p dst of length @p len.
*/
void coap_address_ntop(const coap_address_t *addr, char *dst, int len);
/* Convenience function to copy IPv6 addresses without garbage. */
COAP_STATIC_INLINE void
coap_address_copy( coap_address_t *dst, const coap_address_t *src ) {
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
memcpy( dst, src, sizeof( coap_address_t ) );
#else
memset( dst, 0, sizeof( coap_address_t ) );
dst->size = src->size;
if ( src->addr.sa.sa_family == AF_INET6 ) {
dst->addr.sin6.sin6_family = src->addr.sin6.sin6_family;
dst->addr.sin6.sin6_addr = src->addr.sin6.sin6_addr;
dst->addr.sin6.sin6_port = src->addr.sin6.sin6_port;
dst->addr.sin6.sin6_scope_id = src->addr.sin6.sin6_scope_id;
} else if ( src->addr.sa.sa_family == AF_INET ) {
dst->addr.sin = src->addr.sin;
} else {
memcpy( &dst->addr, &src->addr, src->size );
}
#endif
}
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
/**
* 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
* @c NULL;
*/
COAP_STATIC_INLINE int
coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
assert(a); assert(b);
return _coap_address_equals_impl(a, b);
}
#endif
/**
* Checks if given address object @p a denotes the wildcard address. This
* function returns @c 1 if this is the case, @c 0 otherwise. The parameters @p
* a must not be @c NULL;
*/
COAP_STATIC_INLINE int
coap_address_isany(const coap_address_t *a) {
assert(a);
return _coap_address_isany_impl(a);
}
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
/**
* Checks if given address @p a denotes a multicast address. This function
* 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
/**
* Checks if given address @p a denotes a broadcast address. This function
* returns @c 1 if @p a is broadcast, @c 0 otherwise.
*/
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
* returns @c 1 if @p a is multicast, @c 0 otherwise.
*/
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_ */
-90
View File
@@ -1,90 +0,0 @@
/*
* 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_
#include "coap_internal.h"
/**
* @ingroup internal_api
* @defgroup asn1 ASN.1 Support
* Internal API for CoAP ASN.1 handling
* @{
*/
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_ */
-128
View File
@@ -1,128 +0,0 @@
/*
* coap_async.h -- state management for asynchronous messages
*
* Copyright (C) 2010-2022 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.h
* @brief State management for asynchronous messages
*/
#ifndef COAP_ASYNC_H_
#define COAP_ASYNC_H_
#include "net.h"
/**
* @ingroup application_api
* @defgroup coap_async Asynchronous Messaging
* @{
* API for delayed "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);
/**
* Trigger the registered @p async.
*
* A copy of the original request will get sent to the appropriate request
* handler.
*
* @param async The async object to trigger.
*/
void
coap_async_trigger(coap_async_t *async);
/**
* 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_ */
-69
View File
@@ -1,69 +0,0 @@
/*
* coap_async_internal.h -- state management for asynchronous messages
*
* Copyright (C) 2010-2022 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 "coap_internal.h"
#include "net.h"
/* Note that if COAP_SERVER_SUPPORT is not set, then WITHOUT_ASYNC undefined */
#ifndef WITHOUT_ASYNC
/**
* @ingroup internal_api
* @defgroup coap_async_internal Asynchronous Messaging
* @{
* Internal API for CoAP Asynchronous processing.
* 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_ */
-231
View File
@@ -1,231 +0,0 @@
/*
* coap_block_internal.h -- Structures, Enums & Functions that are not
* exposed to application programming
*
* Copyright (C) 2010-2022 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2021-2022 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_internal.h"
#include "coap_pdu_internal.h"
#include "resource.h"
/**
* @ingroup internal_api
* @defgroup block_internal Block Transfer
* Internal API for Block Transfer (RC7959)
* @{
*/
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 */
uint64_t state_token; /**< state token */
size_t bert_size; /**< size of last BERT block */
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_pdu_code_t request_method; /**< Method used to request this data */
} 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_sent; /**< Last time any data sent */
coap_tick_t last_all_sent; /**< Last time all data sent or 0 */
coap_tick_t last_obs; /**< Last time used (Observe tracking) or 0 */
coap_release_large_data_t release_func; /**< large data de-alloc function */
void *app_ptr; /**< applicaton provided ptr for de-alloc function */
};
#if COAP_CLIENT_SUPPORT
/**
* 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 observe_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 szx; /**< size of individual blocks */
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 */
uint16_t block_option; /**< Block option in use */
uint16_t retry_counter; /**< Retry counter (part of state token) */
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 */
coap_binary_t *obs_token; /**< Initial Observe response PDU token */
uint64_t state_token; /**< state 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 */
};
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
/**
* 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 */
};
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
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);
int coap_block_check_lg_crcv_timeouts(coap_session_t *session,
coap_tick_t now,
coap_tick_t *tim_rem);
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
void coap_block_delete_lg_srcv(coap_session_t *session,
coap_lg_srcv_t *lg_srcv);
int coap_block_check_lg_srcv_timeouts(coap_session_t *session,
coap_tick_t now,
coap_tick_t *tim_rem);
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);
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
int coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent,
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);
#endif /* COAP_CLIENT_SUPPORT */
void coap_block_delete_lg_xmit(coap_session_t *session,
coap_lg_xmit_t *lg_xmit);
int coap_block_check_lg_xmit_timeouts(coap_session_t *session,
coap_tick_t now,
coap_tick_t *tim_rem);
/**
* 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
* @param request_method The requested method
*/
void coap_check_code_lg_xmit(coap_session_t *session, coap_pdu_t *response,
coap_resource_t *resource, coap_string_t *query,
coap_pdu_code_t request_method);
/** @} */
#endif /* COAP_BLOCK_INTERNAL_H_ */
-234
View File
@@ -1,234 +0,0 @@
/* coap_cache.h -- Caching of CoAP requests
*
* Copyright (C) 2020-2022 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"
/**
* @ingroup application_api
* @defgroup cache Cache Support
* API for Cache-Key and Cache-Entry.
* See https://datatracker.ietf.org/doc/html/rfc7252#section-5.4.2
* @{
*/
/**
* 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.4.2
* 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.4.2
* 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 */
-115
View File
@@ -1,115 +0,0 @@
/*
* 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_internal.h"
#include "coap_io.h"
#if COAP_SERVER_SUPPORT
/**
* @ingroup internal_api
* @defgroup cache_internal Cache Support
* Internal API for Cache-Key and Cache-Entry support
* @{
*/
/* 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_SERVER_SUPPORT */
#endif /* COAP_CACHE_INTERNAL_H_ */
-191
View File
@@ -1,191 +0,0 @@
/* 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 libcoap supports client mode code */
#define COAP_CLIENT_SUPPORT 1
/* 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 if libcoap supports server mode code */
#define COAP_SERVER_SUPPORT 1
/* 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 1 */
/* 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.1"
/* 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.1"
/* 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 */
-260
View File
@@ -1,260 +0,0 @@
/*
* coap_debug.h -- debug utilities
*
* Copyright (C) 2010-2011,2014-2022 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_debug.h
* @brief CoAP Logging support
*/
#ifndef COAP_DEBUG_H_
#define COAP_DEBUG_H_
/**
* @ingroup application_api
* @defgroup logging Logging Support
* API for logging support
* @{
*/
#ifndef COAP_DEBUG_FD
/**
* Used for output for @c LOG_DEBUG to @c LOG_ERR.
*/
#define COAP_DEBUG_FD stdout
#endif
#ifndef COAP_ERR_FD
/**
* Used for output for @c LOG_CRIT to @c LOG_EMERG.
*/
#define COAP_ERR_FD stderr
#endif
/**
* Logging type. One of LOG_* from @b syslog.
*/
typedef int coap_log_t;
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
#if defined(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>
#endif /* RIOT_VERSION */
#endif /* HAVE_SYSLOG_H */
#ifndef LOG_EMERG
# define LOG_EMERG 0
#endif
#ifndef LOG_ALERT
# define LOG_ALERT 1
#endif
#ifndef LOG_CRIT
# define LOG_CRIT 2
#endif
#ifndef LOG_ERR
# define LOG_ERR 3
#endif
#ifndef LOG_WARNING
# define LOG_WARNING 4
#endif
#ifndef LOG_NOTICE
# define LOG_NOTICE 5
#endif
#ifndef LOG_INFO
# define LOG_INFO 6
#endif
#ifndef LOG_DEBUG
# define LOG_DEBUG 7
#endif
/*
LOG_DEBUG+2 gives ciphers in GnuTLS
Use COAP_LOG_CIPHERS to output Cipher Info in OpenSSL etc.
*/
#define COAP_LOG_CIPHERS (LOG_DEBUG+2)
/**
* Get the current logging level.
*
* @return One of the LOG_* values.
*/
coap_log_t coap_get_log_level(void);
/**
* Sets the log level to the specified value.
*
* @param level One of the LOG_* values.
*/
void coap_set_log_level(coap_log_t level);
/**
* Logging callback handler definition.
*
* @param level One of the LOG_* values.
* @param message Zero-terminated string message to log.
*/
typedef void (*coap_log_handler_t) (coap_log_t level, const char *message);
/**
* Add a custom log callback handler.
*
* @param handler The logging handler to use or @p NULL to use default handler.
*/
void coap_set_log_handler(coap_log_handler_t handler);
/**
* Get the library package name.
*
* @return Zero-terminated string with the name of this library.
*/
const char *coap_package_name(void);
/**
* Get the library package version.
*
* @return Zero-terminated string with the library version.
*/
const char *coap_package_version(void);
/**
* Get the library package build.
*
* @return Zero-terminated string with the library build.
*/
const char *coap_package_build(void);
/**
* Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c
* COAP_DEBUG_FD (for @p level >= @c LOG_ERR). The text is output only when
* @p level is below or equal to the log level that set by coap_set_log_level().
*
* Internal function.
*
* @param level One of the LOG_* values.
& @param format The format string to use.
*/
#if (defined(__GNUC__))
void coap_log_impl(coap_log_t level,
const char *format, ...) __attribute__ ((format(printf, 2, 3)));
#else
void coap_log_impl(coap_log_t level, const char *format, ...);
#endif
#ifndef coap_log
/**
* Logging function.
* Writes the given text to @c COAP_ERR_FD (for @p level <= @c LOG_CRIT) or @c
* COAP_DEBUG_FD (for @p level >= @c LOG_ERR). The text is output only when
* @p level is below or equal to the log level that set by coap_set_log_level().
*
* @param level One of the LOG_* values.
*/
#define coap_log(level, ...) do { \
if ((int)((level))<=(int)coap_get_log_level()) \
coap_log_impl((level), __VA_ARGS__); \
} while(0)
#endif
#include "pdu.h"
/**
* Defines the output mode for the coap_show_pdu() function.
*
* @param use_fprintf @p 1 if the output is to use fprintf() (the default)
* @p 0 if the output is to use coap_log().
*/
void coap_set_show_pdu_output(int use_fprintf);
/**
* Display the contents of the specified @p pdu.
* Note: The output method of coap_show_pdu() is dependent on the setting of
* coap_set_show_pdu_output().
*
* @param level The required minimum logging level.
* @param pdu The PDU to decode.
*/
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
/**
* Display the current (D)TLS library linked with and built for version.
*
* @param level The required minimum logging level.
*/
void coap_show_tls_version(coap_log_t level);
/**
* Build a string containing the current (D)TLS library linked with and
* built for version.
*
* @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_version(char *buffer, size_t bufsize);
/**
* 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.
*
* Internal Function.
*
* @param address The address to print.
* @param buffer The buffer to print into.
* @param size The size of the buffer to print into.
*
* @return The amount written into the buffer.
*/
size_t coap_print_addr(const coap_address_t *address,
unsigned char *buffer, size_t size);
/** @} */
/**
* Set the packet loss level for testing. This can be in one of two forms.
*
* Percentage : 0% to 100%. Use the specified probability.
* 0% is send all packets, 100% is drop all packets.
*
* List: A comma separated list of numbers or number ranges that are the
* packets to drop.
*
* @param loss_level The defined loss level (percentage or list).
*
* @return @c 1 If loss level set, @c 0 if there is an error.
*/
int coap_debug_set_packet_loss(const char *loss_level);
/**
* Check to see whether a packet should be sent or not.
*
* Internal function
*
* @return @c 1 if packet is to be sent, @c 0 if packet is to be dropped.
*/
int coap_debug_send_packet(void);
#endif /* COAP_DEBUG_H_ */
-491
View File
@@ -1,491 +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>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
/**
* @file coap_dtls.h
* @brief CoAP DTLS support
*/
#ifndef COAP_DTLS_H_
#define COAP_DTLS_H_
#include "coap_time.h"
#include "str.h"
/**
* @ingroup application_api
* @defgroup dtls DTLS Support
* API 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
#ifndef COAP_DTLS_MAX_PSK_IDENTITY
#define COAP_DTLS_MAX_PSK_IDENTITY 64
#endif
#ifndef COAP_DTLS_MAX_PSK
#define COAP_DTLS_MAX_PSK 64
#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 */
-408
View File
@@ -1,408 +0,0 @@
/*
* 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.
*/
/**
* @file coap_dtls_internal.h
* @brief Internal CoAP DTLS support
*/
#ifndef COAP_DTLS_INTERNAL_H_
#define COAP_DTLS_INTERNAL_H_
#include "coap_internal.h"
/**
* @ingroup internal_api
* @defgroup dtls_internal DTLS Support
* Internal API for DTLS Support
* @{
*/
/* 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);
#if COAP_SERVER_SUPPORT
/**
* 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);
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
/**
* 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);
#endif /* COAP_CLIENT_SUPPORT */
/**
* 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);
#if COAP_CLIENT_SUPPORT
/**
* 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);
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
/**
* 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);
#endif /* COAP_SERVER_SUPPORT */
/**
* 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.
*
* @return @c 1 timed out or @c 0 still timing out
*/
int 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);
#if COAP_SERVER_SUPPORT
/**
* 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);
#endif /* COAP_SERVER_SUPPORT */
/**
* 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);
#if COAP_CLIENT_SUPPORT
/**
* 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);
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
/**
* 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);
#endif /* COAP_SERVER_SUPPORT */
/**
* 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
);
/**
* Get the current client's PSK key.
*
* @param coap_session The CoAP session.
*
* @return @c NULL if no key, else a pointer the current key.
*/
const coap_bin_const_t *coap_get_session_client_psk_key(
const coap_session_t *coap_session);
/**
* Get the current client's PSK identity.
*
* @param coap_session The CoAP session.
*
* @return @c NULL if no identity, else a pointer the current identity.
*/
const coap_bin_const_t *coap_get_session_client_psk_identity(
const coap_session_t *coap_session);
/**
* Get the current server's PSK key.
*
* @param coap_session The CoAP session.
*
* @return @c NULL if no key, else a pointer the current key.
*/
const coap_bin_const_t *coap_get_session_server_psk_key(
const coap_session_t *coap_session);
/**
* Get the current server's PSK identity hint.
*
* @param coap_session The CoAP session.
*
* @return @c NULL if no hint, else a pointer the current hint.
*/
const coap_bin_const_t *coap_get_session_server_psk_hint(
const coap_session_t *coap_session);
/**
* 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 */
-146
View File
@@ -1,146 +0,0 @@
/*
* coap_event.h -- libcoap Event API
*
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2021-2022 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_event.h
* @brief Event handling
*/
#ifndef COAP_EVENT_H_
#define COAP_EVENT_H_
#include "libcoap.h"
/**
* @ingroup application_api
* @defgroup events Event Handling
* API for event delivery from lower-layer library functions.
* @{
*/
/**
* Scalar type to represent different events, e.g. DTLS events or
* retransmission timeouts.
*/
typedef enum {
/*
* (D)TLS events for COAP_PROTO_DTLS and COAP_PROTO_TLS
*/
/** Triggerred when (D)TLS session closed */
COAP_EVENT_DTLS_CLOSED = 0x0000,
/** Triggered when (D)TLS session connected */
COAP_EVENT_DTLS_CONNECTED = 0x01DE,
/** Triggered when (D)TLS session renegotiated */
COAP_EVENT_DTLS_RENEGOTIATE = 0x01DF,
/** Triggered when (D)TLS error occurs */
COAP_EVENT_DTLS_ERROR = 0x0200,
/*
* TCP events for COAP_PROTO_TCP and COAP_PROTO_TLS
*/
/** Triggered when TCP layer connects */
COAP_EVENT_TCP_CONNECTED = 0x1001,
/** Triggered when TCP layer is closed */
COAP_EVENT_TCP_CLOSED = 0x1002,
/** Triggered when TCP layer fails for some reason */
COAP_EVENT_TCP_FAILED = 0x1003,
/*
* CSM exchange events for reliable protocols only
*/
/** Triggered when TCP layer completes exchange of CSM information */
COAP_EVENT_SESSION_CONNECTED = 0x2001,
/** Triggered when TCP layer closes following exchange of CSM information */
COAP_EVENT_SESSION_CLOSED = 0x2002,
/** Triggered when TCP layer fails following exchange of CSM information */
COAP_EVENT_SESSION_FAILED = 0x2003,
/*
* (Q-)Block errors
*/
/** Triggered when not all of a large body has been received */
COAP_EVENT_PARTIAL_BLOCK = 0x3001,
/** Triggered when not all of a large body has been transmitted */
COAP_EVENT_XMIT_BLOCK_FAIL = 0x3002,
/*
* Server session events
*/
/**
* Called in the CoAP IO loop if a new *server-side* session is created due
* to an incoming connection.
*
* Note that the session might not be a fully established connection yet,
* it might also refer to, e.g., a DTLS session in a handshake stage.
*/
COAP_EVENT_SERVER_SESSION_NEW = 0x4001,
/**
* Called in the CoAP IO loop if a server session is deleted (e.g., due to
* inactivity or because the maximum number of idle sessions was exceeded).
*
* The session will still contain valid data when the event handler is
* called.
*/
COAP_EVENT_SERVER_SESSION_DEL = 0x4002
} coap_event_t;
/**
* 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 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)(coap_session_t *session,
const coap_event_t event);
/**
* Registers the function @p hnd as callback for events from the given
* CoAP context @p context. Any event handler that has previously been
* registered with @p context will be overwritten by this operation.
*
* @param context The CoAP context to register the event handler with.
* @param hnd The event handler to be registered. @c NULL if to be
* de-registered.
*/
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
* registered with @p context will be overwritten by this operation.
*
* @deprecated Use coap_register_event_handler() instead.
*
* @param context The CoAP context to register the event handler with.
* @param hnd The event handler to be registered.
*/
COAP_DEPRECATED
void coap_set_event_handler(coap_context_t *context,
coap_event_handler_t hnd);
/**
* Clears the event handler registered with @p context.
*
* @deprecated Use coap_register_event_handler() instead with NULL for hnd.
*
* @param context The CoAP context whose event handler is to be removed.
*/
COAP_DEPRECATED
void coap_clear_event_handler(coap_context_t *context);
#endif /* COAP_EVENT_H */
-107
View File
@@ -1,107 +0,0 @@
/*
* coap_forward_decls.h -- Forward declarations of structures that are
* opaque to application programming that use libcoap.
*
* Copyright (C) 2019-2022 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_ */
-61
View File
@@ -1,61 +0,0 @@
/*
* coap_hashkey.h -- definition of hash key type and helper functions
*
* 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 coap_hashkey.h
* @brief Definition of hash key type and helper functions
*/
#ifndef COAP_HASHKEY_H_
#define COAP_HASHKEY_H_
#include "libcoap.h"
#include "uthash.h"
#include "str.h"
typedef unsigned char coap_key_t[4];
#ifndef coap_hash
/**
* Calculates a fast hash over the given string @p s of length @p len and stores
* the result into @p h. Depending on the exact implementation, this function
* cannot be used as one-way function to check message integrity or simlar.
*
* @param s The string used for hash calculation.
* @param len The length of @p s.
* @param h The result buffer to store the calculated hash key.
*/
void coap_hash_impl(const unsigned char *s, size_t len, coap_key_t h);
#define coap_hash(String,Length,Result) \
coap_hash_impl((String),(Length),(Result))
/* This is used to control the pre-set hash-keys for resources. */
#define COAP_DEFAULT_HASH
#else
#undef COAP_DEFAULT_HASH
#endif /* coap_hash */
/**
* Calls coap_hash() with given @c coap_string_t object as parameter.
*
* @param Str Must contain a pointer to a coap string object.
* @param H A coap_key_t object to store the result.
*
* @hideinitializer
*/
#define coap_str_hash(Str,H) { \
assert(Str); \
memset((H), 0, sizeof(coap_key_t)); \
coap_hash((Str)->s, (Str)->length, (H)); \
}
#endif /* COAP_HASHKEY_H_ */
-82
View File
@@ -1,82 +0,0 @@
/*
* coap_internal.h -- Structures, Enums & Functions that are not exposed to
* application programming
*
* Copyright (C) 2019-2022 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.
*/
/*
* All libcoap library files should include this file which then pulls in all
* of the other appropriate header files.
*
* Note: This file should never be included in application code (with the
* possible exception of internal test suites).
*/
/**
* @file coap_internal.h
* @brief Pulls together all the internal only header files
*/
#ifndef COAP_INTERNAL_H_
#define COAP_INTERNAL_H_
#include "coap_config.h"
/*
* Correctly set up assert() based on NDEBUG for libcoap
*/
#if defined(HAVE_ASSERT_H) && !defined(assert)
# include <assert.h>
#endif
/* By default without either configured, these need to be set */
#ifndef COAP_SERVER_SUPPORT
#ifndef COAP_CLIENT_SUPPORT
#define COAP_SERVER_SUPPORT 1
#define COAP_CLIENT_SUPPORT 1
#endif /* COAP_CLIENT_SUPPORT */
#endif /* COAP_SERVER_SUPPORT */
#if ! COAP_SERVER_SUPPORT
#ifndef WITHOUT_ASYNC
/* ASYNC is only there for Server code */
#define WITHOUT_ASYNC
#endif /* WITHOUT_ASYNC */
#endif /* COAP_SERVER_SUPPORT */
#include "coap3/coap.h"
/*
* Include all the header files that are for internal use only.
*/
/* Not defined in coap.h - internal usage .h files */
#include "utlist.h"
#include "uthash.h"
#include "coap_hashkey.h"
#include "coap_mutex.h"
/* Specifically defined internal .h files */
#include "coap_asn1_internal.h"
#include "coap_async_internal.h"
#include "coap_block_internal.h"
#include "coap_cache_internal.h"
#include "coap_dtls_internal.h"
#include "coap_io_internal.h"
#include "coap_net_internal.h"
#include "coap_pdu_internal.h"
#include "coap_session_internal.h"
#include "coap_resource_internal.h"
#include "coap_session_internal.h"
#include "coap_subscribe_internal.h"
#include "coap_tcp_internal.h"
#define COAP_INTERFACE_MAX 16
#endif /* COAP_INTERNAL_H_ */
-77
View File
@@ -1,77 +0,0 @@
/*
* coap_io.h -- Default network I/O functions for libcoap
*
* Copyright (C) 2012-2013,2022 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_io.h
* @brief Default network I/O functions
*/
#ifndef COAP_IO_H_
#define COAP_IO_H_
#include <sys/types.h>
#include "coap_address.h"
#ifdef RIOT_VERSION
#include "net/gnrc.h"
#endif /* RIOT_VERSION */
#ifndef COAP_RXBUFFER_SIZE
#define COAP_RXBUFFER_SIZE 1472
#endif /* COAP_RXBUFFER_SIZE */
/*
* It may may make sense to define this larger on busy systems
* (lots of sessions, large number of which are active), by using
* -DCOAP_MAX_EPOLL_EVENTS=nn at compile time.
*/
#ifndef COAP_MAX_EPOLL_EVENTS
#define COAP_MAX_EPOLL_EVENTS 10
#endif /* COAP_MAX_EPOLL_EVENTS */
#ifdef _WIN32
typedef SOCKET coap_fd_t;
#define coap_closesocket closesocket
#define COAP_SOCKET_ERROR SOCKET_ERROR
#define COAP_INVALID_SOCKET INVALID_SOCKET
#else
typedef int coap_fd_t;
#define coap_closesocket close
#define COAP_SOCKET_ERROR (-1)
#define COAP_INVALID_SOCKET (-1)
#endif
typedef uint16_t coap_socket_flags_t;
typedef struct coap_addr_tuple_t {
coap_address_t remote; /**< remote address and port */
coap_address_t local; /**< local address and port */
} coap_addr_tuple_t;
const char *coap_socket_strerror( void );
/**
* Check whether TCP is available.
*
* @return @c 1 if support for TCP is enabled, or @c 0 otherwise.
*/
int coap_tcp_is_supported(void);
typedef enum {
COAP_NACK_TOO_MANY_RETRIES,
COAP_NACK_NOT_DELIVERABLE,
COAP_NACK_RST,
COAP_NACK_TLS_FAILED,
COAP_NACK_ICMP_ISSUE
} coap_nack_reason_t;
#endif /* COAP_IO_H_ */

Some files were not shown because too many files have changed in this diff Show More