Commit Graph
3018 Commits
Author SHA1 Message Date
Jon Shallow d0bfbb7ac8 client code: Make sure static variables are re-initialized if needed
For embedded applications that can call the 'main()' function multiple
times, they  need to have any statically (globally) defined variables
reset to their default values.
2025-03-21 10:14:03 +00:00
Jon Shallow 0de22aae0b Trust Certs: Load in the PKI trust store for peer cert checking
Load in the PKI trust store with a new function
  coap_context_load_pki_trust_store()

By default, make the client and server applications do this unless
explicitely disabled.

This enables clients doing (D)TLS to not need to be provided with specific
certificates but can validate trust in the server provided certificates.

Note: A default trust store is not supported across all platform types or
some TLS libraries (version dependent).
2025-03-21 09:18:46 +00:00
Jon Shallow 9271b692ab coap_io.c: Do not report ENOSYS errors for setsockopt(IPV6_V6ONLY) 2025-03-20 11:42:35 +00:00
Jon Shallow cce7b65398 Threads: Support multiple threads doing coap_io_process()
Set up a coap_io_process() loop spread across multiple threads, each thread
repeatably calling coap_io_process() and so able to handle any input packets.

Note that the application handlers need to be thread-safe for application
level activity.

Add 2 new main functions
  coap_io_process_loop()
  coap_io_process_terminate_loop()

Add in 2 new sub functions
  coap_io_process_configure_threads()
  coap_io_process_remove_threads()
to set up the parallel threads.

Update example servers to include using coap_io_process_loop().

Support optional thread number logging by configuration to maintain
backwards logging format output if required.
2025-03-19 09:18:35 +00:00
Jon Shallow 0ba446d788 App Data: Provide new set of storing app data in various structures
New functions
 coap_async_set_app_data2()
 coap_cache_set_app_data2()
 coap_context_set_app_data2()
 coap_session_set_app_data2()
that, multi-thread safe, store an application data pointer and return the
previous data pointer (if any). There is an optional callback that will
be called when the respective storage object is released that can free
off as appropriate the data that was stored.

These replace the existing coap_*_set_app_data() functions and
coap_*_get_app_data() can be used to get the stored data pointer.
2025-03-18 16:57:52 +00:00
Jon Shallow 440b645a15 coap_openssl.c: Clear thread errors before doing read/write for TLS
When using multi-threads, if a thread does i/o, but previously that thread had
an SSL error which has not been properly cleared, then the read or write will fail
with SSL_ERROR_SSL.

Make sure that there are no errors before doing SSL_read() or SSL_write().
2025-03-14 11:13:11 +00:00
Jon Shallow 205f52fe24 Separate Responses: Fix missing con_active decrement
New function coap_remove_from_queue_token() in #1600 was missing doing
con_active decrements.
2025-03-14 10:59:22 +00:00
Jon Shallow a746e3f40c Separate Responses: Fix CON arriving before ACK and using Block
Fixes a "large body receive internal issue" issue.
2025-03-12 12:41:01 +00:00
Mario Kicherer 45006ae031 coap_io: do not call select() for contexts without sockets on Windows 2025-03-12 10:56:15 +00:00
Mario Kicherer c3b4be2aab fix coap_socket_strerror() on Windows 2025-03-11 15:47:20 +00:00
Jon Shallow 4c7ce99e09 Async: Report async delayed PDU when request handler is re-invoked 2025-02-21 14:34:02 +00:00
Peter Harper b9526c7ae0 coap_threadsafe_internal.h: Fix coap_lock_invert.
This code fails to compile if COAP_THREAD_SAFE is false as the macro
parameter is "alt_lock" not "func".
2025-02-21 08:50:42 +00:00
Jon Shallow c4d933a969 Proxy: Update documentation, streamline the code
Tidy up naming to reduce confusion between supported proxy types.

Provides simpler proxy examples.

Fixes issue with COAP_PROXY_REVERSE_STRIP.

