Commit Graph
465 Commits
Author SHA1 Message Date
Jon Shallow 710a8b5288 coap_io_pending: Add in new function to check if there is any i/o pending
coap_io_pending() checks to see if there are any PDUs pending transmission,
whether there are any large (block) transmissions in progress, whether
there are still expected response packets(client) or expected request
packets(server), and whether the client is expecting further observe
responses.  If any of this is true, then it returns 1, else 0.

coap_io_pending() also invokes coap_io_process() to check that all that can
be transmitted is, as well as processes any impending input packets.

This takes coap_can_exit() a step further who only checks the transmit state.

coap_handle_response_get_block() has been updated to release the current
lg_crcv if all the fragmented body of a large transfer have been received.

Documentation updated.
2022-11-04 14:06:55 +00:00
Jon Shallow 3897d2334c Logging: Make logging consistent across (D)TLS libraries
Set up coap_log_t as an enum, using syslog variable names prefixed by
COAP_.

Add function coap_dtls_log() for logging information from (D)TLS libraries.

Update the log output to have use Lower-case variants for the logging levels to
indicate that output is from the (D)TLS library instead of the CoAP library.

(D)TLS libraries updated to be consistent in the usage of
coap_dtls_set_log_level()/coap_dtls_get_log_level().

Add in coap_log_emerg(), coap_log_alert() etc. as wrappers to reduce the line
length required for log entries.  Updating all the coap_log() functions to
no longer use syslog variants will be a part of a separate PR.

Added in the "-V" option to the examples, with an initial default of
COAP_LOG_ERR, separating out the CoAP and (D)TLS logging levels.

Note: TinyDTLS log output will be consistent when built against a TinyDTLS
version that contains support for an external logging handler.
2022-11-03 16:02:36 +00:00
Jon Shallow 458f2d5702 TinyDTLS: Support build with DTLS_PSK not defined.
As well as adding in the DTLS_PSK wrappers in the appropriate place. add in
coap_dtls_psk_is_supported(), coap_dtls_pki_is_supported(),
coap_dtls_pkcs11_is_supported() and coap_dtls_rpk_is_supported() functions
to support better granularity of what capabilities are available in the
(D)TLS libraries.

Update coap_string_tls_support() to use these new functions.

Uppdated documentation for these new functions.
2022-11-03 09:03:52 +00:00
Jon Shallow 7b39908e82 LwIP: Add in TinyDTLS support
The dtls versions of the server and client are built as
server-dtls and client-dtls.

Add in flexible option support for server and client.  These are
a subset of the coap-server and coap-client options.
2022-10-29 13:26:43 +01:00
Jon Shallow b39e7bb3fc coap_uri: Tidy up documentation 2022-10-26 14:37:41 +01:00
Jon Shallow 972eecf157 LwIP: Fix unused parameter compiler warnings 2022-10-21 20:45:04 +01:00
Jon Shallow 3126102d00 includes: Prefix more header files with coap_ to prevent name clashes
encode.h and str.h are not used in any open PRs and can safely be renamed
with a coap_ prefix.

Order the include lists alphabetically as if all the entries have a coap_
prefix, so when the include file gets renamed with a coap_ prefix, the
include order is not disturbed.

Rename (as these are all internal files) for clarity
coap_mutex.h to   coap_mutex_internal.h
coap_hashkey.h to coap_hashkey_internal.h
uthash.h to       coap_uthash_internal.h
utlist.h to       coap_utlist_internal.h
2022-10-20 17:00:44 +01:00
Nick Miller 312a0561e4 coap_event: Add COAP_EVENT_MSG_RETRANSMITTED
Apart from debug log messages, there is no way for a user to be
notified when a message retransmission happens.

This event can be useful for diagnosing issues related to
lossy networks or unresponsive CoAP servers (e.g. user can
track total retransmissions as an indicator for general link
quality).

