1
0
mirror of https://github.com/obgm/libcoap.git synced 2025-10-14 02:19:34 +08:00

3128 Commits

Author SHA1 Message Date
raspopov
490e4e0452 Fix wolfSSL bug and MSVC compilation
When I was fixing MSVC compilation incompatibility due to a dynamic
array on the stack in the coap_crypto_aead_decrypt() function,
I accidentally noticed an incorrect calculation of the array size in
the previous coap_crypto_aead_encrypt() function.
2025-10-11 10:50:31 +01:00
raspopov
277f981ab3 Fix the MbedTSL compilation process under Windows
It adds the strndup() function, which is missing in Windows, as has been
done in other parts of libcoap.
2025-10-10 09:28:48 +01:00
Mario Kicherer
da1be4b5ca add COAP_BLOCK_FORCE_Q_BLOCK 2025-10-09 16:31:50 +01:00
Jon Shallow
48a1b83100 Q-Block: Various Q-Block fixes 2025-10-08 13:57:51 +01:00
raspopov
aaaf3d1324 Fix tinyDTLS compilation
The current code uses a dynamic array on the stack, a relatively rare
compiler extension. For example, MSVC does not support it.

The proposed changes use a classic dynamic array on the heap, which
greatly improves code compatibility. This will also enable libcoap to be
compiled alongside tinyDTLS using the Microsoft compiler on Windows.
2025-10-06 18:43:54 +01:00
raspopov
e9c1b0b5ea Fix MSVC compilation
Using the Ninja generator with the MSVC compiler leads to errors due to
incorrect compiler call options. In CMake, the generator and the
compiler are different entities.

This fix replaces the incorrect CMake variable with the correct one that
describes the current MSVC-compatible compiler.
2025-10-06 16:45:20 +01:00
Jon Shallow
fb77750ad3 coap_proxy.c: Correctly cache large proxy responses 2025-10-06 10:23:29 +01:00
Jon Shallow
0c563edfb7 Proxy: Support passing safe-to-forward critical options for reverse proxy 2025-10-06 10:18:55 +01:00
Jon Shallow
e16613eab9 configure.ac: Fix disabling IPv4 or IPv6 builds 2025-10-06 09:39:20 +01:00
raspopov
245354f0ef Fix HAVE_TIME_H and HAVE_SYS_TIME_H ifdefs
If we correctly determine the presence of the sys/time.h and time.h
files using the HAVE_TIME_H and HAVE_SYS_TIME_H macros, then the LWIP
compilation will result in a duplicate function error. Perhaps previous
versions of LWIP did not have these files, in which case everything
would have worked correctly.

These changes add the necessary ifdefs and keep the optimal timer
function for LWIP.

Adds missed #include <time.h> lines to examples and documentation.

Adds the detection of the sys/select.h header to the CMake and autoconf.
2025-10-06 09:38:52 +01:00
raspopov
5ca624642e Fix compiler warnings
Fixed warnings of unused variable
and possible use of initialized variable.
2025-10-06 09:37:00 +01:00
Jon Shallow
576b68e5db LwIP: Add in support for disabling IPv4 or IPv6
Note that TinyDTLS needs both IPv4 and IPv6 if DTLS is going to be used.
2025-10-02 18:48:17 +01:00
raspopov
6cbf590785 Fix coap_resolve_address_info() for LWIP
These changes add a basic implementation of the coap_resolve_address_info()
function when compiling LWIP with NO_SYS = 1. This implementation is
similar to those in CONTIKI and RIOT.

The function gai_strerror() was removed because it is not very important,
yet it is missing from many implementations.

A CONTIKI compilation bug has also been fixed.
2025-10-02 18:39:26 +01:00
raspopov
6f97006daa Fix Windows tests
In Windows, calling the connect function for a socket requires a valid
address. This causes the t_session6 test in the coap_new_client_session()
function in test_session.c to fail.

The fix replaces in6addr_any with in6addr_loopback, as in the adjacent
function call. This does not affect the functionality of the test.

As a result, the tests under Windows are completely successful.
2025-10-02 18:12:50 +01:00
raspopov
f61a2efa0c Add CUnit autodetection to CMake
Added a rules file for automatic detection of the CUnit library,
as well as support for running tests directly from CMake.

Updated distribution bundle rule.
It adds FindCUnit.cmake to the EXTRA_DIST rule in the Makefile.am file.

The CUnit tests run perfectly on both Windows and Debian.
2025-10-02 17:55:51 +01:00
raspopov
1c1c9c6910 Fix Doxygen under Windows
The CMakeLists.txt file calls Doxygen and redirects its output to
/dev/null to suppress it. However, for Windows, you need to redirect it
to "NUL:" otherwise, a build error will occur.
2025-10-02 10:59:21 +01:00
Jon Shallow
8f9a73e397 coap-client: Add in support for configuring Proxy-Scheme option 2025-09-29 20:38:06 +01:00
Jon Shallow
c0b532aa1b Compile time ifdef definitions cleanup
For the libcoap COAP_ compile time options configured in coap_defines.h or
coap_config.h make sure that #ifdef, #ifndef or defined() are not used and
replaced with #if as appropriate so that if the COAP_ compile time option
is defined as 0, the correct code gets built.

