Commit Graph
866 Commits
Author SHA1 Message Date
Jon Shallow b442140bb3 Oscore: Change HAVE_OSCORE define to COAP_OSCORE_SUPPORT for clarity
Prevents possibility of name clashes when integrating with other code.
2023-06-14 12:55:25 +01:00
Jon Shallow 1d81256fc1 ipv[46]: Add in configurable support for IPv4, IPv6 and AF_UNIX
Move some existing header inline code into source files.

Update coap_resolve_address_info() to remove need for client based app
code to have to understand IPv4/IPv6 code.

Remove IPv4/IPv6 specific code from examples code.
2023-06-12 14:55:09 +01:00
Jon Shallow b3ec5b83c3 Windows: Fix resolve issues / remove warnings
Handle Windows x68 size_t being only 32 bits.
2023-06-09 12:07:10 +01:00
Jon Shallow ed295ace42 coap_io.c: Handle windows version of SOL_IP definition
Windows uses IPPROTO_IP for IP_PKTINFO access.
2023-06-09 12:05:17 +01:00
Jon Shallow 21bd1df95b examples: Remove references to sockaddr* structures
This means that apps need to have no knowledge of what IP support is available.

Updates coap_uri_into_options() and coap_resolve_address_info()
which have only been recently added to develop branch and are not in any
previous release.
2023-06-09 12:04:09 +01:00
Jon Shallow d4b9a53eed coap_io.c: Handle windows generating ECONNRESET for udp sessions
Correct msg_namelen to be sizeof(sockaddr_in) if IF_INET.
2023-06-08 18:37:51 +01:00
Jon Shallow 6c05d34fc6 bcast: Support IPv4 broadcast as multicast
See https://datatracker.ietf.org/doc/html/draft-ietf-core-groupcomm-bis-08#section-3.9.5
2023-06-08 17:47:56 +01:00
Jon Shallow f4666c2ea9 LwIP: Support disabling LwIP's IPv6 support 2023-06-08 17:40:08 +01:00
Jon Shallow 8d869fff04 RIOT: Update to support latest libcoap code
Add in examples and pkg/build information
2023-06-05 12:47:15 +01:00
Jon Shallow 04f3a4a7e2 coap_oscore.c: Fix ASan detected global-buffer-overflow bug 2023-05-23 14:54:55 +01:00
Jon Shallow 08cbda80f1 block.c: Check that data received fits into specified block size 2023-05-23 14:53:33 +01:00
Jon Shallow 1cb29b6f5c net.c: Fix building without TCP enabled for EPOLL configured code
Report when using autotools or cmake that disabling TCP also disables
Websockets support.

Also, report for cmake when EPOLL support is not available.
2023-05-16 12:01:59 +01:00
Jon Shallow dbf78b526f block.h: Make COAP_OPT_BLOCK_* functions safe against NULL indirects
COAP_OPT_BLOCK_LAST(opt) may return NULL, so doing *COAP_OPT_BLOCK_LAST(opt)
is unsafe. Replace indirect with COAP_OPT_BLOCK_END_BYTE(opt).
2023-05-11 09:00:53 +01:00
Jon Shallow 4ef0705ccd block.c: Handle missing / incorrect SIZE1 and SIZE2 options 2023-05-11 08:59:59 +01:00
Jon Shallow 6cd7b7883c coap_io.c: Clean up coap_win_error_to_errno() usage 2023-05-11 08:59:04 +01:00
Jon Shallow a40ffc722c CMakeLists.txt: Set compiler options for both the library and examples
Fix some reported Windows errors now that "treat all warnings as errors" is
correctly set in the github workflows.
2023-05-11 08:57:48 +01:00
Jon Shallow 9d66e47241 coap_debug.c: Split out coap_print_ip_addr() from coap_print_addr()
Sometimes just the IP address is required, not the port as well.
2023-05-05 12:00:33 +01:00
Jon Shallow b9d53ed3d4 keepalive: Fix timeouts when network issues
If keepalive is enabled, make sure that they continue when a server
stops / starts.  Limit the retry timeouts to the number of seconds
defined by coap_context_set_keepalive() so that interim NAT devices
are always kept "warm".

