Commit Graph
708 Commits
Author SHA1 Message Date
Magdalena Szumny f79eaba9b9 Add sorting of optlist 2026-02-16 10:34:48 +00:00
Jon Shallow 152f6a8a58 Includes: Remove unnecessary include files
Include common system header files in coap_internal.h based on HAVE_*H
definitions.

Remove these system header files from include/*/*.h.

Add in system header files where appropriate in various apps.
2026-02-02 10:09:17 +00:00
Jon Shallow c9a4b716c4 binary/strings: Check for size overflows when allocating
Includes a check in coap_block_build_body().
2026-02-02 09:52:55 +00:00
Jon Shallow 07c7a7aa57 body_size: Support configuration of max supported body size for RFC7959
Function coap_context_set_max_body_size() added.

For servers, if body size is too large, a 4.13 response is generated.

For clients, if the body size is too large, the server gets a RST and
no date is passed to the application.  A new event COAP_EVENT_BLOCK_ISSUE
is generated.
2026-01-29 09:53:52 +00:00
Jon Shallow 37334b120f Proxy: Add in support for previously set up upstream servers
Add in new coap_proxy_fwd_add_client_session() function to define the
upstream servers from previously set up sessions (i.e. from call-home).
2026-01-21 15:23:48 +00:00
Jon Shallow d80fa1497d Client: Remove (D)TLS / WebSocket startup call-back timing window
Add in new functions
  coap_new_client_session3()
  coap_new_client_session_pki3()
  coap_new_client_session_psk3()
  coap_new_client_session_oscore3()
  coap_new_client_session_oscore_pki3()
  coap_new_client_session_oscore_psk3()
which effectively does coap_session_set_app_data2() and
coap_ws_set_host_request() early on in the session set up cycle.
2026-01-08 17:51:10 +00:00
Jon Shallow c9135b6b26 Copyright: Update to 2026 2026-01-05 10:37:26 +00:00
Jon Shallow 08ae1a7c08 Multi-threading: Correctly lock all callbacks
Make sure all application callbacks are called with a coap_lock_callback*()
wrapper.

Rename callback variables within the internal structures with a _cb suffix for
ease of review.
2025-12-30 11:07:37 +00:00
Jon Shallow 6b33d18735 Doc: Fix typos 2025-12-27 11:57:19 +00:00
Jon Shallow 19f1d78848 coap_send: Do not block on first send when testing for additional support
The first coap_send(pdu) is held back until after the optional tests for
Extended Token or Q-Block support are complete with the return from coap_send()
containing the held back pdu's mid.

If there are any errors with this PDU when subsequentially sent, the
event COAP_EVENT_FIRST_PDU_FAIL gets raised.
2025-12-19 17:03:33 +00:00
Mario Kicherer 43bb86df92 coap_io_process_with_fds_lkd: use local fd_set to avoid conflicts when called in parallel for the same context 2025-12-19 14:30:50 +00:00
Jon Shallow 2c41299b4b size_t %zu format: Support compilers that do not support printf %zu
PRIdS or PRIuS need to be defined for a format specification that compilers /
libraries (e.g. nano) understand rather than the default of %zd and %zu.
2025-12-17 15:30:48 +00:00
Jon Shallow 5567e83dfd coap_mutex_internal.h: Fix typo in coap_thread_pid_t definition 2025-12-15 12:00:23 +00:00
Jon Shallow 5a5330d2be RIOT: Update code version and documentation 2025-12-13 18:07:25 +00:00
Jon Shallow 18bb1ff114 Call-Home: Fix Call-Home reconnecting should remote Client fail 2025-12-11 22:25:32 +00:00
Jon Shallow 0eff6a4ed7 FreeRTOS/LwIP: Support getting thread_id for locking 2025-12-09 10:16:16 +00:00
Jon Shallow f64d16919f multi-threading: Fix no_recursive_check issue 2025-12-06 10:01:58 +00:00
Jon Shallow 9f6e671894 Block Transfer: Support constrained memory clients
Add in new function coap_add_data_large_request_app() that provides a call-back
to get individual blocks rather than having a large buffer held in
(contrained) memory.
2025-12-04 14:42:18 +00:00
Jon Shallow aef27f2e68 coap_proxy.c: Support enabling multicast forwarding requests
Missed pushing a commit.
2025-11-20 17:01:20 +00:00
Jon Shallow 7039c70100 coap_proxy.c: Support enabling multicast forwarding requests
Now configurable, previously the multicast request was just forwarded.
2025-11-20 16:47:51 +00:00
Jon Shallow 763330cb61 LwIP: Fix locking for FreeRTOS environments
Handle recursive locking of LOCK_TCPIP_CORE().

Updated support for IPv4 only environments.
2025-11-20 12:33:24 +00:00
Jon Shallow 49668640a0 coap_session.c: Fix GCC array bounds warning for memcpy
Note assert() added from #1209 has now been removed as not needed by #1628,
and if NDEBUG is defined then the assert() would have been a noop anyway.
2025-10-24 09:56:54 +01:00
Jon Shallow e13dfda905 coap_block.c: Do not timeout lg_srcv if server app request handler is slow 2025-10-20 09:34:08 +01:00
Tobias Tefke 698b897570 coap_encode.h: Check BSD is defined before evaluating it 2025-10-20 09:33:54 +01:00
Tobias Tefke d437d9cabd coap_dgrm_internal.h, coap_subscribe_internal.h: Fix extern C guards 2025-10-20 09:33:20 +01:00
Mario Kicherer 673b2184ce add block data handler for single body block transmissions 2025-10-17 11:36:25 +01:00
Mario Kicherer da1be4b5ca add COAP_BLOCK_FORCE_Q_BLOCK 2025-10-09 16:31:50 +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
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 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 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 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 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 f28f4109ec coap_check_async: Fix async callback timing window
Multiple threads can call coap_check_async() when one of them does a callback
into application space. Only allow one thread to be scanning async_state.
2025-06-20 19:23:02 +01:00
Jon Shallow 06ff7e092b Proxy: Remove proxy subscribe on unsolicited response timeout
Also handle large upstream stream packets being converted to downstream
datagram packets.
2025-06-09 10:25:34 +01:00
Jon Shallow d328fc5330 OSCORE: Handle extended tokens when Echo option is returned for B.1.2 2025-06-03 21:35:56 +01:00
Jon Shallow 358da10706 Proxy: Correctly handle OBSERVE cancellations 2025-05-26 17:04:04 +01:00
Mario Kicherer 0ec5f799f2 add coap_session_get_endpoint, coap_endpoint_get_app_data and coap_endpoint_set_app_data 2025-05-22 08:20:45 +01:00
Jon Shallow ce2057b7a9 Locking: Remove context from a subset of the lock function macros (3 of 3)
Makes reading the code simpler.

Context is no longer used as global_lock is used in the coap_lock_lock() and
coap_lock_unlock() functions.

Part 3 of 3.

Update coap_lock_lock() and coap_lock_unlock() macros and all users.
2025-05-21 16:50:00 +01:00
Jon Shallow 882cd6b735 Locking: Remove context from a subset of the lock function macros (2 of 3)
Makes reading the code simpler.

Context is no longer used as global_lock is used in the coap_lock_lock() and
coap_lock_unlock() functions.

Part 2 of 3.

Update coap_lock_check_locked() and all users.
2025-05-21 15:49:40 +01:00
Jon Shallow ccf53a41af Locking: Remove context from a subset of the lock function macros (1 of 3)
Makes reading the code simpler.

Context is no longer used as global_lock is used in the coap_lock_lock() and
coap_lock_unlock() functions.

Part 1 of 3.

Update coap_lock_callback(), coap_lock_callback_ret(),
coap_lock_callback_release(), coap_lock_callback_ret_release() and
coap_lock_invert() macros and all users.
2025-05-21 14:54:54 +01:00
Jon Shallow 8975c15cd8 coap_resource.c: Fix observe callback timing window
If multiple clients subscribe to the same resource, one of the clients
'goes away', the server will eventually close down the session for that client
which will then remove any subscriptions, iterating through the different
resources.

If this happens at the same time that coap_resource_notify_observers() is called
in another thread, and the GET/FETCH handler is called for a common resource
and in particular for the session that is now going away, on return from the
callback the subscription may no longer exist.  This PR fixes this window.

In addition, if the resource subscriber list is being traversed, then a another
call to coap_notify_observers() for the same resource will not generate a new set
unsolicited observe responses for multi-thread protection.

Update
2025-05-20 15:25:31 +01:00
Jon Shallow 24ec7b19bf RIOT: Fix building RIOT with RIOT's utlist.h change 2025-05-20 11:46:26 +01:00
Jon Shallow 60e9f08e47 LwIP: Fix TCP support 2025-05-16 14:40:52 +01:00
Jon Shallow 07c880b56e coap_pdu.c: Report options with invalid length
Malformed PDUs were responsed to with a RST.  Now request PDUs with invalid
lengths are also reported with a 4.02 response.

See RFC7252 5.4.3 and 5.4.1.
2025-05-16 10:01:11 +01:00
Jon Shallow c816bf7fcf coap_net.c: Add Reserved options RFC7252 Table 7 to option check list
The checking can be overriden by using coap_register_option().

Updated the diagnostic payload for 4.02 responses to be inline with RFC 7252,
and not include the actual errant options in the response.
2025-05-15 09:51:56 +01:00