Commit Graph
2473 Commits
Author SHA1 Message Date
Jon Shallow 37731524a0 RFC8516: Document support 2022-08-18 13:22:18 +01:00
Jon Shallow a7b2f2b490 block.c: Timeout coap_lg_crcv_t structures correctly
Track usage and timeout after COAP_MAX_TRANSMIT_WAIT seconds if
not everything has been received.
2022-08-15 08:22:14 +01:00
Jon Shallow f4507e6e9a Block: Report event on large xmit failures
Add in new event COAP_EVENT_XMIT_BLOCK_FAIL which gets triggered on
detecting transmission failure of large body using BlockX.

Track the last time a lg_xmit was sent, so it can be timed out on failure.

Correctly track the next lg_xmit timeout time (and lg_crcv, lg_srcv) so that
the lg_xmit can be expired.
2022-08-13 14:28:38 +01:00
Jon Shallow 3d387a5be4 block.c: Correct size of allocated PDU buffer
Fix potential buffer overrun corruptions.
2022-08-13 14:19:58 +01:00
Jon Shallow 6a9a787503 Observe: Clean up server timing out after observe failures
Support for larger COAP_OBS_MAX_NON and COAP_OBS_MAX_FAIL definitions.

Change default for COAP_OBS_MAX_FAIL to 1 as there will already have
been MAX_RETRANSMIT(4) of the notification over a period of 93 seconds if
defaults are used.

Code and documentation clean up
2022-08-10 11:54:09 +01:00
Jon Shallow 725e464421 mcast: Tidy up logging
Simplify code and clearly log that this is mcast delays as appropriate.
2022-08-08 16:55:04 +01:00
Jon Shallow 381ff3d94d PDU Data: Clean up internal usage of PDU data
Replace usage of hdr_size with max_hdr_size as appropriate as hdr_size
is not set until PDU is encoded. This should eliminate potential buffer
overruns.

Better checks for available space for the payload when using BlockX.

Clarify documentation.
2022-08-08 14:50:09 +01:00
Jon Shallow 0f0cac71f5 Observe: Support disabling observe cancellation on session close
Add in a new function coap_session_set_no_observe_cancel() to support this.
2022-08-08 10:19:38 +01:00
Jon Shallow bc4c75060b coap_mbedtls.c: Fix output type of a log message 2022-08-08 10:16:32 +01:00
Jon Shallow b8f01cef06 net.c: Move variable into correct block
It was possible to jump to skip_handler with added_block uninitialized.
(Found by valgrind.)
2022-08-08 10:15:15 +01:00
Jon Shallow 58a8b33804 net.c: Send appropriate delayqueue entries in coap_cancel_all_messages()
If coap_cancel_all_messages() is called because of missing separate ACK,
then release any pending delayqueue entries if message is CON.

Remove duplicate code in coap_cancel_all_messages().
2022-08-08 10:13:50 +01:00
Jon Shallow b4306bb791 observe: Make sure the correct token in used for cancellation
Use the Token used for the initial Observe response, not any
interim stateful tokens used for Block handling.
2022-08-08 10:11:43 +01:00
Jon Shallow c68d1e9fe7 mutex: Do not output mutex warnings for LwIP and Contiki
Both LwIP and Contike are single threaded at present, so no need for
stub mutex function warnings
2022-08-04 13:58:22 +01:00
Laukik Hase 7f551fcea5 coap_mbedtls.c: Upgrade to mbedTLS v3.2.1
- Updated the deprecated APIs with the respective alternatives
  - `mbedtls_ssl_conf_min_version` => `mbedtls_ssl_conf_min_tls_version`
- Updated fields for `mbedtls_ssl_ciphersuite_t`
  - `max_major_version`/`max_minor_version` => `max_tls_version`
- Added macros for backward compatibility
2022-08-04 13:56:36 +01:00
Jon Shallow 8c15b896ef esp-idf: Stop -Wformat errors for uint32_t variables
See https://github.com/espressif/idf-extra-components/pull/76
2022-08-04 13:55:16 +01:00
Olaf Bergmann 0ca2fd4a90 Tag release candidate 1 for version 4.3.1 v4.3.1-rc1 2022-07-28 12:23:46 +02:00
Olaf Bergmann 9962bab56f Updated tinydtls to current develop HEAD 2022-07-28 12:23:14 +02:00
Jon Shallow 8fbe440f8a coap_io.c: Updates for esp-idf port 2022-07-27 11:21:28 +01:00
Jon Shallow d2306569d1 proxy: Make proxy requests separate responses
As an incoming proxy request may delay its response (e.g. initiate an
ongoing connection), send back empty ACK immediately so that the
client does not timeout and re-transmit the request.

Do not process duplicated (i.e. re-transmitted) proxy requests.

