Commit Graph
68 Commits
Author SHA1 Message Date
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
Jon Shallow 64e5641017 versioning: Make current git describe available
Add new function coap_package_build() which returns "git describe --tags"
if available at library build time, else standard package version.

The value of "git describe --tags" is created at run time and passed in as
a compiler -D definition.

Update copyright end dates for updated files.
2022-02-02 11:24:52 +00:00
Jon Shallow 74582eddde resource.c: Support deleting resources that have not yet been added
Support deleting a resource both before and after calling
coap_delete_resource().

Make the coap_delete_resource() usage in examples less complex.
2021-12-22 12:59:32 +00:00
obgm c83c7703ed Merge pull request #769 from mrdeep1/handler_doc
handlers: Clarify which handlers are client only, server only or both
2021-12-07 13:04:22 +01:00
Jon Shallow e43cf9369a RFC7959: Handle both client and server initiating requests
Simplify token handling by having a state token for Block1 requests where the
top 16 bits are an incrementing request counter and the bottom 48 bits are the
base token.

Re-order struct coap_lg_crcv_t to reduce data space usage.

Track request method for Block2 requests.

Make coap_add_data_large_internal() a static function.

Make sure that lg_srcv is freed off when all PUT/POST data is in to
prevent next PUT/POST to same resource not getting correctly updated.
2021-11-30 15:53:57 +00:00
Jon Shallow 73389b8192 handlers: Clarify which handlers are client only, server only or both
Add in additional handler coap_register_request_handler() in addition to
coap_register_handler() but now only refer to and use
coap_register_request_handler() to aid readability.
2021-11-05 15:39:22 +00:00
Olaf Bergmann df9071c93e coap_session.[hc]: Added function to retrieve PSK identity from session
The new function coap_session_get_psk_identity() returns the given
session's psk_identity as provided during the handhake (for CoAP server)
or a session setup (for CoAP client).
2021-10-21 09:59:56 +02:00
obgm c190c4960f Merge pull request #732 from mrdeep1/doc_modules
doxygen: Tidy up Modules and Files tab information
2021-10-04 17:17:39 +02:00
Jon Shallow 31722c208a PSK: Make PSK hint / key / identity retrieval simpler
Make the retrieval of  PSK hint / key / identity items simpler, remove
duplicate coding, remove a set of memcpy() and handle all these internally
as coap_bin_const_t.

This removes the need for libcoap internally to allocate (potentially
limited) holding space for these items on the stack.

The respective (D)TLS interface modules then convert these items into
the format required for the underlying (D)TLS libraries.

If the underlying (D)TLS library indicates that there is insufficient
space for an item (defined by a max_len type parameter), then the item
is truncated to that size and a warning issued about the provided item
being too large for the underlying (D)TLS library.

The item access functions are now standalone, not indexed through
coap_context_t.
2021-10-01 17:46:56 +01:00
Jon Shallow d746fc24e5 coap_pdu_parse: Add to public API 2021-09-30 21:41:53 +01:00
Jon Shallow 0aeb0d6247 doxygen: Tidy up Modules and Files tab information
doc/module_api_wrap.h: New

Used to split modules into Application and Internal only.