Addded in a new event COAP_EVENT_KEEPALIVE_FAILURE and updated docs
accordingly.
2023-05-05 10:35:39 +01:00
Jon Shallow 3ebbcde43a mcast_ips: Restore mcast ip for mcast sessions for each new coap_send()
If the server is responding to a mcast request with a packet that is a
part of larger body (i.e. responding with Block2 option) the requests
for the missing packets have to be using unicast, which continues
to be supported.

The application can determine the unicast remote address before the next
coap_send() by using coap_session_get_addr_remote().

Add in a new function coap_session_get_addr_mcast() to get the mcast IP
if the client session was set up to talk to a mcast address.
2023-05-01 16:28:44 +01:00
Jon Shallow 46aa5760ee coap_session.c: Fix handling of COAP_NACK_ICMP_ISSUE disconnects 2023-05-01 10:13:07 +01:00
Jon Shallow e983e4eb5e Persist_OSCORE: Include nonce in the saved OSCORE information
In addition, make sure large (multi packet) FETCH observe information
is properly restored.
2023-04-24 09:55:38 +01:00
Jon Shallow 712255ec90 mid: Add leading zeros to mid= reporting for ease of debugging 2023-04-24 09:54:34 +01:00
Jon Shallow c4ce40347f coap_pdu_duplicate: Revert and fix previous change 2023-04-24 09:53:39 +01:00
Jon Shallow ca609d221c Persist: Support tracking observe information over server restarts
Add in optional callbacks for when dynamic resources are setup and deleted.

Add in optional callbacks for when observe subscriptions start and stop.

Add in optional callbacks for when the observe counter is updated (can be
ratelimited) for a resource as well as track when a resource is deleted.

Add is support for new functions

Main functions with libcoap tracking support are
 coap_persist_startup()
 coap_persist_stop()

coap-server has -t option to track observe information.

UDP sessions supported, as well as OSCORE over UDP.

Documentation updated

libcoap tracking support (as opposed to application tracking) is configurable.
2023-04-22 11:07:21 +01:00
Jon Shallow 203471118f logging: Make bytes received logging consistent 2023-04-22 10:47:43 +01:00
Jon Shallow dfaaa47405 coap_uri.c: Do more libcoap functionality checking in coap_split_uri_sub() 2023-04-22 10:46:36 +01:00
Jon Shallow e533b980fa coap_resolve_address_info: Move logic into function, simplifying server apps
Add in new function coap_get_available_scheme_hint_bits() to help as well.
2023-04-22 10:45:17 +01:00
Jon Shallow 191cd5cf40 Layers: Move layer index table into coap_layers.c 2023-04-15 19:33:18 +01:00
Jon Shallow e10a0d0eff coap_uri.c: Correctly detect port in coap_uri_into_options() 2023-04-15 19:31:55 +01:00
Jon Shallow 621fd20c2b CBOR: Check for buffer overruns when reading in CBOR data 2023-04-13 10:16:38 +01:00
Jon Shallow 5c11bc5f00 coap_ws.c: Fix coap_ws_is_supported() check for GnuTLS 2023-04-13 10:13:54 +01:00
Jon Shallow 964bd69481 MinGW: Initial compile environment support 2023-04-12 10:06:46 +01:00
Jon Shallow aee4c3fa6e logging: Support defining maximum logging level
This allows for code reduction if not all logging levels are required.

Done by defining ./configure --enable-max-logging-level=X, where X can have
the value of 0 through 8 inclusive.

COAP_LOG_EMERG is always logged.

Can save up to 40k bytes.
2023-04-12 09:55:13 +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 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 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 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 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
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 43b968d57c netif: Fix errno tracking and GnuTLS stream read error handling 2023-03-06 12:10:43 +00:00