|
Anjay Lite
|
Platform hooks for network transport integration. More...
#include <anj/init.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <anj/compat/rng.h>#include <anj/crypto.h>Go to the source code of this file.
Data Structures | |
| struct | anj_net_socket_configuration_t |
| struct | anj_net_psk_info_t |
| struct | anj_net_certificate_info_t |
| struct | anj_net_security_info_t |
| struct | anj_net_ssl_configuration_t |
| struct | anj_net_config_t |
Macros | |
Network API error codes | |
Specific error codes recognized by Anjay. Any other generic error must be indicated by a negative value. | |
| #define | ANJ_NET_OK (0) |
| #define | ANJ_NET_EAGAIN (1) |
| #define | ANJ_NET_EMSGSIZE (2) |
| #define | ANJ_NET_ENOTSUP (3) |
| #define | ANJ_NET_EINPROGRESS (4) |
Typedefs | |
| typedef struct anj_net_ctx_struct | anj_net_ctx_t |
| Opaque network context handle. | |
| typedef int | anj_net_create_ctx_t(anj_net_ctx_t **ctx, const anj_net_config_t *config) |
| typedef int | anj_net_cleanup_ctx_t(anj_net_ctx_t **ctx) |
| typedef int | anj_net_connect_t(anj_net_ctx_t *ctx, const char *hostname, const char *port) |
| typedef int | anj_net_send_t(anj_net_ctx_t *ctx, size_t *bytes_sent, const uint8_t *buf, size_t length) |
| typedef int | anj_net_recv_t(anj_net_ctx_t *ctx, size_t *bytes_received, uint8_t *buf, size_t length) |
| typedef int | anj_net_shutdown_t(anj_net_ctx_t *ctx) |
| typedef int | anj_net_close_t(anj_net_ctx_t *ctx) |
| typedef int | anj_net_get_state_t(anj_net_ctx_t *ctx, anj_net_socket_state_t *out_value) |
| typedef int | anj_net_get_inner_mtu_t(anj_net_ctx_t *ctx, int32_t *out_value) |
| typedef int | anj_net_queue_mode_rx_off_t(anj_net_ctx_t *ctx) |
Functions | |
| static bool | anj_net_is_ok (int res) |
| Check if a network operation succeeded. | |
| static bool | anj_net_is_again (int res) |
| Check if data was received. | |
| static bool | anj_net_is_inprogress (int res) |
| Check if a network operation is in progress. | |
Platform hooks for network transport integration.
This header declares the minimal socket-like API that platform integrators must implement to let Anjay Lite communicate over UDP, TCP, DTLS, TLS or some Non-IP transport.
The API covers:
Security (PSK / certificates) is supported if ANJ_WITH_SECURITY is enabled. The functions are designed to be non-blocking, with retry signaled by returning ANJ_NET_EINPROGRESS.
Implementations typically wrap system sockets, modem AT command layers, or RTOS/BSP networking stacks.
| #define ANJ_NET_EAGAIN (1) |
A code indicating that no data is currently available to be received. The caller should retry the function with the same parameters. This does not need to occur immediately, other operations might be executed first.
| #define ANJ_NET_EINPROGRESS (4) |
A code indicating that the operation cannot be performed immediately. This may occur when the underlying operation is still in progress (e.g., ongoing communication with a cellular modem). To properly complete the operation, the caller must retry the function with the same parameters.
| #define ANJ_NET_EMSGSIZE (2) |
Message too long.
| #define ANJ_NET_ENOTSUP (3) |
Operation not supported. This indicates that the function is either not implemented or that the provided arguments are not supported.
| #define ANJ_NET_OK (0) |
Error code indicating success.
| typedef int anj_net_cleanup_ctx_t(anj_net_ctx_t **ctx) |
Calls shutdown on the connection associated with ctx, cleans up the ctx context, and sets it to NULL.
| [in,out] | ctx | Connection context to clean up. |
| typedef int anj_net_close_t(anj_net_ctx_t *ctx) |
Shuts down the connection associated with ctx. No further communication is allowed using this context. Discards any buffered but not yet processed data.
ctx may later be reused by calling anj_net_connect again.
| ctx | Communication context to close. |
| typedef int anj_net_connect_t(anj_net_ctx_t *ctx, const char *hostname, const char *port) |
This function connects to a server specified by the hostname and port parameters. If the specific binding being used does not require these parameters, the user should pass NULL instead.
| ctx | Pointer to a socket context. |
| hostname | Target host name to connect to. |
| port | Target port of the server. |
| typedef int anj_net_create_ctx_t(anj_net_ctx_t **ctx, const anj_net_config_t *config) |
Initializes a communication context for a connection.
If a valid config pointer is supplied, it is used to configure the context; otherwise, a NULL pointer is acceptable.
| [out] | ctx | Created socket context. |
| config | Optional configuration for initializing the socket context. |
| typedef struct anj_net_ctx_struct anj_net_ctx_t |
Opaque network context handle.
This type represents a network context object used internally by the networking layer. Its definition is intentionally hidden and implementation- specific. Applications should only work with pointers to anj_net_ctx_t obtained from API functions such as anj_net_create_ctx, and never attempt to access or modify its contents directly.
On the implementation side, anj_net_ctx_t is cast to a backend-specific structure.
| typedef int anj_net_get_inner_mtu_t(anj_net_ctx_t *ctx, int32_t *out_value) |
Returns the maximum size of a buffer that can be passed to anj_net_send and transmitted as a single packet.
| ctx | Pointer to a socket context. | |
| [out] | out_value | Retrieved option value. |
| typedef int anj_net_get_state_t(anj_net_ctx_t *ctx, anj_net_socket_state_t *out_value) |
Returns the current state of the socket context.
| ctx | Pointer to a socket context. | |
| [out] | out_value | Retrieved option value. |
| typedef int anj_net_queue_mode_rx_off_t(anj_net_ctx_t *ctx) |
Hints the transport that the client is entering LwM2M Queue Mode and will not need to receive application data until it initiates the next outgoing exchange. Implementations may use this to reduce power consumption (e.g., disable RX path / radio) while keeping the connection context valid.
Requirements:
ctx. Subsequent calls to anj_net_send / anj_net_recv and others must still be possible.Non-blocking semantics:
| ctx | Pointer to a transport context. |
| typedef int anj_net_recv_t(anj_net_ctx_t *ctx, size_t *bytes_received, uint8_t *buf, size_t length) |
This function receives data from the specified connection context. If data is available, it is stored in the provided buffer, and bytes_received indicates the number of bytes received.
| ctx | Pointer to a socket context. | |
| [out] | bytes_received | Output parameter indicating the number of bytes received. |
| [out] | buf | Pointer to the message buffer. |
| length | Size of the provided buffer. |
| typedef int anj_net_send_t(anj_net_ctx_t *ctx, size_t *bytes_sent, const uint8_t *buf, size_t length) |
This function sends the provided data through the given connection context.
If no data has been sent, the function returns ANJ_NET_EINPROGRESS. However, if some (all) data has been successfully sent, the function returns ANJ_NET_OK, and bytes_sent will indicate the amount of data transmitted. The caller should then retry the operation with the remaining data until all bytes are sent.
| ctx | Pointer to a socket context. | |
| [out] | bytes_sent | Number of bytes sent. |
| buf | Pointer to the message buffer. | |
| length | Length of the data in the message buffer. |
| typedef int anj_net_shutdown_t(anj_net_ctx_t *ctx) |
Shuts down the connection associated with ctx. No further communication is allowed using this context. Any buffered but not yet processed data should still be delivered. Performs the termination handshake if the protocol used requires one.
Data already received can still be read using anj_net_recv. However, the user must call anj_net_close before reusing the context.
| ctx | Communication context to shut down. |
Address family preference when creating a network socket.
| Enumerator | |
|---|---|
| ANJ_NET_SOCKET_STATE_CLOSED | Socket is either newly constructed, or it has been closed by calling anj_net_close. |
| ANJ_NET_SOCKET_STATE_SHUTDOWN | Socket was previously in ANJ_NET_SOCKET_STATE_CONNECTED state, and anj_net_shutdown was called. |
| ANJ_NET_SOCKET_STATE_CONNECTED | anj_net_connect has been called. The socket is connected to some specific server. It is ready for anj_net_send and anj_net_recv operations. |
|
inlinestatic |
Check if data was received.
Convenience function that tests whether the result code of a network operation equals ANJ_NET_EAGAIN.
| res | Result code returned by a networking API call. |
true if res equals ANJ_NET_EAGAIN, false otherwise.
|
inlinestatic |
Check if a network operation is in progress.
Convenience function that tests whether the result code of a network operation equals ANJ_NET_EINPROGRESS.
This indicates thst the operation requires a repeated call, without any other anj_net_* calls being performed in between.
| res | Result code returned by a networking API call. |
true if res indicates a retryable condition, false otherwise.
|
inlinestatic |
Check if a network operation succeeded.
Convenience function that tests whether the result code of a network operation equals ANJ_NET_OK.
| res | Result code returned by a networking API call. |
true if res indicates success, false otherwise.