Support upstream server using AF_UNIX.
2025-02-20 10:12:05 +00:00
Jon Shallow 4289cb072d Copyright: Update to 2025 where appropriate 2025-02-17 09:37:55 +00:00
Jon Shallow a51fa3b77d Server Keepalive: Timeout sessions observing Unknown or Proxy resources
In general, the Unknown or Proxy resources should not be set as observable.
2025-02-17 09:32:14 +00:00
Jon Shallow 18274073da Proxy Support: Update documentation 2025-02-13 19:36:53 +00:00
Jon Shallow 60fbbd3e3b KeepAlive: Better session cleanup after KeepAlive failure 2025-02-13 12:53:32 +00:00
Jon Shallow 238694fe1a Block1: Only save all data if Observe request for subsequent re-registration 2025-02-13 11:22:05 +00:00
kkrentz cea3dd449b Contiki-NG: Replace u_char with uint8_t to fix compilation errors 2025-02-13 10:23:42 +00:00
Jon Shallow 0b41ee0511 cache_response: Cache the latest response to a CON request
If the ACK (not empty) response gets lost, the repeated CON request will just
get the cached response without invoking further analysis.

This stops things like OSCORE reporting retry issues.

This functionality needs to be enabled by setting the COAP_BLOCK_CACHE_RESPONSE
bit when calling coap_context_set_block_mode().  If not enabled, then, for OSCORE
the response is sent as a separate response (empty ACK followed by CON response),
which is how code previous to this PR works.
2025-02-03 08:51:31 +00:00
Jon Shallow 38c8ba5790 coap_send_internal: Update parameters
Preparatory work for supporting caching responses by updating
coap_send_internal() parameters.
2025-01-29 09:50:12 +00:00
Jon Shallow 895b0dfd9f CIFuzz: Make sure libcoap is running when calling coap_delete_pdu() 2025-01-28 17:12:37 +00:00
Jon Shallow ba09d0f643 coap_delete_pdu: Add in multi-threaded lock protection
The reference counter needs to be protected.
2025-01-28 15:23:19 +00:00
Jon Shallow 109842b833 Proxy: Fix memory leaks in proxy logic 2025-01-14 15:58:15 +00:00
Jon Shallow 21c70295d7 mcast: Support specifying output interface for IPv6 multicast packets
Specify the interface or scope_id in the IP address as a %suffix.

For example:-

examples/coap-client -N coap://[ff02::fd%interface]
2025-01-14 15:57:06 +00:00
Jon Shallow 4d84859620 keepalive: Add in server keepalive support
If coap_context_set_keepalive() is set in the server, CoAP keepalive packets
will get sent for any CoAP session that is curently observing a resource.

If the keepalive times out, then the observation(s) are canceled and the
server session is deleted.
2025-01-10 10:44:20 +00:00
Jon Shallow 080da9a843 coap_block.c: Handle missing Size1 option when using Block1 2025-01-09 15:42:09 +00:00
Jon Shallow ea86105178 coap_io.c: Fix compiler warnings that socket() is redefined
Seems some compliers do not like socket being a variable name.
2025-01-08 17:17:38 +00:00
Jon Shallow bd2c2b04f8 DTLS: Correctly log sending plain data size when using DTLS 2025-01-06 15:01:39 +00:00
Jon Shallow 75b4322b0f coap_net.c: Remove un-needed coap_remove_from_queue() call
Genuine separately initiated CON messages could be deleted if incoming
NON message has same MID.
2025-01-06 10:12:12 +00:00
kkrentz 72190a8854 coap_subscribe_internal.h: Fix "unbalanced grouping commands" 2024-12-19 16:27:07 +00:00
Jon Shallow b7eee795b3 coap_socket_strerror: For Windows, return ascii readable 2024-12-18 14:12:21 +00:00
Jon Shallow a87fb0c1cf coap_io.c: Add in support for getting state of internal file descriptors
Add in a new function coap_io_get_fds() to get the lists of (internal
to libcoap) file descriptors that are in a read or write pending state,
as well as the timeout time for the next internal to libcoap activity
(e.g. packet retransmission).
2024-12-18 14:09:48 +00:00
Hugo Hakim Damer 32c124f7d5 doc: fix invisible text if browser is set to prefer dark mode 2024-12-16 17:01:53 +00:00
Mario Kicherer ebb8f07796 add helper functions to support external event loops, see #1554 2024-12-13 14:11:01 +00:00
Jon Shallow d82f857f67 LwIP: Support client sending multicast / broadcast (IPv4) packets 2024-12-05 13:36:01 +00:00
Jon Shallow ae162903ab LwIP: Support Server Multicast registration 2024-12-05 13:05:48 +00:00
Jon Shallow 7ad6579121 coap_uri.c: Fix sending Uri-Host option
Ipv6 Hosts with %interface suffix were incorrectly getting sent
with a Uri-Host option which included the &interface as well.
2024-12-05 13:03:53 +00:00
Jon Shallow 6036e7a329 LwIP: Support DTLS if CID is enabled n TinyDTLS 2024-12-02 16:21:00 +00:00
Jon Shallow 5f4c2ab96b coap_block.c: Fix returning 2.03 for ETag match
Tag server returned data with a digest computed ETag option value so
requests with an ETag option can return 2.03 if there is a match.

