Commit Graph
3057 Commits
Author SHA1 Message Date
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
Jon Shallow f91a7fab31 coap_io.c: Do not trigger a ping heartbeat if active CON 2025-04-14 10:07:14 +01:00
Jon Shallow 72691daec2 coap_pdu.c: Support incrementing reference count on const coap_pdu_t parameters
const coap_pdu_t * parameters are passed into application (call-back handler)
code.  If the application code then calls a libcoap API with a
const coap_pdu_t * parameter, it is not possible to increment the reference
counter so that multiple entities can reference the same PDU and an entity's
call to coap_delete_pdu() does not prematurely remove the PDU until all the
entities have finished.

This code allows the (const) PDU's reference counter to be incremented.
2025-04-11 16:26:44 +01:00
Jon Shallow 84778a7bb4 Proxy: Provide support for a proxy to create a client session
Add in functions
 coap_new_client_session_proxy()
 coap_register_proxy_response_handler()
2025-04-04 11:35:23 +01:00
Jon Shallow 39956aa9a6 coap_session.c: Tidy up coap_new_endpoint()
Remove unnecessary assert() and return NULL on failure.
2025-04-03 11:15:49 +01:00
Jon Shallow 499341c4f6 Proxy: Make upstream server handling more rigorous
Allow re-establishment with upstream server when server restarts.

When upstream server re-connects, re-establish any (D)TLS sessions
and active observe subscriptions.

Supported by a new function coap_context_set_session_reconnect_time().
2025-04-03 08:30:57 +01:00
Jon Shallow 1ba3158db8 Observe: Make sending observe failed messages optional
When a server cleanly closes down (calls coap_free_context()), when
a resource gets deleted, a 4.04 message is sent out (not when using
coap_persist(3)) for any active observe subscriptions. If a server knows it is
going to be restarted, then there is no need to send out a observe failed message.

When deleting a resource when normally running, it is correct to send out a 4.04
Not Found response as the resource has genuinely gone away.  However, when the
server is cleaning shutting down, it is better to use 5.03 Service Unavailable to
indicate the situation may be temporary.
2025-03-28 12:25:05 +00:00
Jon Shallow d38e177af1 Proxy: Remove unused proxy entries when they time out.
Add a common cleanup function to make sure all information is correctly
freed off.

Make sure that there is client session stickability to use the same proxy entry
when making new requests.
2025-03-27 08:57:37 +00:00
Mario Kicherer 4d2ceb6dbb coap-client: let observe duration override the default wait timeout 2025-03-26 15:06:36 +00:00
Jon Shallow 6f4c8b68de coap_proxy.c: Correct returning responses match
Correctly match proxy_entry against session when checking unpstream response
when there are multiple proxy entries.
2025-03-26 09:51:11 +00:00
Jon Shallow 742eeff3ce coap_proxy.c: Make client AF_UNIX filename unique 2025-03-26 09:33:36 +00:00
Jon Shallow 06fcc92a43 coap_resopurce.c: coap_notify_observers() incorrectly setting observe_pending
Fixes issue introduced in #1616.
2025-03-25 16:59:53 +00:00
Jon Shallow df95d5bcc3 Proxy: Ignore idle timeout if observe subscription on session
Ignore the idle_timeout_secs parameter for a server if there is one
or more active observe subscriptions for the server session.
2025-03-24 16:17:14 +00:00
Jon Shallow b2cbc7057a coap_resource.c: Do not immediately retry sending unsolicited response
If coap_send() returns COAP_INVALID_MID, or other internal issue found in
coap_notify_observers(), when sending an unsolicited response, do not flag
to send again as soon as possible.
2025-03-24 16:06:35 +00:00
Jon Shallow 8ff334d756 coap_address.c: Check for AF_UNIX in coap_address_equals() 2025-03-24 15:31:05 +00:00
Jon Shallow 29410f1f96 coap_subscribe.c: Catch persist restart errors
Report on endpoint mismatches and make sure memory is freed off
if adding observe entry errors.
2025-03-24 15:06:01 +00:00
Jon Shallow 64d5eab74c coap_net.c: Fix coap_check_send_need_lg_crcv() for requests only
A proxy returning a response could unnecessarily create a lg_crcv.
2025-03-24 14:50:58 +00:00
Jon Shallow 01264107f4 coap_io.c: Rate limit ping retries
If coap_session_send_ping_lkd() fails with COAP_INVALID_MID, rate limit
retries.
2025-03-24 11:50:37 +00:00
Jon Shallow ff50974043 coap_block.c: Correct actual_token in coap_block_new_lg_crcv()
It could point to a pdu that is freed off, rather than the saved PDU
information.
2025-03-24 10:08:36 +00:00
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