Correct a couple of typos in example proxy code.
2022-07-25 12:47:18 +02:00
Jon Shallow 98ecf5a2a1 tinydtls: Update submodule to latest version 2022-07-23 12:36:25 +01:00
Jon Shallow 8c973a454e mid_duplicates: Drop general responses duplicates 2022-07-08 15:59:13 +01:00
Jon Shallow dc92fe5e1e coap.h.windows.in: Fix missing file renames 2022-07-01 13:29:06 +01:00
Jon Shallow 347270b9ab file naming: Rename files to have coap_ prefix
Initial update - rename files that are not subject to any PRs.
2022-07-01 11:36:26 +01:00
Jon Shallow 8b9377ef2a coap_mbedtls.c: Fix memory leak 2022-06-27 14:00:24 +02:00
Jon Shallow e8052b3988 resource.c: Further fix making subscribers iteration safe 2022-06-27 13:19:18 +02:00
Jon Shallow f93b9a3e37 coap_mbedtls.c: Catch connection reset in coap_tls_write 2022-06-24 18:15:02 +02:00
Jon Shallow d5bcb8159b resource.c: Make subscribers iteration safe in coap_notify_observers
When sending an unsolicited Observe message, this may trigger a
session disconnection which can remove a subscription.
2022-06-24 18:09:59 +02:00
Jon Shallow 0d9f2531e5 coap_session.c: Free off session's last_token on session deletion 2022-06-24 09:42:11 +02:00
Jon Shallow 415fbdb7cd RFC9175: Add in support for the Echo and Request-Tag options
A unique Request-Tag is added to any PUT/POST/FETCH request that contains
a large body.  The server is then able to differentiate between concurrent
sending of large data using the same session.

If a server responds with a 4.01 and includes an Echo option, then the libcoap
client retransmits the request adding in the received Echo option with the same
value.

If the server responds normally with an Echo option, then the next request
from the libcoap client (internally added by libcoap) will contain that Echo
option.

It is the responsibility of the server application to add in the Echo
option if required and validate the next request unless the Echo is triggered
by OSCORE (RFC8613 Appendix B.1.2).
2022-06-22 15:08:47 +02:00
Jon Shallow 88ae9563e6 mcast support: Support multicast granular to the resource level
Add in new function coap_mcast_per_resource() to enable granularity of
handling multicast requests differently at the resource level.

The granularity is handled by how the flags variable is set up in
coap_resource_init().  These additional flags are ignored if
function coap_mcast_per_resource() has not been invoked.

Added 2 functions coap_resource_unknown_init2() and
coap_resource_proxy_uri_init2() that support defining the mcast flags as
per coap_resource_init().

Responses are now delayed rather than the request being delayed before being
passed to the request handler.

Update coap-server with the -r option to enable multicast on specific
resources.

Do not reset wait_ms in coap-client for Block2 transfers.
2022-06-22 15:08:26 +02:00
Jon Shallow 73565196a8 block.c: Fix error handling with Block transfers
Fix double release of lg_xmit data.

Allow lg_xmit server sessions to timeout.

Check that there is support for adding diagnostic messages for
error returns.

Truncate received data that is larger than the indicated block size
apart from the BERT case.
2022-06-21 15:13:54 +01:00
Jon Shallow 132c726190 net.c: Handle multiple same token request/responses
Sending off multiple CON requests with the same token without waiting for
any responses, causes the first one to be sent with the remainder ending
up in the delayqueue.

On receipt of ACK, coap_remove_from_queue() called in coap_dispatch(),
which returns the MID matching entry that was in the send queue, and then
the next entry on the delayqueue is removed from delayqueue and then sent
which puts the request on the sendqueue for any required re-transmissions.

coap_cancel_all_messages() should not be called in handle_response()
following the logic above if response is type ACK. If
coap_cancel_all_messages() is subsequently called with the same (possibly
empty) token as the next request that is being sent, then the next sendqueue
entry is inadvertantly deleted.

As there is now no sendqueue entry on receipt of the next ACK, the next
delayqueue entry is not sent off.

Only call coap_cancel_all_messages() if response is not of type ACK
(i.e. a separate response).

Report on tokens being the same as the previous one to encourage application
coders to use different tokens.
2022-06-21 14:50:47 +01:00
Jon Shallow d68f5d6f57 net.c: Handle well_known requests when there is no libcoap block support
Fit as much as possible into a single PDU.
2022-06-21 10:28:14 +01:00
Jon Shallow fe51d3335e lwip: Fix minor issues
Increase MEMP_LEN_COAPSTRING to handle example server .wellknown/core request.

If session cannot be generated, check for NULL pointer.
2022-06-21 10:26:40 +01:00
Jon Shallow 6046dcbd55 net.c: Fix broken client only build
Comment out specific server code in coap_start().
2022-06-17 16:42:45 +02:00
Jon Shallow 20f15a17d6 Large Observes: Prevent server sending new response if active response
If the response is large, it can take time to transfer over the body.  If
the server then initiates a new unsolicited response during the existing
transfer, then overflow / retry issues start to occur, compounded if multiple
unsolicited responses are triggerred during an existing transfer.

