Commit Graph
3086 Commits
Author SHA1 Message Date
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
Jon Shallow 68c3e861ed src/coap_net.c: Make CSM Max-Message-Size handling more generic
Cater for environments like ESP-IDF which use LwIP under the hood.
2025-06-21 11:55:38 +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 e6883c3d67 coap_mbedtls.c: Fix SNI hostname definition if not provided
MbedTLS based PKI clients may report

SSL - Attempt to verify a certificate without an expected hostname.
This is usually insecure.  In TLS clients, when a client authenticates a
server through its certificate, the client normally checks three things: ....

The application provided client_sni may have been removed as per
https://datatracker.ietf.org/doc/html/rfc6066#section-3

   Literal IPv4 and IPv6 addresses are not permitted in "HostName".

and so MbedTLS is now explicitly told that therw is no hostname.
2025-06-20 16:30:52 +01:00
Jon Shallow 7889db616a coap_net.c: Set remote CSM Max Message Size to local max if bigger
Prevent remote endpoint from setting Max Message Size to be larger
than the local endpoint can handle.
2025-06-20 16:10:15 +01:00
Jon Shallow 1b790ea800 coap-server: Sanity check maximum value of server new base time
Check for time overflow in hnd_put_time.
2025-06-18 10:07:58 +01:00
Jon Shallow e5f268fd5d coap_io.c: Support MinGW build with _WIN32_WINNT == 0x0a00 2025-06-17 09:57:27 +01:00
Jon Shallow 17c3feeb08 coap_session_mfree: Check for lg_crcv all cleared out if failure
Call to coap_cancel_observe_lkd() may cause session->lg_crcv to be cleared
out if transmission failure.
2025-06-12 13:55:53 +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 1ed516a2bf MinGW: Fix latest MinGW support build 2025-06-09 10:15:04 +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
@pawel.szwarnowski 67a38770a1 OSCORE: Validate a non-OSCORE response to an OSCORE request 2025-05-27 12:36:49 +01:00
Jon Shallow 358da10706 Proxy: Correctly handle OBSERVE cancellations 2025-05-26 17:04:04 +01:00
Jon Shallow 9f3c1301b8 Proxy: Flush out all proxy requests for proxy entry 2025-05-23 15:50:43 +01:00
Jon Shallow 396dbacfe2 LwIP: Fix locking
In particular for TCP support.

Also added in retrying to get the lwip git 3 times for the CI tests as the
lwip host server is currently not that reliable, returning 502 gateway errors.
2025-05-22 17:06:34 +01:00
Mario Kicherer 8401ff1ffe coap_session.c: fix free callback for endpoint app data 2025-05-22 12:26:44 +01:00
Jon Shallow 3ebb745c91 coap_session.c: Fix coap_lock_lock() issue 2025-05-22 08:41:53 +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 0c18ad5228 coap_net.c: Remove timing window for tcp based session reads
Clear session->partial_pdu before calling coap_dispatch().
2025-05-20 10:53:10 +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
Mario Kicherer 1f3f881656 remove SNI caching for OpenSSL >= 1.1.1 2025-05-16 09:58:58 +01:00
Jon Shallow 551a71572a coap_openssl.c: Fix OpenSSL < 1.1.1 builds 2025-05-16 08:31:39 +01:00
Jon Shallow f7df0ef751 coap_debug.c: Allow compilation with thread-safe not enabled
If COAP_THREAD_NUM_LOGGING was set, but COAP_THREAD_SAFE was not, compilation
errors occurred.
2025-05-16 08:30:22 +01:00
Jon Shallow 9d228feff0 testdriver.c: unit tests failures do not error on exit
Unfortunately tests/testdriver always exited with 0, even if there was a test
suite error.  This meant that CI tests were not picking up any issues.

tests/testdriver now exits with a value of 1 if there is a test suite issue.

Errors corrected in/for the test suite.
2025-05-15 19:22:01 +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
Jon Shallow daa4e05e18 Proxy: Add in support for multiplexing Observe requests
Add in limited caching for multiple clients requesting an Observe subscription
for the same upstream session resource so that only a single observation request
is sent upstream and any unsolicited response is sent back to all the
requesting clients.

This requires a change in the recently added handler registered to
coap_register_proxy_response_handler(), which no longer should no longer call
coap_proxy_forward_response(), but just return a PDU for forwarding on.
2025-05-05 09:46:53 +01:00
Jon Shallow 2e8decf756 Mcast: Support multiple large blocked body responses
When initating a multicast request, multiple unicast responses can occur.

If the unicast response subsequently generates further traffic (in other words
a BLOCK1 or BLOCK2 transfer) to complete the request/response sequence, each
unicast transfer can behave differently.

Set up different coap_lg_crcv_t for each unicast response for the session.

Set up different coap_lg_xmit_t for each unicast request if doing large transmits.

Reference initial transmitted request PDU rather than maintaining copies of the
PDU in coap_lg_crcv_t or coap_lg_xmit_t.
2025-05-05 09:12:30 +01:00
Jon Shallow d03c0d4145 DTLS: Detect connection issues
Supports upstream reconnection attempt detections.
2025-05-05 09:11:20 +01:00
Jon Shallow 97ab322f8d coap-client.c: Adjust wait timeouts based on observe and multicast 2025-05-03 19:24:06 +01:00
Jon Shallow ca103b3610 coap_openssl.c: Fix cert chain usage for OpenSSL >= 3.0.0 2025-04-29 17:40:55 +01:00
Jon Shallow 3afff2dba5 coap_io.c: Correct timeout values when entry has just timed out
If calculated timeout is 0 in coap_io_prepare_io_lkd(), then do not set overall
timeout to 0 so that when passed back to caller it does not get reset to the
caller's max defined timeout.

Updated some timeout check functions to update remaining timeout in a new
parameter and to return 1 if this parameter was updated, else 0. for simplicity.

It was also unsafe to set the initial max timeout value to -1 as coap_tick_t
can be int64_t.
2025-04-22 08:59:27 +01:00
Jon Shallow 04f789b3ce coap_net.c: Fix handling response generated packet failures
Unintended consequence from PR #1627 where additional
coap_session_disconnected_lkd() was called.
2025-04-22 08:57:56 +01:00
Jon Shallow fada39dcba coap_cache.h: Fix documentation @return error 2025-04-14 17:15:56 +01:00
Jon Shallow f97bc19434 Observe: Clarify observing of Unknown or Proxy URIs is not supported 2025-04-14 16:08:25 +01:00
Jon Shallow 17204f488d RIOT: Move examples to new directory structures 2025-04-14 15:55:50 +01:00
Jon Shallow f12b620cde RIOT: Fix examples client issue
Bring the code up to the latest libcoap spec.
2025-04-14 12:34:10 +01:00
Jon Shallow cd06a72916 coap-client.c: Do not report token failures for ping packets in nack handler 2025-04-14 10:08:04 +01:00