Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024-2026 Carl Seifert
3 * SPDX-FileCopyrightText: 2024-2026 TU Dresden
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
9#include <stdint.h>
10#include "net/unicoap.h"
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
20
26
27/* We don't require a DTLS implementation to be present when the CoAP over DTLS driver is not used.
28 * Including DTLS headers without an implementation fails. Hence, we create a local alias
29 * that either maps to the system-provided DTLS session struct or to nothing. */
30
31#ifndef DOXYGEN
32# if IS_USED(MODULE_UNICOAP_DRIVER_DTLS)
33typedef sock_dtls_session_t unicoap_sock_dtls_session_t;
34# else
35typedef void unicoap_sock_dtls_session_t;
36# endif
37#endif
38
45typedef struct {
50
55
56 union {
57#if IS_USED(MODULE_UNICOAP_DRIVER_DTLS) || defined(DOXYGEN)
64#endif
65
66 /* MARK: unicoap_driver_extension_point */
67 };
68
73
79
88{
89 return packet->remote->proto;
90}
91
99static inline const void* _packet_get_dtls_session(unicoap_packet_t* packet)
100{
101#if IS_USED(MODULE_UNICOAP_DRIVER_DTLS)
102 return unicoap_packet_proto(packet) == UNICOAP_PROTO_DTLS ? packet->dtls_session : NULL;
103#else
104 (void)packet;
105 return NULL;
106#endif
107}
108
116 const unicoap_sock_dtls_session_t* dtls_session)
117{
118#if IS_USED(MODULE_UNICOAP_DRIVER_DTLS)
119 packet->dtls_session = dtls_session;
120#else
121 (void)packet;
122 (void)dtls_session;
123#endif
124}
125
126#ifdef __cplusplus
127}
128#endif
129
struct sock_dtls_session sock_dtls_session_t
Information about a created session.
Definition dtls.h:635
static const void * _packet_get_dtls_session(unicoap_packet_t *packet)
Retrieves transport session from packet.
Definition packet.h:99
static void _packet_set_dtls_session(unicoap_packet_t *packet, const unicoap_sock_dtls_session_t *dtls_session)
Sets DTLS transport session of packet.
Definition packet.h:115
static unicoap_proto_t unicoap_packet_proto(const unicoap_packet_t *packet)
Retrieves protocol number from packet.
Definition packet.h:87
unicoap_proto_t
Transport protocol CoAP is used over.
Definition transport.h:130
@ UNICOAP_PROTO_DTLS
CoAP over DTLS over UDP endpoint.
Definition transport.h:135
A CoAP endpoint.
Definition transport.h:182
unicoap_proto_t proto
Protocol number.
Definition transport.h:184
Properties of a CoAP message.
Definition message.h:297
Generic CoAP message.
Definition message.h:72
A type acting as an envelope for a message and data connected, like endpoints.
Definition packet.h:45
const unicoap_endpoint_t * local
The local endpoint this packet was received at or is to be sent from.
Definition packet.h:54
const sock_dtls_session_t * dtls_session
DTLS session.
Definition packet.h:63
unicoap_message_properties_t properties
Backing storage for properties, used by PDU header parser.
Definition packet.h:77
unicoap_message_t * message
Message, public API, also used by PDU header parser.
Definition packet.h:72
const unicoap_endpoint_t * remote
The remote endpoint this packet was received from or is destined for.
Definition packet.h:49
Main header for unicoap