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 11 /** 12 * @file coap_layers.c 13 * @brief Layer Handling 14 */ 15 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 }; 125