Commit Graph
2617 Commits
Author SHA1 Message Date
Jon Shallow a4bbac4a60 coap_mutex_internal.h: Convert tabs to spaces 2023-04-10 14:56:03 +01:00
Jon Shallow 391803aebf WebSockets: Add in support for WebSockets layer
Follows RFC6455, as specified in RFC8323.

Make support configurable.

Add in example support.

Update other code to be aware of WebSockets as a CoAP protocol.
2023-04-10 14:38:56 +01:00
Jon Shallow f0f20c285d syslog.h: Leave in conditional LOG_ definitions for now 2023-04-10 14:19:09 +01:00
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 546f4203b1 examples: Clean up memory usage on error close down
Makes valgrind testing easier.

Note that it is unsafe to call coap_free_context() from with an atexit()
handler.
2023-04-08 18:02:16 +01:00
Jon Shallow 605c875030 coap_session.c: Make sure that lg_crcv is properly freed off
The response will never get seen as coap_session_mfree() continues to
close down the socket.
2023-04-08 17:59:36 +01:00
Jon Shallow 59e9434518 workflows: Support Windows changed OpenSSL directory
No longer need choco to install install OpenSSL as it is in loaded image.
2023-04-07 14:51:11 +01:00
Jon Shallow 5ae51b4ef1 Makefile.am: Make sure libcoap-3.{map|sym} sort is consistent 2023-04-04 19:36:40 +01:00
Jon Shallow 53615f5643 coap_encode.c: Fix coap_flsll() for negative numbers 2023-04-04 19:35:09 +01:00
Jon Shallow 00e4510636 net.c: Fix critical option checking 2023-04-04 19:33:16 +01:00
Jon Shallow e242200f0a net.c: Fix potential overflow in coap_send_internal() 2023-04-03 17:29:55 +01:00
Jon Shallow 6cd2ecb136 resource.c: Use initialized token in coap_notify_observers() 2023-04-03 17:27:58 +01:00
Jon Shallow da6459416f coap-server.c: Fix scheme hint type tracking
Missing part of a Websockets merge.
2023-03-26 18:53:37 +01:00
Jon Shallow 305c400d6f LwIP: Fix git clone url 2023-03-24 12:53:59 +00: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
Jon Shallow d06d701038 Layers: Report read/write counts at each layer and add diagnostics 2023-03-15 09:47:51 +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 6315c1af53 doxygen: Fix out of tree error and refresh Doxyfile 2023-03-13 19:44:14 +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 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