Commit Graph
2595 Commits
Author SHA1 Message Date
Jon Shallow 28c8a95f02 netif: Add stream listen, accept and connect 2023-03-08 11:48:52 +00:00
Jon Shallow 09222bb666 netif: Add in close 2023-03-06 15:05:13 +00:00
Jon Shallow cd874dad44 netif: Add in datagram listen and connect 2023-03-06 12:41:13 +00:00
Jon Shallow 43b968d57c netif: Fix errno tracking and GnuTLS stream read error handling 2023-03-06 12:10:43 +00:00
Richard Retanubun 4a6a99f5c7 coap-client: Make retransmision give up visible
Useful when coap-client is used to send block transfers.

Without this, users have to run coap-client with `-v 7`
before they can see why coap-client ends earlier than expected.

Logging at warning level to match the default log level
set by coap-client source code.
2023-03-04 09:59:44 +00:00
Jon Shallow 52cfd56c65 netif: Add in stream read write 2023-03-03 09:19:49 +00:00
Jon Shallow 4dfbcb631f coap_io.c: Map Windows WSA errors into errno for CoAP layer simplification 2023-03-02 15:19:47 +00:00
Jon Shallow aa34b5fb28 netif: Replace coap_network_{send|read}() with coap_socket_{send|recv}()
Replace coap_network_{send|read}() with coap_socket_{send|recv}().

Move coap_epoll_ctl_mod() into coap_io.c to be along with all the other epoll
specific functions for consistency.
2023-03-02 15:09:37 +00:00
Jon Shallow f933c6e604 netif: Create netif layer, initially provide datagram read/write
Add in skeleton coap_netif.c coap_netif_internal.h files, populated with
coap_netif_dgrm_read(), coap_netif_dgrm_read_ep(), and coap_netif_dgrm_write()
functions that are called by the CoAP and (D)TLS code which in turn call
the appropriate coap_socket_*() functions.

The coap_dtls_send() function parameters are aligned with
coap_netif_dgrm_write().
2023-03-01 13:58:06 +00:00
Jon Shallow 62c57e4842 inttypes.h: Add in PRIu32 if not defined 2023-02-25 14:00:42 +00:00
Marcin Niestroj 600eb783c9 net: fix coap_log_warn() in coap_send()
pdu->actual_token.length is a size_t, so use "%zu" format specifier.

session->max_token_size is a uint32_t, so use "%" PRIu32 format specifier.

This allows to correctly handle those in a cross platform way.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-02-25 13:36:57 +00:00
Jon Shallow 9654c3fd2e inttypes.h: Make usage for print formatting global 2023-02-25 11:00:41 +00:00
Marcin Niestroj 820bab3199 mutex: support Zephyr RTOS mutex definition
Provide mutex implementation for Zephyr RTOS, so that libcoap inside Zephyr
can be used with COAP_CONSTRAINED_STACK enabled.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-02-24 20:37:43 +00:00
Marcin Niestroj bad2255ab4 mutex: define mutex with COAP_MUTEX_DEFINE() macro
Introduce new macro, which will be used for defining static mutex
objects, for use from COAP_CONSTRAINED_STACK enabled code. This macro
will automatically initialize mutex using platform/OS specific macro if
such exists.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-02-24 20:37:43 +00:00
Jon Shallow 2390abf8bd coap_io_contiki.c: Fix coap_network_read 2023-02-24 14:37:07 +00:00
Jon Shallow 54652664fb coap_packet_t: Rework to simplify usage
Reduces LwIP specific code.
2023-02-23 21:19:47 +00:00
Marcin Niestroj 40b76247af debug.c: replace 'in_port_t' with 'uint16_t'
`in_port_t` might be hidden under `_GNU_SOURCE` feature test macro, which
is not defined at the top of the file. This happens with newlib build with
Zephyr SDK and with Zephyr RTOS. As a result following build error occurs:

  /libcoap/src/coap_debug.c: In function 'coap_print_addr':
  /libcoap/src/coap_debug.c:189:3: error: unknown type name 'in_port_t'; \
                                              did you mean 'io_port_t'?
    189 |   in_port_t port;
        |   ^~~~~~~~~
        |   io_port_t