Add #if wrappers to source files that are platform specific or OSCORE.
2025-09-29 11:10:25 +01:00
Jon Shallow
743dc928d8 LwIP: Support memory management other than Custom Memory Pools 2025-09-27 15:07:01 +01:00
Jon Shallow
32471d1439 coap-rd.c: Sanity check POST query lengths 2025-09-26 12:37:39 +01:00
Jon Shallow
ec125f28c7 coap_openssl.c: Check return values in case internal OpenSSL issue 2025-09-22 13:15:17 +01:00
Jon Shallow
ea6a3c6f53 Platforms: Split out TCP and UDP socket functions on a platform basis
Currently supported types

Posix
LwIP
Contiki
RIOT

Zephyr and Windows are treated as Posix.

UDP
src/coap_dgrm_contiki.c      Datagram r/w/c functions from src/coap_io_contiki.c
src/coap_dgrm_lwip.c         Datagram r/w/c functions from src/coap_io_lwip.c
src/coap_dgrm_posix.c        Datagram r/w/c functions from src/coap_io.c
src/coap_dgrm_riot.c         Datagram r/w/c functions from src/coap_io_riot.c

TCP
src/coap_strm_contiki.c      Stub TCP entries
src/coap_strm_lwip.c         Stream r/w/c functions from src/coap_io_lwip.c
src/coap_strm_posix.c        Was src/coap_tcp.c with stream r/w/c functions from src/coap_io.c
src/coap_strm_riot.c         Stream r/w/c functions from src/coap_io_riot.c

I/O specific
src/coap_io_contiki.c        Datagram / Stream functions removed
src/coap_io_lwip.c           Datagram / Stream functions removed
src/coap_io_posix.c          Abstracted from src/coap_io.c
src/coap_io_riot.c           Datagram / Stream functions removed

Remaining common I/O functions
src/coap_io.c                With separated out code removed
2025-09-22 10:27:14 +01:00
Jon Shallow
c12193fdef coap_uri.c: Fix parsing Unix Domains 2025-09-20 13:53:02 +01:00
Jon Shallow
67dbe5ac36 testdriver: Suppress log Warning when error detecting 2025-09-16 10:45:03 +01:00
Sandro Scherer
9266cafe82 cmake: Add OpenSSL dependency check in configuration
This enables projects having to
only find libcoap in their cmake
and not openssl too.
2025-09-15 10:18:14 +01:00
Jon Shallow
5aee88f186 CI: Fix CI windows-2025 ms-build image build 2025-09-15 09:24:19 +01:00
Jon Shallow
0bd03b658e cmake: Remove the need to configure tests/test_common.h 2025-09-12 13:29:17 +01:00
Jon Shallow
30db3eaa1f coap_address.c: Validate length of provided host name
Host names larger than 255 bytes will cause an internal buffer overflow.

Hostnames provided to coap_resolve_address_info() now have their length validated.

