Anjay Lite
Loading...
Searching...
No Matches
anj_net_wrapper.h
Go to the documentation of this file.
1/*
2 * Copyright 2023-2026 AVSystem <avsystem@avsystem.com>
3 * AVSystem Anjay Lite LwM2M SDK
4 * All rights reserved.
5 *
6 * Licensed under AVSystem Anjay Lite LwM2M Client SDK - Non-Commercial License.
7 * See the attached LICENSE file for details.
8 */
9
10#include <anj/init.h>
11
32#ifndef ANJ_NET_WRAPPER_H
33# define ANJ_NET_WRAPPER_H
34
36# ifdef ANJ_NET_WITH_UDP
38# endif // ANJ_NET_WITH_UDP
39# ifdef ANJ_NET_WITH_DTLS
41# endif // ANJ_NET_WITH_DTLS
42# ifdef ANJ_NET_WITH_NON_IP_BINDING
44# endif // ANJ_NET_WITH_NON_IP_BINDING
45
46# ifdef __cplusplus
47extern "C" {
48# endif
49
52 anj_net_ctx_t **ctx,
53 const anj_net_config_t *config) {
54 switch (type) {
55# if defined(ANJ_NET_WITH_UDP)
57 return anj_udp_create_ctx(ctx, config);
58# endif // defined(ANJ_NET_WITH_UDP)
59# if defined(ANJ_NET_WITH_DTLS)
61 return anj_dtls_create_ctx(ctx, config);
62# endif // defined(ANJ_NET_WITH_DTLS)
63# if defined(ANJ_NET_WITH_NON_IP_BINDING)
65 return anj_non_ip_create_ctx(ctx, config);
66# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
67 default:
68 return ANJ_NET_ENOTSUP;
69 }
70}
71
74 anj_net_ctx_t *ctx,
75 const char *hostname,
76 const char *port) {
77 switch (type) {
78# if defined(ANJ_NET_WITH_UDP)
80 return anj_udp_connect(ctx, hostname, port);
81# endif // defined(ANJ_NET_WITH_UDP)
82# if defined(ANJ_NET_WITH_DTLS)
84 return anj_dtls_connect(ctx, hostname, port);
85# endif // defined(ANJ_NET_WITH_DTLS)
86# if defined(ANJ_NET_WITH_NON_IP_BINDING)
88 return anj_non_ip_connect(ctx, hostname, port);
89# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
90 default:
91 return ANJ_NET_ENOTSUP;
92 }
93}
94
96static inline int anj_net_send(anj_net_binding_type_t type,
97 anj_net_ctx_t *ctx,
98 size_t *bytes_sent,
99 const uint8_t *buf,
100 size_t length) {
101 switch (type) {
102# if defined(ANJ_NET_WITH_UDP)
104 return anj_udp_send(ctx, bytes_sent, buf, length);
105# endif // defined(ANJ_NET_WITH_UDP)
106# if defined(ANJ_NET_WITH_DTLS)
108 return anj_dtls_send(ctx, bytes_sent, buf, length);
109# endif // defined(ANJ_NET_WITH_DTLS)
110# if defined(ANJ_NET_WITH_NON_IP_BINDING)
112 return anj_non_ip_send(ctx, bytes_sent, buf, length);
113# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
114 default:
115 return ANJ_NET_ENOTSUP;
116 }
117}
118
121 anj_net_ctx_t *ctx,
122 size_t *bytes_received,
123 uint8_t *buf,
124 size_t length) {
125 switch (type) {
126# if defined(ANJ_NET_WITH_UDP)
128 return anj_udp_recv(ctx, bytes_received, buf, length);
129# endif // defined(ANJ_NET_WITH_UDP)
130# if defined(ANJ_NET_WITH_DTLS)
132 return anj_dtls_recv(ctx, bytes_received, buf, length);
133# endif // defined(ANJ_NET_WITH_DTLS)
134# if defined(ANJ_NET_WITH_NON_IP_BINDING)
136 return anj_non_ip_recv(ctx, bytes_received, buf, length);
137# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
138 default:
139 return ANJ_NET_ENOTSUP;
140 }
141}
142
145 anj_net_ctx_t *ctx) {
146 switch (type) {
147# if defined(ANJ_NET_WITH_UDP)
149 return anj_udp_close(ctx);
150# endif // defined(ANJ_NET_WITH_UDP)
151# if defined(ANJ_NET_WITH_DTLS)
153 return anj_dtls_close(ctx);
154# endif // defined(ANJ_NET_WITH_DTLS)
155# if defined(ANJ_NET_WITH_NON_IP_BINDING)
157 return anj_non_ip_close(ctx);
158# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
159 default:
160 return ANJ_NET_ENOTSUP;
161 }
162}
163
166 anj_net_ctx_t **ctx) {
167 switch (type) {
168# if defined(ANJ_NET_WITH_UDP)
170 return anj_udp_cleanup_ctx(ctx);
171# endif // defined(ANJ_NET_WITH_UDP)
172# if defined(ANJ_NET_WITH_DTLS)
174 return anj_dtls_cleanup_ctx(ctx);
175# endif // defined(ANJ_NET_WITH_DTLS)
176# if defined(ANJ_NET_WITH_NON_IP_BINDING)
178 return anj_non_ip_cleanup_ctx(ctx);
179# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
180 default:
181 return ANJ_NET_ENOTSUP;
182 }
183}
184
187 anj_net_ctx_t *ctx,
188 int32_t *out_value) {
189 switch (type) {
190# if defined(ANJ_NET_WITH_UDP)
192 return anj_udp_get_inner_mtu(ctx, out_value);
193# endif // defined(ANJ_NET_WITH_UDP)
194# if defined(ANJ_NET_WITH_DTLS)
196 return anj_dtls_get_inner_mtu(ctx, out_value);
197# endif // defined(ANJ_NET_WITH_DTLS)
198# if defined(ANJ_NET_WITH_NON_IP_BINDING)
200 return anj_non_ip_get_inner_mtu(ctx, out_value);
201# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
202 default:
203 return ANJ_NET_ENOTSUP;
204 }
205}
206
209 anj_net_ctx_t *ctx,
210 anj_net_socket_state_t *out_value) {
211 switch (type) {
212# if defined(ANJ_NET_WITH_UDP)
214 return anj_udp_get_state(ctx, out_value);
215# endif // defined(ANJ_NET_WITH_UDP)
216# if defined(ANJ_NET_WITH_DTLS)
218 return anj_dtls_get_state(ctx, out_value);
219# endif // defined(ANJ_NET_WITH_DTLS)
220# if defined(ANJ_NET_WITH_NON_IP_BINDING)
222 return anj_non_ip_get_state(ctx, out_value);
223# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
224 default:
225 return ANJ_NET_ENOTSUP;
226 }
227}
228
231 anj_net_ctx_t *ctx) {
232 switch (type) {
233# if defined(ANJ_NET_WITH_UDP)
235 return anj_udp_queue_mode_rx_off(ctx);
236# endif // defined(ANJ_NET_WITH_UDP)
237# if defined(ANJ_NET_WITH_DTLS)
239 return anj_dtls_queue_mode_rx_off(ctx);
240# endif // defined(ANJ_NET_WITH_DTLS)
241# if defined(ANJ_NET_WITH_NON_IP_BINDING)
243 return anj_non_ip_queue_mode_rx_off(ctx);
244# endif // defined(ANJ_NET_WITH_NON_IP_BINDING)
245 default:
246 return ANJ_NET_ENOTSUP;
247 }
248}
249
250# ifdef __cplusplus
251}
252# endif
253
254#endif // ANJ_NET_WRAPPER_H
Network backend interface for DTLS transport.
anj_net_cleanup_ctx_t anj_dtls_cleanup_ctx
Definition anj_dtls.h:40
anj_net_get_inner_mtu_t anj_dtls_get_inner_mtu
Definition anj_dtls.h:42
anj_net_create_ctx_t anj_dtls_create_ctx
Definition anj_dtls.h:37
anj_net_recv_t anj_dtls_recv
Definition anj_dtls.h:39
anj_net_get_state_t anj_dtls_get_state
Definition anj_dtls.h:43
anj_net_connect_t anj_dtls_connect
Definition anj_dtls.h:36
anj_net_queue_mode_rx_off_t anj_dtls_queue_mode_rx_off
Definition anj_dtls.h:44
anj_net_send_t anj_dtls_send
Definition anj_dtls.h:38
anj_net_close_t anj_dtls_close
Definition anj_dtls.h:35
Platform hooks for network transport integration.
#define ANJ_NET_ENOTSUP
Definition anj_net_api.h:77
anj_net_binding_type_t
Definition anj_net_api.h:89
@ ANJ_NET_BINDING_NON_IP
Definition anj_net_api.h:92
@ ANJ_NET_BINDING_DTLS
Definition anj_net_api.h:91
@ ANJ_NET_BINDING_UDP
Definition anj_net_api.h:90
struct anj_net_ctx_struct anj_net_ctx_t
Opaque network context handle.
Definition anj_net_api.h:227
anj_net_socket_state_t
Definition anj_net_api.h:95
static int anj_net_get_state(anj_net_binding_type_t type, anj_net_ctx_t *ctx, anj_net_socket_state_t *out_value)
Definition anj_net_wrapper.h:208
static int anj_net_create_ctx(anj_net_binding_type_t type, anj_net_ctx_t **ctx, const anj_net_config_t *config)
Definition anj_net_wrapper.h:51
static int anj_net_cleanup_ctx(anj_net_binding_type_t type, anj_net_ctx_t **ctx)
Definition anj_net_wrapper.h:165
static int anj_net_connect(anj_net_binding_type_t type, anj_net_ctx_t *ctx, const char *hostname, const char *port)
Definition anj_net_wrapper.h:73
static int anj_net_queue_mode_rx_off(anj_net_binding_type_t type, anj_net_ctx_t *ctx)
Definition anj_net_wrapper.h:230
static int anj_net_close(anj_net_binding_type_t type, anj_net_ctx_t *ctx)
Definition anj_net_wrapper.h:144
static int anj_net_recv(anj_net_binding_type_t type, anj_net_ctx_t *ctx, size_t *bytes_received, uint8_t *buf, size_t length)
Definition anj_net_wrapper.h:120
static int anj_net_get_inner_mtu(anj_net_binding_type_t type, anj_net_ctx_t *ctx, int32_t *out_value)
Definition anj_net_wrapper.h:186
static int anj_net_send(anj_net_binding_type_t type, anj_net_ctx_t *ctx, size_t *bytes_sent, const uint8_t *buf, size_t length)
Definition anj_net_wrapper.h:96
Network backend interface for Non-IP transport.
Network backend interface for UDP transport.
anj_net_send_t anj_udp_send
Definition anj_udp.h:38
anj_net_connect_t anj_udp_connect
Definition anj_udp.h:36
anj_net_close_t anj_udp_close
Definition anj_udp.h:35
anj_net_create_ctx_t anj_udp_create_ctx
Definition anj_udp.h:37
anj_net_recv_t anj_udp_recv
Definition anj_udp.h:39
anj_net_cleanup_ctx_t anj_udp_cleanup_ctx
Definition anj_udp.h:40
anj_net_get_state_t anj_udp_get_state
Definition anj_udp.h:43
anj_net_queue_mode_rx_off_t anj_udp_queue_mode_rx_off
Definition anj_udp.h:44
anj_net_get_inner_mtu_t anj_udp_get_inner_mtu
Definition anj_udp.h:42
Global configuration validation header for Anjay Lite.
Definition anj_net_api.h:206