Assigned event ID to 0x5002 to avoid creating a new 0x6000
event group, and because it's similar to COAP_EVENT_BAD_PACKET (0x5001).
2022-10-19 16:34:07 +01:00
Jon Shallow c5c4f9bf1d uri.c: Add coap_uri_into_options() function
Simplify code for applications by providing coap_uri_into_options()
which then adds the (optional) port and splits out the path / query
as CoAP options, adding them to the optlist_chain for subsequent use.

Added a new coap_delete_uri() for completeness.

Update documentation to include the uri based functions.

Update examples to use the new coap_uri_into_options() function.
2022-10-12 15:24:02 +01:00
Jon Shallow de1bc9f3cb LwIP: Add in support for client
New demo client app.

Update some of the memory sizes.
New coap_lwip_dump_memory_pools() to dump LwIP memory pool usage.

Add in logic to handle new client sessions.

New coap_io_process() to handle LwIP which can invoke a callback handler
to wait / timeout for the next input handler.
New coap_lwip_set_input_wait_handler() to define this handler.

Update coap_io_prepare_io() to handle LwIP.

Support re-use of pbuf for PDU re-transmissions.

Make sure that NSTART is correctly obeyed.

Build the client with client only libcoap code.

Build the server with server only libcoap code.

Update LwIP source to latest stable release.

Reserve memory for a response PDU.

New coap_lwip(3) man page.

Update directory structures for config files.

Update files contained in "make dist" and check lwip rebuilds
in the github workflows.
2022-09-22 10:14:48 +01:00
Jon Shallow 2f25c950af net.c: Call nack handler for badly formatted response packet
If a response packet is received that is badly formatted, invoke the
nack handler (if defined) with COAP_NACK_BAD_RESPONSE so that the
requestor knows there is an issue, rather than timing out.

However, if the response packet is so badly formatted, or it is not
possible to find the requesting packet, then this nack event will not
trigger, but an event is triggered with COAP_EVENT_BAD_PACKET.
2022-09-20 15:12:29 +02:00
Olaf Bergmann c694baead2 Update version to release 4.3.1 2022-09-02 13:42:24 +02:00
Olaf Bergmann 09aab40d14 Tag release candidate 2 for version 4.3.1 2022-08-23 13:19:08 +02:00
Jon Shallow 4f12b9be1b coap_event.h: Clean up Doxygen documentation for coap_event_t 2022-08-22 14:50:03 +02:00
Jon Shallow 43bfbea924 Copyright: Update dates to 2022 where appropriate 2022-08-18 13:23:36 +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 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 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
Olaf Bergmann 0ca2fd4a90 Tag release candidate 1 for version 4.3.1 2022-07-28 12:23:46 +02:00
Jon Shallow 8fbe440f8a coap_io.c: Updates for esp-idf port 2022-07-27 11:21:28 +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 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 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 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 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 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
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 8b05aa5211 Merge pull request #848 from mrdeep1/bert
BERT: Support block BERT szx of 7 for reliable protocols
2022-06-07 16:07:35 +01:00
Jon Shallow 03a9059439 BERT: Support block BERT szx of 7 for reliable protocols
Add in new coap_block_b_t structure that tracks BERT usage, and
use new functions coap_*block_b_* that are in addition to the old
coap_*block_* functions that use coap_block_b_t.
2022-05-31 19:45:29 +01:00
Jon Shallow 445a9481de RFC7390: Update support for RFC7390
Update documentation and add in missing content-format.
2022-05-26 21:10:29 +01:00
Jon Shallow 21fd838dc7 coap_io_prepare_io: Re-order function code for correctly updating sockets[]
Two cases for not updating active sockets[] with file descriptors from a
session (non epoll code)
  coap_retransmit() can release a session
  coap_dtls_handle_timeout() can disconnect a session

Move the restransmit test code to before any updates to socket[].

