Implement support for LLC sockets

Useful in embedded contexts, where devices might only have a link-layer
connection, but still need to exchange information.
This commit is contained in:
Ernestas Kulik authored and Jon Shallow committed 2026-04-18 09:11:19 +01:00
1 parent 3f4d08f964
commit 766b852849
19 files changed
+463 -39

No files matched your search

+38 -2
View File
@@ -155,6 +155,21 @@ coap_address_clr_addr(coap_address_t *addr) {
#else /* ! WITH_LWIP && ! WITH_CONTIKI && ! RIOT_VERSION */
#if COAP_AF_LLC_SUPPORT
/* Including net/if.h after linux/llc.h results in redefinitions of numerous
* symbols.
*/
#include <net/if.h>
#include <linux/llc.h>
/* 00:11:22:33:44:55 */
#define HW_ADDRSTRLEN 17
/* llc[00:11:22:33:44:55]:DC */
#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
#endif /* COAP_AF_LLC_SUPPORT */
#ifdef _WIN32
#define sa_family_t short
#endif /* _WIN32 */
@@ -174,6 +189,9 @@ struct coap_address_t {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
struct coap_sockaddr_un cun; /* CoAP shortened special */
#if COAP_AF_LLC_SUPPORT
struct sockaddr_llc llc;
#endif /* COAP_AF_LLC_SUPPORT */
} addr;
};
@@ -217,14 +235,14 @@ typedef struct coap_addr_info_t {
* @param have_pki_psk Set to @c 1 if PSK/PKI information is known else @c 0.
* @param ws_check Set to @c 1 is WebSockets is to be included in the list
* else @c 0.
* @param use_unix_proto Set to the appropriate protocol to use for Unix
* @param use_proto Set to the appropriate protocol to use for Unix/LLC
* sockets, else set to COAP_PROTO_NONE for INET / INET6
* sockets.
* @return A bit mask of the available CoAP protocols (can be @c 0 if none)
* suitable for passing to coap_resolve_address_info().
*/
uint32_t coap_get_available_scheme_hint_bits(int have_pki_psk, int ws_check,
coap_proto_t use_unix_proto);
coap_proto_t use_proto);
/**
* coap_resolve_type_t values
@@ -290,6 +308,18 @@ void coap_address_init(coap_address_t *addr);
int coap_address_set_unix_domain(coap_address_t *addr,
const uint8_t *host, size_t host_len);
/**
* Copy the parsed LLC host into @p addr, setting other fields as appropriate.
*
* @param addr coap_address_t to update.
* @param host The parsed host from the CoAP URI.
* @param host_len The length of the parsed host from the CoAP URI.
*
* @return @c 1 success, @c 0 failure.
*/
int coap_address_set_llc(coap_address_t *addr,
const uint8_t *host, size_t host_len);
/* Convenience function to copy IPv6 addresses without garbage. */
#if defined(WITH_LWIP) || defined(WITH_CONTIKI) || defined(RIOT_VERSION)
COAP_STATIC_INLINE void
@@ -346,6 +376,12 @@ int coap_is_bcast(const coap_address_t *a);
*/
int coap_is_af_unix(const coap_address_t *a);
/**
* Checks if given address @p a denotes an AF_LLC address. This function
* returns @c 1 if @p a is of type AF_LLC, @c 0 otherwise.
*/
int coap_is_af_llc(const coap_address_t *a);
#else /* WITH_CONTIKI || RIOT_VERSION */
/**
+1
View File
@@ -85,6 +85,7 @@ struct coap_socket_t {
#define COAP_SOCKET_CAN_CONNECT 0x0800 /**< non blocking client socket can now connect without blocking */
#define COAP_SOCKET_MULTICAST 0x1000 /**< socket is used for multicast communication */
#define COAP_SOCKET_SLAVE 0x2000 /**< socket is a slave socket - do not close */
#define COAP_SOCKET_WANT_SENDTO 0x4000 /**< socket requires a destination address for sending */
#if COAP_SERVER_SUPPORT
coap_endpoint_t *coap_malloc_endpoint(void);
+10
View File
@@ -98,6 +98,16 @@ coap_uri_scheme_is_secure(const coap_uri_t *uri) {
*/
int coap_host_is_unix_domain(const coap_str_const_t *host);
/**
* Determines from the @p host whether this is an LLC socket request.
*
* @param host The host object.
*
* @return @c 0 on failure, or @c 1 on success.
*
*/
int coap_host_is_llc(const coap_str_const_t *host);
/**
* Creates a new coap_uri_t object from the specified URI. Returns the new
* object or NULL on error. The memory allocated by the new coap_uri_t