Anjay Lite
Loading...
Searching...
No Matches
anj_net_api.h
Go to the documentation of this file.
1/*
2 * Copyright 2023-2025 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
34#ifndef ANJ_NET_API_H
35# define ANJ_NET_API_H
36
37# include <stdbool.h>
38# include <stddef.h>
39# include <stdint.h>
40
41# ifdef __cplusplus
42extern "C" {
43# endif
44
45# ifdef ANJ_WITH_SECURITY
46# include <anj/compat/rng.h>
47# include <anj/crypto.h>
48# endif // ANJ_WITH_SECURITY
49
59# define ANJ_NET_OK (0)
60
66# define ANJ_NET_EAGAIN (1)
67
71# define ANJ_NET_EMSGSIZE (2)
72
77# define ANJ_NET_ENOTSUP (3)
78
85# define ANJ_NET_EINPROGRESS (4)
86
96
117
152
163
164# ifdef ANJ_WITH_SECURITY
169
174
175typedef struct {
176 void *empty;
178
186
187typedef struct {
193
194# ifdef ANJ_WITH_EXTERNAL_CRYPTO_STORAGE
199# endif // ANJ_WITH_EXTERNAL_CRYPTO_STORAGE
201# endif // ANJ_WITH_SECURITY
202
214typedef struct {
216# ifdef ANJ_WITH_SECURITY
218# endif // ANJ_WITH_SECURITY
220
221struct anj_net_ctx_struct;
222
235typedef struct anj_net_ctx_struct anj_net_ctx_t;
236
246static inline bool anj_net_is_ok(int res) {
247 return ANJ_NET_OK == res;
248}
249
260static inline bool anj_net_is_again(int res) {
261 return ANJ_NET_EAGAIN == res;
262}
263
277static inline bool anj_net_is_inprogress(int res) {
278 return ANJ_NET_EINPROGRESS == res;
279}
280
297 const anj_net_config_t *config);
298
312
331typedef int
332anj_net_connect_t(anj_net_ctx_t *ctx, const char *hostname, const char *port);
333
356 size_t *bytes_sent,
357 const uint8_t *buf,
358 size_t length);
359
380 size_t *bytes_received,
381 uint8_t *buf,
382 size_t length);
383
402
418
431 anj_net_socket_state_t *out_value);
432
445typedef int anj_net_get_inner_mtu_t(anj_net_ctx_t *ctx, int32_t *out_value);
446
479
480# ifdef __cplusplus
481}
482# endif
483
484#endif // ANJ_NET_API_H
int anj_net_get_state_t(anj_net_ctx_t *ctx, anj_net_socket_state_t *out_value)
Definition anj_net_api.h:430
#define ANJ_NET_EAGAIN
Definition anj_net_api.h:66
int anj_net_close_t(anj_net_ctx_t *ctx)
Definition anj_net_api.h:417
int anj_net_shutdown_t(anj_net_ctx_t *ctx)
Definition anj_net_api.h:401
static bool anj_net_is_ok(int res)
Check if a network operation succeeded.
Definition anj_net_api.h:246
anj_net_binding_type_t
Definition anj_net_api.h:89
@ ANJ_NET_BINDING_TCP
Definition anj_net_api.h:91
@ ANJ_NET_BINDING_TLS
Definition anj_net_api.h:93
@ ANJ_NET_BINDING_NON_IP
Definition anj_net_api.h:94
@ ANJ_NET_BINDING_DTLS
Definition anj_net_api.h:92
@ ANJ_NET_BINDING_UDP
Definition anj_net_api.h:90
anj_net_security_mode_t
Definition anj_net_api.h:165
@ ANJ_NET_SECURITY_PSK
Definition anj_net_api.h:166
@ ANJ_NET_SECURITY_CERTIFICATE
Definition anj_net_api.h:167
struct anj_net_ctx_struct anj_net_ctx_t
Opaque network context handle.
Definition anj_net_api.h:235
int anj_net_create_ctx_t(anj_net_ctx_t **ctx, const anj_net_config_t *config)
Definition anj_net_api.h:296
int anj_net_get_inner_mtu_t(anj_net_ctx_t *ctx, int32_t *out_value)
Definition anj_net_api.h:445
#define ANJ_NET_OK
Definition anj_net_api.h:59
int anj_net_recv_t(anj_net_ctx_t *ctx, size_t *bytes_received, uint8_t *buf, size_t length)
Definition anj_net_api.h:379
anj_net_socket_state_t
Definition anj_net_api.h:97
@ ANJ_NET_SOCKET_STATE_CONNECTED
Definition anj_net_api.h:115
@ ANJ_NET_SOCKET_STATE_CLOSED
Definition anj_net_api.h:102
@ ANJ_NET_SOCKET_STATE_SHUTDOWN
Definition anj_net_api.h:108
int anj_net_cleanup_ctx_t(anj_net_ctx_t **ctx)
Definition anj_net_api.h:311
int anj_net_connect_t(anj_net_ctx_t *ctx, const char *hostname, const char *port)
Definition anj_net_api.h:332
anj_net_address_family_setting_t
Definition anj_net_api.h:121
@ ANJ_NET_AF_SETTING_PREFERRED_INET4
Definition anj_net_api.h:144
@ ANJ_NET_AF_SETTING_FORCE_INET4
Definition anj_net_api.h:132
@ ANJ_NET_AF_SETTING_FORCE_INET6
Definition anj_net_api.h:138
@ ANJ_NET_AF_SETTING_PREFERRED_INET6
Definition anj_net_api.h:150
@ ANJ_NET_AF_SETTING_UNSPEC
Definition anj_net_api.h:126
static bool anj_net_is_again(int res)
Check if data was received.
Definition anj_net_api.h:260
#define ANJ_NET_EINPROGRESS
Definition anj_net_api.h:85
static bool anj_net_is_inprogress(int res)
Check if a network operation is in progress.
Definition anj_net_api.h:277
int anj_net_send_t(anj_net_ctx_t *ctx, size_t *bytes_sent, const uint8_t *buf, size_t length)
Definition anj_net_api.h:355
int anj_net_queue_mode_rx_off_t(anj_net_ctx_t *ctx)
Definition anj_net_api.h:478
Cryptographic data descriptors used by Security Object and networking.
Global configuration validation header for Anjay Lite.
Platform hook for providing randomness.
Definition crypto.h:101
Definition anj_net_api.h:175
void * empty
Definition anj_net_api.h:176
Definition anj_net_api.h:214
anj_net_socket_configuration_t raw_socket_config
Definition anj_net_api.h:215
anj_net_ssl_configuration_t secure_socket_config
Definition anj_net_api.h:217
Definition anj_net_api.h:170
anj_crypto_security_info_t key
Definition anj_net_api.h:171
anj_crypto_security_info_t identity
Definition anj_net_api.h:172
Definition anj_net_api.h:179
anj_net_certificate_info_t cert
Definition anj_net_api.h:183
anj_net_security_mode_t mode
Definition anj_net_api.h:180
anj_net_psk_info_t psk
Definition anj_net_api.h:182
Definition anj_net_api.h:156
anj_net_address_family_setting_t af_setting
Definition anj_net_api.h:161
Definition anj_net_api.h:187
void * crypto_ctx
Definition anj_net_api.h:198
anj_net_security_info_t security
Definition anj_net_api.h:192