Workaround that issue by replacing `in_port_t` with `uint16_t`, as that is
the only place where former typedef was used.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-02-23 21:16:58 +00:00
Jon Shallow 78304f43a0 file prefix: Update more file names to have coap_ prefix 2023-02-10 20:35:32 +00:00
Jon Shallow 786149fb12 Unix Domain: Add in support for Unix Domains
Support the AF_UNIX address family for transporting CoAP internally within
an appliance.
2023-02-10 19:52:48 +00:00
Jon Shallow 95efc52a7d file prefix: Update more file names to have coap_ prefix 2023-02-09 09:47:14 +00:00
kkrentz 79c66705a1 Updates Contiki-specific code to Contiki-NG 2023-02-08 16:05:09 +00:00
Jon Shallow 33ddcc4840 coap_prng.c: Remove support for rand() (CVE-2021-34430)
Replace it using random().
2023-02-08 13:19:47 +00:00
Jon Shallow b24d646877 net.c: Release pdu if timeout failure in coap_send()
Remove some code duplication at the same time.
2023-02-08 13:18:16 +00:00
Jon Shallow 24d26465e8 block.c: Fix lg_xmit pdu's extended token in coap_add_data_large_internal() 2023-02-07 12:02:16 +00:00
Jon Shallow 47a83549a8 RFC8974: Add in support for Extended Tokens
Add in new function coap_context_set_max_token_size() to define
the maximum supported token size.

Track changes to PDU to support extended tokens.

Update documentation.
2023-02-04 11:08:32 +00:00
Jon Shallow c7cda63092 oscore: Handle encrypt error return
Check return from cose_encrypt0_encrypt() and correct spelling error.
2023-02-03 12:48:53 +00:00
Jon Shallow 583c52c567 net.c: Refactor handle_request() code for rigorous checking of output
Stack variable errors can creep in when code jumps to a label that is
in an inner level block that defines and uses that variable. Most cases are
caught by the compiler, but some are only caught by valgrind.

Reorder code so that use of inner blocks is reduced and labels are in the
top level block.
2023-02-03 09:54:32 +00:00
Jon Shallow 0a5d80ad66 coap_address.[ch]: Add coap_resolve_address_info() and coap_free_address_info()
coap_resolve_address_info() emulates getaddrinfo() but has the extensibility to
support other socket types based on the address to resolve.

coap-client, coap-server and lwip/client updated to use this new functionality.

coap_address(3) updated to include the new functions.
2023-02-03 09:53:24 +00:00
Jon Shallow 556a8ac213 CONTRIBUTE: Tidy up following a review 2023-02-01 16:46:00 +00:00
Jon Shallow ba2fada8f2 documentation: Tidy up man pages
Add in new coap_address(3) man page.
Tidy up endpoint documentation.
Fix other minor nits in the documentation.
2023-01-21 13:42:59 +00:00
Olaf Bergmann 5e79c96882 Doxyfile.in: Adjust maximum value for graph nodes
This change increases DOT_GRAPH_MAX_NODES to 100. With the default
value 50, the following error message occured:

error: Included by graph for 'coap_internal.h' not generated, too many nodes (51), threshold is 50. Consider increasing DOT_GRAPH_MAX_NODES.
2023-01-20 18:05:14 +01:00
Jon Shallow 813de0e39f uri.c: Simplify coap_split_uri_sub()
Remove complexity from parsing and make it easier to add in new schemes.
2023-01-19 16:45:03 +00:00
Jon Shallow 7fab8aa6fb OSCORE Option: Check for off by one for kid 2023-01-14 15:16:26 +00:00
Jon Shallow 7623e0f085 OSCORE: Add in interopability tests
See https://core-wg.github.io/oscore/test-spec5.html

Add in new test server oscore-interop-server to provide the necessary
functionality.

Add in script and configuration files to run the tests locally.
2023-01-14 10:26:20 +00:00
Jon Shallow dac6bd3b60 RFC8613: Add in OSCORE support
Based on work done in https://gitlab.informatik.uni-bremen.de/obergman/libcoap

New directories with files
 include/oscore
 src/oscore

New files
 include/coap3/coap_oscore.h
 include/coap3/coap_crypto_internal.h
 include/coap3/coap_oscore_internal.h
 man/coap-oscore-conf.txt.in
 man/coap_oscore.txt.in
 src/coap_oscore.c
 tests/test_oscore.c
 tests/test_oscore.h

Supported by new option (enabled by default)
 ./configure --enable-oscore
 cmake .. -DENABLE_OSCORE=ON