The size of bytes hash that is computed for the ETag can be overwritten by
localy defining COAP_ETAG_MAX_BYTES to be a value between 1 and 8 bytes
inclusive.  It is set to 4 by default.
2024-12-02 10:15:51 +00:00
Jon Shallow 3457c2e2fd Zephyr: Track memory allocations 2024-12-02 10:04:23 +00:00
Jon Shallow 9b0ec2dae0 coap_send_internal: Log OSCORE failed PDU 2024-11-23 13:11:12 +00:00
Jon Shallow 4c6ab62e9d coap_digest_free: Handle NULL pointer 2024-11-23 12:16:27 +00:00
Jon Shallow 1d465b6bde coap_net.c: Fix TCP boundary read condition
Increment session->partial_read correctly.
2024-11-23 12:06:35 +00:00
Jon Shallow 19cef11d04 CMakeLists.txt: Fix include check order for TinyDTLS
Search built include files before libcoap general include files.
2024-11-02 10:39:38 +00:00
Jon Shallow 0808b97009 coap_net.c: New coap_send_recv() function
Supports sending a PDU and waiting for the response PDU for subsequent analysis.

Handles multiple block transfers.
2024-11-01 15:27:22 +00:00
Adrian Freihofer abfe2a3c6c CMakeLists.txt: remove vendored tinydtls build path
Do not write the absolute build path into libcoapTargets.cmake. The
libcoapTargets.cmake is supposed to be packaged and installed by
distros. An absolute path referring to the build directory looks
therefore wrong.
Some build frameworks like Yocto have quality assurance check which
handle these issues as a warning or as an error. Example:

WARNING: libcoap-4.3.4-r0 do_package_qa: QA Issue:
  File /usr/lib/cmake/libcoap/libcoapTargets.cmake in package
  libcoap-dev contains reference to TMPDIR [buildpaths]

Declaring this header files as build interface looks like the right fix.
In case of a bundled tinytls library the header files should be handled
like the header files from libcoap itself: Either in the build folder of
libcoap or in /usr/include as declared one line above.
2024-11-01 15:26:47 +00:00
Jon Shallow 466f1e0b5c coap_oscore.c: Process queued OSCORE Observe responses after de-registration
If an Observe is de-registered, but an unsolicited Observe response is received
before the de-register response is received, then the unsolicited response
failed to get decrypted.
2024-10-28 14:33:34 +00:00
Jon Shallow 92b3db23e9 NACK handling: simplify libcoap code
Remove a lot of code duplication by providing new coap_handle_nack()
function.
2024-10-19 11:58:19 +01:00
Jon Shallow 7f14e0a637 coap_mbedtls.c: Breakout of permanent loop for (D)TLS setup
Stop MbedTLS continuing to try to establish a (D)TLS session where the
server keeps on sending back a Server-Hello when it fails to decrypt
a client handhake (i.e. mismatch on PSK).
2024-10-18 13:47:11 +01:00