Commit Graph
501 Commits
Author SHA1 Message Date
Jon Shallow 6599297edb syslog.h: Remove all references to syslog.h
syslog.h is no longer required for libcoap as all LOG_ usage has been replaced
with COAP_LOG_.

Added #include <stdio.h> to example code for code-client and coap-server as
a hint should application code be using LOG_.
2023-04-10 14:03:13 +01:00
Jon Shallow c041af0b2b WebSockets: Add in libcoap infrastructure
Add in stub Websockets files.

Add in coap_crypto_hash(0 function.

Actual WebSocket support for applications will follow.
2023-03-24 09:49:00 +00:00
Jon Shallow 29c65c9d44 layers: Simplify and be more rigorous in layer separation
Tidy up send/receive reporting at each layer.
2023-03-23 19:04:55 +00:00
Jon Shallow adb8a3f5e2 layers: Add in protocol layers support
Current stack:-

Application
CoAP
CoAP-Session
DTLS
Netif
Sockets
Network Stack

Depending on the CoAP protocol, indexing functions through coap_layers_coap[]
(in src/coap_io.c) will invoke the correct layer function when used at the
CoAP and DTLS layers.

It is then easy to add in another protocol layer by updating coap_layers_coap[].
2023-03-20 10:49:02 +00:00
hasheddan e9576507d9 block.h/pdu.h: fix misspellings of "already"
Fixes misspellings of "already" in the block and pdu header files.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2023-03-15 09:02:11 +00:00
Jon Shallow ecf07b53b5 tls_layer: Separate out (D)TLS layer functionality
Add in new file src/coap_dtls.c.

Add in coap_(d)tls_establish() functions which are called when netif
accept / connect take place.

Add in coap_session_establish() function which is called when (D)TLS
has established as well as at the session layer if there is no (D)TLS
in preparation for properly supporting protocol layers.

Add in coap_(d)tls_close() functions which are called prior to
coap_netif_close().
2023-03-13 20:42:22 +00:00
Jon Shallow 7d76228b86 MacOS: Fix compile warnings 2023-03-13 20:05:18 +00:00
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 52cfd56c65 netif: Add in stream read write 2023-03-03 09:19:49 +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
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 54652664fb coap_packet_t: Rework to simplify usage
Reduces LwIP specific code.
2023-02-23 21:19:47 +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 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 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 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 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
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 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 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
Carsten Schoenert 2221a53d9c Spelling: Fix typo compatability -> compatibility 2022-12-01 19:05:22 +00:00
Jon Shallow 73b59182fd FETCH Observe: Handle Observes when FETCH body is large
Assemble all the blocks before checking for Observe registration
or de-registration.

Track all the tokens used for the large FETCH registration and
re-use them for the de-registration as the server can elect to use
any of them when re-assembling the body for the registration Token.
2022-11-30 11:35:25 +00:00
Jon Shallow c9f40d7d09 request-tag: Add in support for sending Request-Tag option with every request
If multiple requests (apart from DELETE) are sent at the same time to
the same resource, and the responses need to make use of the Block2 option,
there is no way for the server to differentiate between which block set a
request (if there is a resource content change) is for unless a Request-Tag
is used.

Disable this functionality by setting COAP_BLOCK_NO_PREEMPTIVE_RTAG when
calling coap_context_set_block_mode().  Request-Tag will still be sent
with any request that includes Block1 option.
2022-11-26 12:47:21 +00:00
Jon Shallow 89b159b148 coap_io_process_with_fds: Move mutex protected variables into coap_context_t
coap_io_process_with_fds() can lock up a mutex for a long time for
stack constrained systems.

If 2 threads (in embedded system) provide client and server functionality
using separate coap_context_t, then there will be random delays on the other
thread while the first is waiting having called coap_io_process() or
coap_io_process_with_fds().

No thread should lock up a mutex for a long time.  Moved the (mutex protected)
variables into coap_context_t so there is no need to use a mutex.
2022-11-26 12:29:46 +00:00
Jon Shallow c0559e37b4 option checking: Do further option syntax checking for incoming PDUs
Extend coap_option_check_critical() for repeating options that are not
repeatable, so 4.02 error code can be returned.
https://www.rfc-editor.org/rfc/rfc7252#section-5.4.5

Check for option Proxy-Scheme and return 4.02 if option Uri-Host is
not present.

Clear M bit for option Block2 in a request as it must be ingnored on reception.
https://datatracker.ietf.org/doc/html/rfc7959#section-2.2

check_repeatable() now is coap_option_check_repeatable() (still internal).
2022-11-23 15:51:34 +00:00
Jon Shallow 8a40fcc4aa options: Update documentation and fix incorrect function usage
Correct documented return values from changes back in 2015 for option filter
checking (option numbers could only be 1 byte then).

Correct code in coap_option_next() that assumed one of the defunct return
values.
2022-11-23 15:42:47 +00:00
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