include/coap/*.h:

Module (@defgroup) description put into group application_api or internal_api
as appropriate.

Add in @file information if missing.

src/*.c

Add in @file information.
2021-09-30 16:59:04 +01:00
Jon Shallow f026f5701e client+server: Reduce code size by building libcoap for client or server only
Add in new ./configure options --enable-client-mode or
--enable-server-mode which by default are enabled.

If --disable-client-mode is set, then disable all the client specific code.
[ COAP_CLIENT_SUPPORT is not defined ]

If --disable-server-mode is set, then disable all the server specific code.
[ COAP_SERVER_SUPPORT is not defined ]

Functions and variables are only #ifdef'd out in the include/coap3/*_internal.h
files.  They cannot be #ifdef'd out in the other include files as
COAP_CLIENT_SUPPORT and COAP_SERVER_SUPPORT are not available for application
compilations. The result of this is if, say, client only API functons are used
in a server application and COAP_CLIENT_SUPPORT is not defined, there will be
linking issues (missing functions).  Providing stub functions unecessarily
increases the code size.

For coap-server, if it is able to provide proxy support, requires both
COAP_SERVER_SUPPORT and COAP_CLIENT_SUPPORT to set up the ongoing sessions.
So, the build environment deliberatly sets SERVER_CAN_PROXY=0 if
COAP_CLIENT_SUPPORT is not available to allow linking.

Some of the tests have to be disabled if COAP_SERVER_SUPPORT or
COAP_CLIENT_SUPPORT is not set.

Code size change indications

   text    data     bss     sum   filename
 155912    1728   12080  169720   libcoap-3-notls.a
 138300    1728   12080  152108   libcoap-3-notls.a --disable-client-mode
 106734    1632   10304  118670   libcoap-3-notls.a --disable-server-mode

 180485    1733   12080  194298   libcoap-3-openssl.a
 160306    1733   12080  174119   libcoap-3-openssl.a --disable-client-mode
 125543    1637   10304  137484   libcoap-3-openssl.a --disable-server-mode

 181755    1728   12080  195563   libcoap-3-gnutls.a
 160972    1728   12080  174780   libcoap-3-gnutls.a --disable-client-mode
 127178    1632   10304  139114   libcoap-3-gnutls.a --disable-server-mode

 165879    1855   12128  179862   libcoap-3-tinydtls.a
 147022    1855   12128  161005   libcoap-3-tinydtls.a --disable-client-mode
 115618    1759   10352  127729   libcoap-3-tinydtls.a --disable-server-mode

 171690    1728   13744  187162   libcoap-3-mbedtls.a
 152099    1728   13712  167539   libcoap-3-mbedtls.a --disable-client-mode
 118786    1632   11984  132402   libcoap-3-mbedtls.a --disable-server-mode
2021-09-30 16:10:52 +01:00
Jon Shallow a7f53b4d6b coap_debug.h: Allow <syslog.h> to be included before and after <coap3/coap.h>
The syslog LOG_ definitions are defined in <syslog.h> and can be defined in
coap_debug.h (wrapped by a HAVE_SYSLOG_H wrapper to prevent duplicaton).

However, the coding order of
  include <coap3/coap.h>
  include <stdio.h
works, but
  include <stdio.h
  include <coap3/coap.h>
but fails if the application build environment does not define HAVE_SYSLOG_H
(as is the case of the examples in the examples/ directory).

The former "just" happens to work as the values of the variables are the same.

This fix is to remove the coap_log_t enum and replace it by simple #define
if LOG_ALERT etc. is not already defined.

Make coap_log_t int to remove Visual Studio compile warnings.
2021-09-28 12:10:04 +01:00
obgm 0061b3fe07 Merge pull request #739 from mrdeep1/coap_can_exit
doc: Document the coap_can_exit() function
2021-09-28 12:54:54 +02:00
Olaf Bergmann ca44071b8a net.h: do not include sys/select.h in Windows builds
Windows apparently has no select.h header, therefore it is not
included for Windows builds.
2021-09-01 09:50:45 +02:00
Olaf Bergmann e984f38b8f [DTLS] make buffer sizes for psk and psk_identity configurable
The pre-processor values COAP_DTLS_MAX_PSK and
COAP_DTLS_MAX_PSK_IDENTITY now can be set at build time. Both values
default to 64. Static buffer sizes in the TLS library wrappers are
adjusted accordingly.
2021-09-01 09:35:38 +02:00
Olaf Bergmann 54dbc3eeb8 [RIOT] coap_time.h: fix COAP_TICKS_PER_SECOND for undefined XTIMER_HZ
With ztimer usage, XTIMER_HZ is not defined anymore in xtimer.h. As a
workaround, XTIMER_HZ_BASE is used.
2021-09-01 09:34:47 +02:00
Olaf Bergmann 05e7f12d7c net.h: Include sys/select.h for fd_set 2021-09-01 09:34:47 +02:00
Jon Shallow a5c0d12354 doc: Document the coap_can_exit() function 2021-08-04 14:14:37 +01:00
Jon Shallow 8ce139d349 coap_event.h: Make coap_event_t an enum
examples/coap-client.c:
examples/coap-server.c:

Explicitly define each enum case to remove complier warnings.
2021-07-31 17:08:10 +01:00
Jon Shallow c61748f4dd RFC7959: session->lg_xmit not being released for a server
Following transmission of a large body by a server using BLOCK2,
session->lg_xmit is not getting released. It does get released when the session
is freed off.

A client doing transmission of a large body idoes release session->lg_xmit.

Timeout lg_xmit after 4 * ACK_TIMEOUT seconds after final block is transmitted.
2021-07-07 15:27:06 +01:00
Jon Shallow d52986f004 coap_resource_init: Leading '/' is not required for uri_path
Remind users in the documentation that the full path defining the resource in
the uri_path parameter does not normally need a leading '/'.

E.g. It should be "full/path/for/resource", not "/full/path/for/resource".
2021-06-30 14:05:22 +01:00
Jon Shallow 60c69557f3 pdu.h: Remove unassigned response code COAP_RESPONSE_CODE_OK 2021-06-30 12:11:54 +01:00
Olaf Bergmann 1da37b9abb Bump version to 4.3.0 2021-06-21 10:39:42 +02:00
Olaf Bergmann 64505862d1 update release version to rc4 in configuration 2021-06-15 10:27:25 +02:00
Olaf Bergmann 60421db0a5 Add SPDX-License-Identifier to source files
This change adds 'SPDX-License-Identifier: BSD-2-Clause' [1] to
the source code files that originate in the libcoap project.

Note that not all files are tagged because they are pulled in
from other sources and thus may fall under a different license.
More information about these is contained in the LICENSE file.

[1] https://spdx.org/licenses/BSD-2-Clause.html
2021-06-08 18:14:03 +02:00