Hold back the notify of the new unsolicited response(s) until the
existing response has completed (or failed for another reason).

Other code has been tightened up incase the server or client are
not libcoap based and also exhibit this behavior, so to have a better chance
of recovery.
2022-06-17 13:02:45 +02:00
Jon Shallow 5a10ce4890 Congestion Control: add in RFC7252 configuration flexibility
Create where appropriate default values for the Congestion control base
values and update the derived CC values accordingly.

Move derived value #define to coap_session_internal.h.

Update coap_session_t to hold the new CC values.

Update documentation for the new CC functions that update / get the
appropriate values.

NOTE: PROBING_WAIT is not currently checked in the code.
2022-06-17 12:15:19 +02:00
Jon Shallow 41afb92141 net.c: Update .well-known/core handling to use common logic
This removes a lot of code duplication by creating a pseudo resource
for .well-known/core that is not included in the .well-known/core output.
In particular specific Block2 option handling is no longer required.

Updated tests which now include checking that queries work.
2022-06-17 12:12:45 +02:00
Jon Shallow 6b32ed3de2 coap_io.c: Track ICMP Host Administravely Prohibited error
Add in tracking for EHOSTUNREACH in coap_network_read().
2022-06-17 12:00:49 +02:00
Jon Shallow 279755b1df coap_send: Make error checks for coap_send() more rigorous
Always delete PDUs on error before return from coap_send() (aligning with
previous documentation).

Check that the socket is still available before continuing with the PDU
transmission in coap_send().

Update documentation to be clearer on non-usage of PDU on return from
coap_send().

Trap coap_send() errors in coap-client.

Move event handlers setup code to earlier in coap-client to trap events
early on in the CoAP setup process.
2022-06-17 11:34:41 +02:00
Olaf Bergmann 925d39fd8c coap-server.c: Cleanup misplaced comment
Fix comment that has been left at the wrong place by a previous change.
2022-06-17 11:25:08 +02:00
Jon Shallow c771767147 coap_gnutls.c: Handle another error in do_gnutls_handshake()
Treat GNUTLS_E_UNEXPECTED_PACKET as a reason for DTLS closure.

To test, gnutls server and client with different PSK keys and coaps://

GNUTLS_E_UNEXPECTED_PACKET raised if alert sent by server in the
middle of the setup handshaking.
2022-06-17 08:59:00 +02:00
Jon Shallow 801e5492f2 CSM: Move coap_client_delay_first() to later in code processing
Commit 069a0786ce (#833) introduced the concept
of delaying PDU building until the CSM message had been received from server
so that PDUs could be correctly sized.

However, this meant that the functions coap_new_client_session*() would not
complete until the CSM was in for reliable protocols.  Some applications need
the returned session to handle / differentiate between different events.

CSM can update
session->mtu
session->csm_block_supported
session->csm_bert_rem_support

coap_client_delay_first() is now called in coap_add_data_large_request()
and coap_session_max_pdu_size() (not coap_session_max_pdu_rcv_size() as
this is for receiving PDUs).

coap_client_delay_first() has been updated to catch recursive requests as well
as using more of the common code for the LwIP specifics.
2022-06-17 08:49:09 +02:00
mrdeep1 4cad453197 Merge pull request #778 from mrdeep1/coap_io_prepare_io
coap_io_prepare_io: Re-order function code for correctly updating sockets[]
2022-06-14 10:22:06 +01:00
mrdeep1 ee863e4509 Merge pull request #863 from mrdeep1/update_block
block.c: Correctly preset updated_block variable
2022-06-13 16:54:52 +01:00
mrdeep1 f2de7098ce Merge pull request #862 from mrdeep1/white_space_1
async.c: Remove white space
2022-06-13 16:48:19 +01:00
Jon Shallow 346a831cd6 block.c: Correctly preset updated_block variable 2022-06-13 13:42:18 +01:00
Jon Shallow 56db248dab async.c: Remove white space 2022-06-13 13:35:15 +01:00
mrdeep1 df99212fac Merge pull request #850 from mrdeep1/sigpipe
TLS SIGPIPE: Stop programs exiting with code 141 (128 + 13:SIGPIPE)
2022-06-09 10:27:57 +01:00
Jon Shallow 256a758e02 TLS SIGPIPE: Stop programs exiting with code 141 (128 + 13:SIGPIPE)
The example coap-client application was setting the SIGPIPE signal to
SIG_IGN too late.

For applications that do not handle SIGPIPE, set MSG_NOSIGNAL in send() flags
to stop SIGPIPE being generated (but send() still returns EPIPE).

Drop the logging level when a client session cannot be extablished.

Can be reproduced when server requires certificates, but client does not
provide any certificate when using coaps+tcp:// and Mbed TLS.

Window 1
$ coap-server -c server.pem -C ca.pem
Window 2
$ coap-client coaps+tcp://127.0.0.1
$ echo $?
2022-06-09 09:21:14 +01:00