libcoap 4.3.2rc2

coap_layers.c
Go to the documentation of this file.
1/* coap_layers.c -- Layer handling for libcoap
2 *
3 * Copyright (C) 2023 Jon Shallow <supjps-libcoap@jpshallow.com>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * This file is part of the CoAP library libcoap. Please see
8 * README for terms of use.
9 */
10
16#include "coap3/coap_internal.h"
17
18/*
19 * Layer index table. A whole protocol chunk gets copied into coap_socket_t.
20 * Each layer invokes the function defined at its layer to get the next layer
21 * (which could be above or below) to complete.
22 *
23 * The stack layers are (* managed by libcoap)
24 * Application
25 * CoAP *
26 * CoAP-Session *
27 * DTLS *
28 * Netif *
29 * Sockets *
30 * Network Stack
31 *
32 * dgrm read currently handled separately.
33 * strm read works down the layers.
34 * write works down the layers.
35 * establish is done after netif accept/connect completes by invoking SESSION
36 * and then works up the layers.
37 * close works down the layers
38 */
39 coap_layer_func_t coap_layers_coap[COAP_PROTO_LAST][COAP_LAYER_LAST] = {
40 {
41 /* COAP_PROTO_NONE */
42 { NULL, NULL, NULL, NULL }, /* SESSION */
43 { NULL, NULL, NULL, NULL }, /* WS */
44 { NULL, NULL, NULL, NULL } /* TLS */
45 },
46 {
47 /* COAP_PROTO_UDP */
48 { NULL, coap_netif_dgrm_write, coap_session_establish, coap_netif_close }, /* SESSION */
49 { NULL, NULL, NULL, NULL }, /* WS */
50 { NULL, NULL, NULL, NULL } /* TLS */
51 },
52 {
53 /* COAP_PROTO_DTLS */
54 { NULL, coap_dtls_send, coap_dtls_establish, coap_dtls_close }, /* SESSION */
55 { NULL, NULL, NULL, NULL }, /* WS */
56 { NULL, coap_netif_dgrm_write, coap_session_establish, coap_netif_close } /* TLS */
57 },
58#if !COAP_DISABLE_TCP
59 {
60 /* COAP_PROTO_TCP */
61 { coap_netif_strm_read, coap_netif_strm_write, coap_session_establish, coap_netif_close }, /* SESSION */
62 { NULL, NULL, NULL, NULL }, /* WS */
63 { NULL, NULL, NULL, NULL } /* TLS */
64 },
65 {
66 /* COAP_PROTO_TLS */
67 { coap_tls_read, coap_tls_write, coap_tls_establish, coap_tls_close }, /* SESSION */
68 { NULL, NULL, NULL, NULL }, /* WS */
69 { coap_netif_strm_read, coap_netif_strm_write, coap_session_establish, coap_netif_close } /* TLS */
70 },
71#if COAP_WS_SUPPORT
72 {
73 /* COAP_PROTO_WS */
74 { coap_ws_read, coap_ws_write, coap_ws_establish, coap_ws_close }, /* SESSION */
75 { coap_netif_strm_read, coap_netif_strm_write, coap_session_establish, coap_netif_close }, /* WS */
76 { NULL, NULL, NULL, NULL } /* TLS */
77 },
78 {
79 /* COAP_PROTO_WSS */
80 { coap_ws_read, coap_ws_write, coap_tls_establish, coap_ws_close }, /* SESSION */
81 { coap_tls_read, coap_tls_write, coap_session_establish, coap_tls_close }, /* WS */
82 { coap_netif_strm_read, coap_netif_strm_write, coap_ws_establish, coap_netif_close } /* TLS */
83 }
84#else /* !COAP_WS_SUPPORT */
85 {
86 /* COAP_PROTO_WS */
87 { NULL, NULL, NULL, NULL }, /* SESSION */
88 { NULL, NULL, NULL, NULL }, /* WS */
89 { NULL, NULL, NULL, NULL } /* TLS */
90 },
91 {
92 /* COAP_PROTO_WSS */
93 { NULL, NULL, NULL, NULL }, /* SESSION */
94 { NULL, NULL, NULL, NULL }, /* WS */
95 { NULL, NULL, NULL, NULL } /* TLS */
96 }
97#endif /* !COAP_WS_SUPPORT */
98#else /* COAP_DISABLE_TCP */
99 {
100 /* COAP_PROTO_TCP */
101 { NULL, NULL, NULL, NULL }, /* SESSION */
102 { NULL, NULL, NULL, NULL }, /* WS */
103 { NULL, NULL, NULL, NULL } /* TLS */
104 },
105 {
106 /* COAP_PROTO_TLS */
107 { NULL, NULL, NULL, NULL }, /* SESSION */
108 { NULL, NULL, NULL, NULL }, /* WS */
109 { NULL, NULL, NULL, NULL } /* TLS */
110 },
111 {
112 /* COAP_PROTO_WS */
113 { NULL, NULL, NULL, NULL }, /* SESSION */
114 { NULL, NULL, NULL, NULL }, /* WS */
115 { NULL, NULL, NULL, NULL } /* TLS */
116 },
117 {
118 /* COAP_PROTO_WSS */
119 { NULL, NULL, NULL, NULL }, /* SESSION */
120 { NULL, NULL, NULL, NULL }, /* WS */
121 { NULL, NULL, NULL, NULL } /* TLS */
122 }
123#endif /* COAP_DISABLE_TCP */
124};
coap_internal.h
Pulls together all the internal only header files.
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_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:264
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:175
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:252
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:50
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:21
coap_tls_close
void coap_tls_close(coap_session_t *session)
Layer function interface for TLS close for a session.
Definition: coap_dtls.c:69
coap_dtls_close
void coap_dtls_close(coap_session_t *session)
Layer function interface for DTLS close for a session.
Definition: coap_dtls.c:40
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:123
coap_netif_close
void coap_netif_close(coap_session_t *session)
Layer function interface for Netif close for a session.
Definition: coap_netif.c:258
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:234
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:213
COAP_PROTO_LAST
@ COAP_PROTO_LAST
Definition: coap_pdu.h:312
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:1270
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