Requires a TLS library configured to do the OSCORE encryption and hashing.
2023-01-14 10:26:20 +00:00
Jon Shallow 3552b53be4 Copyright: Update copyright date to end 2023 as appropriate 2023-01-02 11:45:10 +00:00
Jon Shallow 4882641b95 documentation: Tidy up / correct documentation 2022-12-30 10:55:29 +00:00
Richard Retanubun e1d33fd7c9 resource.c: Add COAP_RESOURCE_MAX_SUBSCRIBER to limit subscribers
If COAP_RESOURCE_MAX_SUBSCRIBER is > 0
coap_add_observer() now checks and returns NULL
if COAP_RESOURCE_MAX_SUBSCRIBER is exceeded.

net.c then detects this and respond.

Per RFC7641 4.1. Request:

  A server that is unable or unwilling to add a new entry to the list
  of observers of a resource MAY silently ignore the registration
  request and process the GET request as usual.  The resulting response
  MUST NOT include an Observe Option, the absence of which signals to
  the client that it will not be notified of changes to the resource
  and, e.g., needs to poll the resource for its state instead.

Useful for constrained systems that wants to support
observers but need to be mindful of memory usage.
2022-12-26 11:19:21 +00:00
Jon Shallow 088fff1a82 coap-client.c: Fix case when no host is specified in the URI
If the host has not been specified in the URI, do not add in an
empty Uri-Host option as that is illegal.
2022-12-26 10:49:20 +00:00
Jon Shallow 7aa003bbe7 RFC links: Provide consistency for links to RFCs
Use https://rfc-editor.org/rfc/rfc.... instead of
https://tools.ietf.org/html/rfc.... for the RFC links.

Use https://rfc-editor.org/rfc/rfc.... instead of
https://datatracker.ietf.org/doc/html/rfc.... for the RFC links.
2022-12-20 20:36:53 +00:00
Jon Shallow 4821daf366 documentation: Tidy up documentation
Provide consistency across all of the man pages as per :-

Provide missing function headers for functions.

Hyper link the function definitions.

Hyper link RFC references (except in code blocks).

Use https://rfc-editor.org/rfc/rfc.... instead of
https://tools.ietf.org/html/rfc.... for the RFC links.

Use https://rfc-editor.org/rfc/rfc.... instead of
https://datatracker.ietf.org/doc/html/rfc.... for the RFC links.
2022-12-20 20:34:37 +00:00
Jon Shallow 68f1a6eff3 log_levels: Replace usage of syslog LOG_ with COAP_LOG_
This removes the reliance of syslog definitions in libcoap by using libcoap's
version.
2022-12-17 12:38:31 +00:00
Jon Shallow b8c5638423 examples: Align exit codes with documentation
Exit code of -1 is not defined in example man pages - use a value of 1
2022-12-13 20:31:18 +00:00
Jon Shallow be40b1f9cd block.c: Fix missing coap_log() updates from a merge 2022-12-13 20:29:32 +00:00
Jon Shallow 19841c2369 NACK: make sure token is correct as presented to NACK handler
For clients, update the stateless token used for subsequent block
transmissions back to the token used for the coap_send() when
reporting NACK errors.
2022-12-13 08:42:43 +00:00
Jon Shallow 73c4466779 logging: Use the new logging macros for libcoap code
Drop the use of syslog LOG_DEBUG etc. for coap_log() and use the
coap_log_debug() etc. macros which make use of COAP_LOG_DEBUG etc.
2022-12-13 08:30:33 +00:00
Jon Shallow f6aebcbff7 mem: Use coap_malloc_type() and coap_free_type() in libcoap
The use of coap_malloc() and coap_free() does not work with environments
that have their own memory managers (e.g. LwIP).

Convert coap_malloc() to coap_malloc_type(COAP_STRING,) and coap_free()
to coap_free_type(COAP_STRING,) in the library.
2022-12-13 08:24:29 +00:00
Jon Shallow 48c8eb0b3c .gitignore: Ignore LwIP DTLS enabled executables 2022-12-10 15:16:52 +00:00
Jon Shallow 4b54c0d9ef logging: Use new logging macros for examples and man pages
Drop the use of syslog LOG_DEBUG etc. for coap_log() and use the
coap_log_debug() etc. macros which make use of COAP_LOG_DEBUG etc.

Application examples updated, as well as the man page examples.
2022-12-09 14:55:39 +00:00
Jon Shallow 2c61bf184e Reliable: Fix usage of PDU type and mid
Reliable code expects type to be CON and can get confused by NON.

Having random values for mid for reliable sessions makes no sense as
the mid is not in the packet..

Only send out RST if non-reliable session.
2022-12-09 14:53:20 +00:00