Discovered by SecMate (https://secmate.dev).

Sanity check host lengths when parsing a CoAP URI when using the coap_split_uri()
function.
2025-09-12 13:28:22 +01:00
Jon Shallow
1cae046728 CMakeLists.txt: Remove need for deprecated CMP0115 2025-09-05 16:48:37 +01:00
Jon Shallow
b47c82535c coap_net.c: Include MID check in coap_pdu_cksum() 2025-09-05 16:45:01 +01:00
Jon Shallow
da534de75e OSCORE: Fix OSCORE configuration file parsing issue
With a large boolean parameter value, (longer than "false"), memory
would be read past the "true" or "false" string boundaries in the ".rodata"
section when doing a memcmp(), potetially causing the application to crash
when calling coap_new_oscore_conf() with a specially crafted configuration
file.

It also can provide a mechanism to determine the byte values following the
"true" or "false" string boundaries which could lead to accessing sensitive
information. The standard libcoap library does not have defined keys or
certificates. This can only be done by a specially crafted local application.

Discovered by SecMate (https://secmate.dev).

Now fixed.
2025-09-05 16:16:32 +01:00
Jon Shallow
56a90642d3 coap_session.c Fix CID update check 2025-09-05 16:11:17 +01:00
Jon Shallow
ea01661faf Zephyr: Support C++ builds
Some of the Zephyr include files need to be C++, not C based. The 'extern "C"'
wrapper in include/coap3/coap.h means that all #include are treated as being C.

Remove 'extern "C"' wrapper from include/coap3/coap.h and add wrapper to
include files after #include and before any function / structure definitions.

Add in a C++ build test for CI.
2025-08-21 12:17:41 +01:00
Jon Shallow
7dff177f29 Sockets: Update documentation
Separate out the Datagram (UDP) and Stream (TCP) socket documentation.

Add in a Doxygen Datagram (UDP) topic.
2025-08-18 17:24:36 +01:00
Sandro Scherer
f438c61b6e Zephyr: improve POSIX API integration 2025-07-30 11:38:44 +01:00
Jon Shallow
690e5fa8aa coap_block.c: Stop premature deletion of lg_srcv 2025-07-22 11:23:15 +01:00
fj-blanco
022e848da4 Zephyr: Add wolfSSL DTLS backend support
- Add wolfSSL detection and configuration in zephyr/CMakeLists.txt
- Set wolfSSL to take priority over mbedTLS when both are available
- Bypass find_package() call and link wolfSSL library directly
- Prevent system wolfSSL library conflicts with ZEPHYR_BASE checks
- Fix compiler warnings in coap_wolfssl.c for unused functions
2025-07-21 08:43:13 +01:00
Jon Shallow
79a041414c Zephyr: Enable CI builds
Fix a Zephyr unexpected success response for ioctl FIONBIO.
2025-07-19 12:17:38 +01:00
Jon Shallow
b359512f8d coap_block.c: Fix ETag generation for CoAP responses
If the response code in the PDU was not set before calling
coap_add_data_large_response(), the ETag option was not getting
set.
2025-07-19 12:04:23 +01:00
Jon Shallow
433f483f2c WIN32: Support determining local broadcast addresses 2025-07-12 13:09:26 +01:00
Jon Shallow
c9a162b610 MinGW: Add in more CI workflow builds 2025-07-09 14:55:18 +01:00
Jon Shallow
df0b820d88 coap_threadsafe.c: Support Visual Studio builds
Fix missing external references
2025-07-09 10:54:26 +01:00
Jon Shallow
f62c836ece coap_resource.c: Make dynamic resource handling thread safe
Let libcoap do the necessary multi-thread locking during resource
generation, lookup and deletion.

Supported using a new handler set up by coap_register_dynamic_resource_handler().
2025-07-08 13:37:57 +01:00
Jon Shallow
33b3f02006 coap_session.c: Clean up session close down order 2025-07-07 17:55:46 +01:00
Jon Shallow
6d322e1f1c coap_io.txt.in: Fix some compiler errors when building examples
The variable name of socket creates issues for some compilers.
2025-07-07 17:54:04 +01:00
kkrentz
71d16929dd coap_net: Use platform-independent format specifier 2025-07-03 09:43:37 +01:00
Jon Shallow
d33b7fa571 coap_session.c: Support converting a Client session to a Server session
Server to Client is already supported, this provides the reverse with
coap_session_set_type_server().

Add in call-home support to coap-client and coap-server for testing.

Addition of a new event COAP_EVENT_SERVER_SESSION_CONNECTED.
2025-07-02 17:41:07 +01:00
fj-blanco
4fa3dfa0c7 Zephyr: add POSIX API support
Changes:
- Remove duplicate OBSERVE_PERSIST configuration block

Improve example build:

- Make virtual environment activation optional in Makefile
- Remove --fresh flag unsupported in newer west versions
- Copy mbedTLS config header to workspace include directory
- Add TARGET check for mbedTLS before configuring include directories
- Add mbedTLS linking to coap-3 target

Add POSIX API support:

- Enable CONFIG_POSIX_API=y in examples/zephyr
- Replace direct Linux/Windows system calls with Zephyr POSIX API
equivalents
- Add Zephyr's sys_rand_get() to coap_prng_default()
- Define missing network macros (IN_MULTICAST, IN6_IS_ADDR_MULTICAST,
etc.)
- Add FIONBIO and OPTVAL_T/OPTVAL_GT macro definitions for Zephyr
- Add native Zephyr timing functions to replace missing mbedTLS timing
support
- Fix fd_set mapping using zephyr/net/socket_select.h
- Exclude strnlen redefinition conflicts for Zephyr
- Add proper IPv6 packet info and address mapped definitions

(Patch) Add DNS resolution and net setup to example client:
- Enable CONFIG_DNS_RESOLVER for hostname resolution
- Add Linux networking setup instructions for native_sim board
- Configure static IP gateway and DNS server (8.8.8.8)
- Add DHCP vs static IP configuration documentation
Co-authored-by: mrdeep1
2025-06-26 15:23:23 +01:00
Jon Shallow
cf45e84be2 coap_io.c: Cleanup MinGW builds
Move the MinGW #if tests to after where mswsock.h is included.

Tidy up documentation.

Tested against MSYS2 UCRT64, CLANG64, MINGW32 and MINGW64 on Windows 11.
Fixed a couple of minor build issues found.
2025-06-26 15:17:48 +01:00
Jon Shallow
2dac61cf50 LwIP: Update to STABLE-2_2_1_RELEASE 2025-06-21 12:20:16 +01:00