Update coap_dtls_handle_timeout() to return a value indicating a DTLS timeout
has occurred.  At the same time move the coap_dtls_handle_timeout() checks
into the first sessions iteration loop, removing having to iterate through the
sessions twice if DTLS.
2022-05-20 11:10:32 +01:00
obgm abbe3edd5a Merge pull request #795 from mrdeep1/async_fix
async: Handle changes to delay when using epoll
2022-05-06 14:47:39 +02:00
Jon Shallow 069a0786ce CSM: Support different XMT and RCV Max-Message-Size
Track the RCV mtu size separately from the XMT mtu, so that sufficiently
large PDUs can be built for receiving incoming data.

Wait until reliable session is complete and the initial CSM have been exchanged
before building any new PDUs for transmission so that they can hold the
appropriate amount of Max-Message-Size data.

Add in support into coap-server and coap-client for defining the
Max-Message-Size to use by adding in 2 new functions
coap_context_set_csm_max_message_size() and
coap_context_get_csm_max_message_size().

Add in flexibility into coap-server to control the initial example_data size.

Requires #844 to prevent recursive mutex locking when initiating proxy ongoing
session to upstream server.
2022-05-04 10:01:37 +01:00
Hugo Hakim Damer d9c19c378f event.h: Add events for server session state management
This commit adds two new events (`COAP_EVENT_SERVER_SESSION_NEW`
and `COAP_EVENT_SERVER_SESSION_DEL`), which are triggered when the
IO loop creates or deletes server-side sessions.
2022-04-29 09:18:51 +02:00
Jon Shallow aa391b5b76 async: Handle changes to delay when using epoll
Add in new function coap_async_trigger() to immediately release an async
session, rather than using coap_async_set_delay(async, 1).

Add new internal function coap_update_epoll_timer() to reduce code
duplication and use it for the async logic.

Move doing coap_io_prepare_epoll() for every epoll event to just doing it once
outside of the loop.

Update documentation.
2022-04-07 13:14:49 +01:00
Olaf Bergmann eb7656850f pdu.h: Add Content-Format for application/ace+cbor
RFC 9200 defines the new media type application/ace+cbor for
Authentication and Authorization in Constrained Environments.  The
CoAP Content-Format value for this media type is registered as value
19.
2022-03-15 13:01:04 +01:00
Jon Shallow dfc678c33b Proxy: Support unknown Critical but Safe-To-Forward options
The CoAP Proxy may not know how to handle a Critical option, but if it
is safe to forward it should be able to handle this.

RFRC7252 5.4.1
   Critical/elective rules apply to non-proxying endpoints.  A proxy
   processes options based on Unsafe/Safe-to-Forward classes as defined
   in Section 5.7.

If this is an incoming proxy type request special case any
critical options that are safe to forward.

Track ongoing sessions from an enabled proxy server so unknown critical
response options can be passed back to the originating requestor.

Update coap-server to handle Proxy-Scheme for proxying.

Update tests to use critical option 25 instead of 9.
2022-02-18 12:51:35 +00:00
Jon Shallow 756bb04239 pdu building: Enforce the application order of building a PDU
Make coap_add_option() invalid after calling a coap_add_data*() function.
Add in internal support for adding options to PDUs that contain data with
a replacement coap_add_option_internal() function.  Call this new function
in the appropriate places in the libcoap src.

Add coap_log warnings when the application tries to build a PDU in the wrong
order and then return failure.

Update documentation re-inforcing the PDU building order.
2022-02-08 14:14:51 +00:00
obgm 1fceff7cc3 Merge pull request #814 from mrdeep1/build_version
versioning: Make current git describe available
2022-02-07 14:38:34 +01:00
Jon Shallow a8c00f2af9 coap_pdu_setup.txt.in: Better document coap_encode_var_safe8()
Document return value can be 0 for both being valid and returning on error.
Same is true for coap_encode_var_safe().

[Error should assert() by default]
2022-02-02 21:37:54 +00:00