Loading...
Searching...
No Matches
coap_layers.c
Go to the documentation of this file.
/* coap_layers.c -- Layer handling for libcoap
*
* Copyright (C) 2023-2024 Jon Shallow <supjps-libcoap@jpshallow.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
#include "coap3/coap_libcoap_build.h"
/*
* Layer index table. A whole protocol chunk gets copied into coap_socket_t.
* Each layer invokes the function defined at its layer to get the next layer
* (which could be above or below) to complete.
*
* The stack layers are (* managed by libcoap)
* Application
* CoAP *
* CoAP-Session *
* DTLS *
* Netif *
* Sockets *
* Network Stack
*
* dgrm read currently handled separately.
* strm read works down the layers.
* write works down the layers.
* establish is done after netif accept/connect completes by invoking SESSION
* and then works up the layers.
* close works down the layers
*/
coap_layer_func_t coap_layers_coap[COAP_PROTO_LAST][COAP_LAYER_LAST] = {
{
/* COAP_PROTO_NONE */
{ NULL, NULL, NULL, NULL }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_UDP */
{ NULL, coap_netif_dgrm_write, coap_session_establish, coap_netif_close }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_DTLS */
{ NULL, coap_dtls_send, coap_dtls_establish, coap_dtls_close }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, coap_netif_dgrm_write, coap_session_establish, coap_netif_close } /* TLS */
},
#if !COAP_DISABLE_TCP
{
/* COAP_PROTO_TCP */
{ coap_netif_strm_read, coap_netif_strm_write, coap_session_establish, coap_netif_close }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_TLS */
{ coap_tls_read, coap_tls_write, coap_tls_establish, coap_tls_close }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ coap_netif_strm_read, coap_netif_strm_write, coap_session_establish, coap_netif_close } /* TLS */
},
#if COAP_WS_SUPPORT
{
/* COAP_PROTO_WS */
{ coap_ws_read, coap_ws_write, coap_ws_establish, coap_ws_close }, /* SESSION */
{ coap_netif_strm_read, coap_netif_strm_write, coap_session_establish, coap_netif_close }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_WSS */
{ coap_ws_read, coap_ws_write, coap_tls_establish, coap_ws_close }, /* SESSION */
{ coap_tls_read, coap_tls_write, coap_session_establish, coap_tls_close }, /* WS */
{ coap_netif_strm_read, coap_netif_strm_write, coap_ws_establish, coap_netif_close } /* TLS */
}
#else /* !COAP_WS_SUPPORT */
{
/* COAP_PROTO_WS */
{ NULL, NULL, NULL, NULL }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_WSS */
{ NULL, NULL, NULL, NULL }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
}
#endif /* !COAP_WS_SUPPORT */
#else /* COAP_DISABLE_TCP */
{
/* COAP_PROTO_TCP */
{ NULL, NULL, NULL, NULL }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_TLS */
{ NULL, NULL, NULL, NULL }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_WS */
{ NULL, NULL, NULL, NULL }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
},
{
/* COAP_PROTO_WSS */
{ NULL, NULL, NULL, NULL }, /* SESSION */
{ NULL, NULL, NULL, NULL }, /* WS */
{ NULL, NULL, NULL, NULL } /* TLS */
}
#endif /* COAP_DISABLE_TCP */
};
coap_layers_coap
coap_layer_func_t coap_layers_coap[COAP_PROTO_LAST][COAP_LAYER_LAST]
Definition coap_layers.c:39
COAP_LAYER_LAST
@ COAP_LAYER_LAST
Definition coap_layers_internal.h:26
coap_libcoap_build.h
Library specific build wrapper for coap_internal.h.
coap_tls_read
ssize_t coap_tls_read(coap_session_t *session COAP_UNUSED, uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition coap_notls.c:296
coap_dtls_send
ssize_t coap_dtls_send(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition coap_notls.c:207
coap_tls_write
ssize_t coap_tls_write(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition coap_notls.c:284
coap_tls_establish
void coap_tls_establish(coap_session_t *session)
Layer function interface for layer below TLS accept/connect being established.
Definition coap_dtls.c:295
coap_dtls_establish
void coap_dtls_establish(coap_session_t *session)
Layer function interface for layer below DTLS connect being established.
Definition coap_dtls.c:266
coap_tls_close
void coap_tls_close(coap_session_t *session)
Layer function interface for TLS close for a session.
Definition coap_dtls.c:314
coap_dtls_close
void coap_dtls_close(coap_session_t *session)
Layer function interface for DTLS close for a session.
Definition coap_dtls.c:285
coap_netif_dgrm_write
ssize_t coap_netif_dgrm_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for netif datagram data transmission.
Definition coap_netif.c:125
coap_netif_close
void coap_netif_close(coap_session_t *session)
Layer function interface for Netif close for a session.
Definition coap_netif.c:260
coap_netif_strm_write
ssize_t coap_netif_strm_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for netif stream data transmission.
Definition coap_netif.c:236
coap_netif_strm_read
ssize_t coap_netif_strm_read(coap_session_t *session, uint8_t *data, size_t datalen)
Function interface for layer data stream receiving.
Definition coap_netif.c:215
COAP_PROTO_LAST
@ COAP_PROTO_LAST
Definition coap_pdu.h:320
coap_session_establish
void coap_session_establish(coap_session_t *session)
Layer function interface for layer below session accept/connect being established.
Definition coap_session.c:1395
coap_ws_establish
void coap_ws_establish(coap_session_t *session)
Layer function interface for layer below WebSockets accept/connect being established.
coap_ws_write
ssize_t coap_ws_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for websockets data transmission.
coap_ws_close
void coap_ws_close(coap_session_t *session)
Layer function interface for WebSockets close for a session.
coap_ws_read
ssize_t coap_ws_read(coap_session_t *session, uint8_t *data, size_t datalen)
Function interface for websockets data receiving.
coap_layer_func_t
Definition coap_layers_internal.h:106