anjay
core.h File Reference
#include <stdint.h>
#include <avsystem/coap/udp.h>
#include <avsystem/commons/avs_list.h>
#include <avsystem/commons/avs_net.h>
#include <avsystem/commons/avs_prng.h>
#include <avsystem/commons/avs_sched.h>
#include <avsystem/commons/avs_stream.h>
#include <avsystem/commons/avs_time.h>
#include <anjay/anjay_config.h>

Go to the source code of this file.

Data Structures

struct  anjay_configuration
 
struct  anjay_socket_entry_t
 
struct  anjay_transport_set_t
 
struct  anjay_security_config_t
 

Macros

#define ANJAY_SSID_ANY   0
 
#define ANJAY_SSID_BOOTSTRAP   UINT16_MAX
 
#define ANJAY_COAP_DEFAULT_UDP_TX_PARAMS
 
#define ANJAY_DTLS_DEFAULT_UDP_HS_TX_PARAMS
 
#define ANJAY_ID_INVALID   UINT16_MAX
 
#define ANJAY_COAP_STATUS(Maj, Min)   ((uint8_t) ((Maj << 5) | (Min & 0x1F)))
 
#define ANJAY_ERR_BAD_REQUEST   (-ANJAY_COAP_STATUS(4, 0))
 
#define ANJAY_ERR_UNAUTHORIZED   (-ANJAY_COAP_STATUS(4, 1))
 
#define ANJAY_ERR_BAD_OPTION   (-ANJAY_COAP_STATUS(4, 2))
 
#define ANJAY_ERR_FORBIDDEN   (-ANJAY_COAP_STATUS(4, 3))
 
#define ANJAY_ERR_NOT_FOUND   (-ANJAY_COAP_STATUS(4, 4))
 
#define ANJAY_ERR_METHOD_NOT_ALLOWED   (-ANJAY_COAP_STATUS(4, 5))
 
#define ANJAY_ERR_NOT_ACCEPTABLE   (-ANJAY_COAP_STATUS(4, 6))
 
#define ANJAY_ERR_REQUEST_ENTITY_INCOMPLETE   (-ANJAY_COAP_STATUS(4, 8))
 
#define ANJAY_ERR_UNSUPPORTED_CONTENT_FORMAT   (-ANJAY_COAP_STATUS(4, 15))
 
#define ANJAY_ERR_INTERNAL   (-ANJAY_COAP_STATUS(5, 0))
 
#define ANJAY_ERR_NOT_IMPLEMENTED   (-ANJAY_COAP_STATUS(5, 1))
 
#define ANJAY_ERR_SERVICE_UNAVAILABLE   (-ANJAY_COAP_STATUS(5, 3))
 

Typedefs

typedef uint16_t anjay_ssid_t
 
typedef struct anjay_struct anjay_t
 
typedef struct anjay_configuration anjay_configuration_t
 
typedef uint16_t anjay_oid_t
 
typedef uint16_t anjay_iid_t
 
typedef uint16_t anjay_rid_t
 
typedef uint16_t anjay_riid_t
 

Enumerations

enum  anjay_socket_transport_t { ANJAY_SOCKET_TRANSPORT_INVALID = -1 , ANJAY_SOCKET_TRANSPORT_UDP = 0 , ANJAY_SOCKET_TRANSPORT_TCP }
 

Functions

const char * anjay_get_version (void)
 
anjay_tanjay_new (const anjay_configuration_t *config)
 
void anjay_delete (anjay_t *anjay)
 
AVS_LIST[avs_net_socket_t *const] anjay_get_sockets (anjay_t *anjay)
 
AVS_LIST[const anjay_socket_entry_tanjay_get_socket_entries (anjay_t *anjay)
 
int anjay_serve (anjay_t *anjay, avs_net_socket_t *ready_socket)
 
avs_sched_t * anjay_get_scheduler (anjay_t *anjay)
 
int anjay_sched_time_to_next (anjay_t *anjay, avs_time_duration_t *out_delay)
 
int anjay_sched_time_to_next_ms (anjay_t *anjay, int *out_delay_ms)
 
int anjay_sched_calculate_wait_time_ms (anjay_t *anjay, int limit_ms)
 
void anjay_sched_run (anjay_t *anjay)
 
int anjay_event_loop_run (anjay_t *anjay, avs_time_duration_t max_wait_time)
 
int anjay_event_loop_interrupt (anjay_t *anjay)
 
int anjay_serve_any (anjay_t *anjay, avs_time_duration_t max_wait_time)
 
int anjay_schedule_registration_update (anjay_t *anjay, anjay_ssid_t ssid)
 
int anjay_disable_server (anjay_t *anjay, anjay_ssid_t ssid)
 
int anjay_disable_server_with_timeout (anjay_t *anjay, anjay_ssid_t ssid, avs_time_duration_t timeout)
 
int anjay_enable_server (anjay_t *anjay, anjay_ssid_t ssid)
 
bool anjay_transport_is_offline (anjay_t *anjay, anjay_transport_set_t transport_set)
 
int anjay_transport_enter_offline (anjay_t *anjay, anjay_transport_set_t transport_set)
 
int anjay_transport_exit_offline (anjay_t *anjay, anjay_transport_set_t transport_set)
 
int anjay_transport_set_online (anjay_t *anjay, anjay_transport_set_t transport_set)
 
int anjay_transport_schedule_reconnect (anjay_t *anjay, anjay_transport_set_t transport_set)
 
bool anjay_all_connections_failed (anjay_t *anjay)
 
int anjay_security_config_from_dm (anjay_t *anjay, anjay_security_config_t *out_config, const char *uri)
 
bool anjay_ongoing_registration_exists (anjay_t *anjay)
 

Variables

const anjay_transport_set_t ANJAY_TRANSPORT_SET_ALL
 
const anjay_transport_set_t ANJAY_TRANSPORT_SET_IP
 
const anjay_transport_set_t ANJAY_TRANSPORT_SET_UDP
 
const anjay_transport_set_t ANJAY_TRANSPORT_SET_TCP
 

Macro Definition Documentation

◆ ANJAY_COAP_DEFAULT_UDP_TX_PARAMS

#define ANJAY_COAP_DEFAULT_UDP_TX_PARAMS
Value:
{ \
/* .ack_timeout = */ { 2, 0 }, \
/* .ack_random_factor = */ 1.5, \
/* .max_retransmit = */ 4, \
/* .nstart = */ 1 \
}

Default transmission params recommended by the CoAP specification (RFC 7252).

◆ ANJAY_COAP_STATUS

#define ANJAY_COAP_STATUS (   Maj,
  Min 
)    ((uint8_t) ((Maj << 5) | (Min & 0x1F)))

Helper macro used to define ANJAY_ERR_ constants. Generated values are valid CoAP Status Codes encoded as a single byte.

◆ ANJAY_DTLS_DEFAULT_UDP_HS_TX_PARAMS

#define ANJAY_DTLS_DEFAULT_UDP_HS_TX_PARAMS
Value:
{ \
/* .min = */ { 1, 0 }, \
/* .max = */ { 60, 0 } \
}

Default handshake retransmission params recommended by the DTLS specification (RFC 6347), i.e: 1s for the initial response, growing exponentially (with each retransmission) up to maximum of 60s.

◆ ANJAY_ERR_BAD_OPTION

#define ANJAY_ERR_BAD_OPTION   (-ANJAY_COAP_STATUS(4, 2))

Low-level CoAP error code; used internally by Anjay when CoAP option values were invalid.

◆ ANJAY_ERR_BAD_REQUEST

#define ANJAY_ERR_BAD_REQUEST   (-ANJAY_COAP_STATUS(4, 0))

Error values that may be returned from data model handlers. Request sent by the LwM2M Server was malformed or contained an invalid value.

◆ ANJAY_ERR_FORBIDDEN

#define ANJAY_ERR_FORBIDDEN   (-ANJAY_COAP_STATUS(4, 3))

◆ ANJAY_ERR_INTERNAL

#define ANJAY_ERR_INTERNAL   (-ANJAY_COAP_STATUS(5, 0))

Unspecified error, no other error code was suitable.

◆ ANJAY_ERR_METHOD_NOT_ALLOWED

#define ANJAY_ERR_METHOD_NOT_ALLOWED   (-ANJAY_COAP_STATUS(4, 5))

Operation is not allowed in current device state or the attempted operation is invalid for this target (Object/Instance/Resource)

◆ ANJAY_ERR_NOT_ACCEPTABLE

#define ANJAY_ERR_NOT_ACCEPTABLE   (-ANJAY_COAP_STATUS(4, 6))

Low-level CoAP error code; used internally by Anjay when the client is unable to encode response in requested content format.

◆ ANJAY_ERR_NOT_FOUND

#define ANJAY_ERR_NOT_FOUND   (-ANJAY_COAP_STATUS(4, 4))

Target of the operation (Object/Instance/Resource) does not exist.

◆ ANJAY_ERR_NOT_IMPLEMENTED

#define ANJAY_ERR_NOT_IMPLEMENTED   (-ANJAY_COAP_STATUS(5, 1))

Operation is not implemented by the LwM2M Client.

◆ ANJAY_ERR_REQUEST_ENTITY_INCOMPLETE

#define ANJAY_ERR_REQUEST_ENTITY_INCOMPLETE   (-ANJAY_COAP_STATUS(4, 8))

Low-level CoAP error code; used internally by Anjay in case of unrecoverable problems during block-wise transfer.

◆ ANJAY_ERR_SERVICE_UNAVAILABLE

#define ANJAY_ERR_SERVICE_UNAVAILABLE   (-ANJAY_COAP_STATUS(5, 3))

LwM2M Client is busy processing some other request; LwM2M Server may retry sending the same request after some delay.

◆ ANJAY_ERR_UNAUTHORIZED

#define ANJAY_ERR_UNAUTHORIZED   (-ANJAY_COAP_STATUS(4, 1))

LwM2M Server is not allowed to perform the operation due to lack of necessary access rights.

◆ ANJAY_ERR_UNSUPPORTED_CONTENT_FORMAT

#define ANJAY_ERR_UNSUPPORTED_CONTENT_FORMAT   (-ANJAY_COAP_STATUS(4, 15))

The server requested operation has a Content Format option that is unsupported by Anjay.

◆ ANJAY_ID_INVALID

#define ANJAY_ID_INVALID   UINT16_MAX

Value reserved by the LwM2M spec for all kinds of IDs (Object IDs, Object Instance IDs, Resource IDs, Resource Instance IDs, Short Server IDs).

◆ ANJAY_SSID_ANY

#define ANJAY_SSID_ANY   0

A constant that may be used in anjay_schedule_registration_update call instead of Short Server ID to send Update messages to all connected servers.

◆ ANJAY_SSID_BOOTSTRAP

#define ANJAY_SSID_BOOTSTRAP   UINT16_MAX

An SSID value reserved by LwM2M to refer to the Bootstrap Server. NOTE: The value of a "Short Server ID" Resource in the Security Object Instance referring to the Bootstrap Server is irrelevant and cannot be used to identify the Bootstrap Server.

Typedef Documentation

◆ anjay_configuration_t

◆ anjay_iid_t

typedef uint16_t anjay_iid_t

Object Instance ID

◆ anjay_oid_t

typedef uint16_t anjay_oid_t

Object ID

◆ anjay_rid_t

typedef uint16_t anjay_rid_t

Resource ID

◆ anjay_riid_t

typedef uint16_t anjay_riid_t

Resource Instance ID

◆ anjay_ssid_t

typedef uint16_t anjay_ssid_t

Short Server ID type.

◆ anjay_t

typedef struct anjay_struct anjay_t

Anjay object containing all information required for LwM2M communication.

Enumeration Type Documentation

◆ anjay_socket_transport_t

Enumerator
ANJAY_SOCKET_TRANSPORT_INVALID 
ANJAY_SOCKET_TRANSPORT_UDP 
ANJAY_SOCKET_TRANSPORT_TCP 

Function Documentation

◆ anjay_all_connections_failed()

bool anjay_all_connections_failed ( anjay_t anjay)

Tests if Anjay gave up on any further server connection attempts. It will happen if none of the configured servers could be reached.

If this function returns true, it means that Anjay is in an essentially non-operational state. anjay_schedule_reconnect may be called to reset the failure state and retry connecting to all configured servers. anjay_transport_schedule_reconnect will do the same, but only for the specified transports. Alternatively, anjay_enable_server may be used to retry connection only to a specific server.

Parameters
anjayAnjay object to operate on.
Returns
0 on success, a negative value in case of error.

◆ anjay_delete()

void anjay_delete ( anjay_t anjay)

Cleans up all resources and releases the Anjay object.

NOTE: It shall be called before freeing LwM2M Objects registered within the anjay object.

Parameters
anjayAnjay object to delete. MUST NOT be NULL .

◆ anjay_disable_server()

int anjay_disable_server ( anjay_t anjay,
anjay_ssid_t  ssid 
)

This function shall be called when an LwM2M Server Object shall be disabled. The standard case for this is when Execute is performed on the Disable resource (/1/x/4).

The server will be disabled for the period of time determined by the value of the Disable Timeout resource (/1/x/5). The resource is read soon after the invocation of this function (during next anjay_sched_run) and is not updated upon any subsequent Writes to that resource.

Parameters
anjayAnjay object to operate on.
ssidShort Server ID of the server to put in a disabled state. NOTE: disabling a server requires a Server Object Instance to be present for given ssid . Because the Bootstrap Server does not have one, this function does nothing when called with ANJAY_SSID_BOOTSTRAP .
Returns
0 on success, a negative value in case of error.

◆ anjay_disable_server_with_timeout()

int anjay_disable_server_with_timeout ( anjay_t anjay,
anjay_ssid_t  ssid,
avs_time_duration_t  timeout 
)

This function shall be called when an LwM2M Server Object shall be disabled. The standard case for this is when Execute is performed on the Disable resource (/1/x/4). It may also be used to prevent reconnections if the server becomes unreachable.

The server will become disabled during next anjay_sched_run call.

NOTE: disabling a server with dual binding (e.g. UDP+SMS trigger) closes both communication channels. Shutting down only one of them requires changing the Binding Resource in Server object.

Parameters
anjayAnjay object to operate on.
ssidShort Server ID of the server to put in a disabled state.
timeoutDisable timeout. If set to AVS_TIME_DURATION_INVALID, the server will remain disabled until explicit call to anjay_enable_server . Otherwise, the server will get enabled automatically after timeout .
Returns
0 on success, a negative value in case of error.

◆ anjay_enable_server()

int anjay_enable_server ( anjay_t anjay,
anjay_ssid_t  ssid 
)

Schedules a job for re-enabling a previously disabled (with a call to anjay_disable_server_with_timeout ) server. The server will be enabled during next anjay_sched_run call.

Parameters
anjayAnjay object to operate on.
ssidShort Server ID of the server to enable.
Returns
0 on success, a negative value in case of error.

◆ anjay_event_loop_interrupt()

int anjay_event_loop_interrupt ( anjay_t anjay)

Interrupts an ongoing execution of anjay_event_loop_run.

This function may be called from another thread, or from a callback running within the event loop itself.

After the call to this function, the event loop will finish as soon as possible while gracefully executing any outstanding tasks.

Please note that the event loop may not be interrupted immediately and instead wait until either of the following:

  • any ongoing scheduler tasks finish
  • any incoming RPC involving a blockwise transfer finishes
  • the poll or select() operation finishes (see the max_wait_time argument to anjay_event_loop_run)

Interrupting the two latter cases may be possible by performing a system-specific call that would interrupt ongoing socket operations (e.g. raising a signal with an appropriately crafted signal handler on Unix-like systems) immediately after having called anjay_event_loop_interrupt().

Parameters
anjayAnjay object to operate on.
Returns
0 if the interrupt has been successfully raised, or a negative value if the event loop is either not running or already in the process of finishing due to a previous interrupt.

Please note that this function always returns immediately, without waiting for the event loop to actually finish. Please use an appropriate system API (e.g. pthread_join() on Unix-like systems) if you need to ensure that the event loop has finished.

◆ anjay_event_loop_run()

int anjay_event_loop_run ( anjay_t anjay,
avs_time_duration_t  max_wait_time 
)

Runs Anjay's main event loop that executes anjay_serve and anjay_sched_run as appropriate.

This function will only return after either:

  • anjay_event_loop_interrupt is called (from a different thread or from a user callback), or
  • a fatal error (e.g. out-of-memory) occurs in the loop itself (errors from anjay_serve are not considered fatal)

IMPORTANT: The preimplemented event loop is primarily intended to be run in a dedicated thread, while other threads may handle tasks not related to LwM2M. It is safe to control the same instance of Anjay concurrently from a different thread only if the thread safety features have been enabled at Anjay's compile time:

  • AVS_COMMONS_SCHED_THREAD_SAFE (WITH_SCHEDULER_THREAD_SAFE in CMake) is required to safely use Anjay's internal scheduler (see anjay_get_scheduler)
    • Please note that only managing scheduler tasks from another thread is safe. Attempting to call anjay_sched_run (or avs_sched_run(anjay_get_scheduler(anjay)) while the event loop is running may lead to undefined behavior in the loop
  • ANJAY_WITH_THREAD_SAFETY (WITH_THREAD_SAFETY in CMake) is required to call any other functions, aside from the cleanup functions (which are only safe to call after the event loop has finished) and anjay_event_loop_interrupt (which is always safe to call)

CAUTION: The preimplemented event loop will only work if all the sockets that may be created by Anjay will return file descriptors compatible with poll() or select() through avs_net_socket_get_system().

In particular, please be cautious when using SMS or NIDD transports (applicable to commercial version only) - your anjay_smsdrv_system_socket_t and anjay_nidd_driver_system_descriptor_t functions need to populate the output argument with a valid file descriptor (e.g. int fd = ...; *out = ), and that file descriptor must be valid to use with the poll() or select() functions (which may not true if the socket API is separate from other IO APIs, as is the case e.g. on Windows). Otherwise attempting to use this event loop implementation will not handle NIDD and SMS transports properly, and may even lead to undefined behavior.

Parameters
anjayAnjay object to operate on.
max_wait_timeMaximum time to spend in each single call to poll() or select(). Larger times will prevent the event loop thread from waking up too frequently. However, during this wait time, the call to anjay_event_loop_interrupt may not be handled immediately, and scheduler jobs requested from other threads (see anjay_get_scheduler) will not be executed, so shortening this time will make the scheduler more responsive.
Returns
0 after having been successfully interrupted by anjay_event_loop_interrupt, or a negative value in case of a fatal error.

◆ anjay_get_scheduler()

avs_sched_t* anjay_get_scheduler ( anjay_t anjay)

Extracts the scheduler used by Anjay allowing the user to schedule his own tasks.

See docs of avs_commons library for API of avs_sched_t object.

Must not use avs_sched_cleanup on the returned scheduler. Anjay will cleanup it itself.

Parameters
anjayAnjay object to operate on.
Returns
non-null scheduler object used by Anjay.

◆ anjay_get_socket_entries()

AVS_LIST [ const anjay_socket_entry_t ] anjay_get_socket_entries ( anjay_t anjay)

Retrieves a list of structures that describe sockets used for communication with LwM2M servers. Returned list must not be freed nor modified.

The returned data is equivalent to the one that can be retrieved using anjay_get_sockets - but includes additional data that describes the socket in addition to the socket itself. See anjay_socket_entry_t for details.

Parameters
anjayAnjay object to operate on.
Returns
A list of valid server socket entries on success, NULL when the device is not connected to any server.

◆ anjay_get_sockets()

AVS_LIST [ avs_net_socket_t *const ] anjay_get_sockets ( anjay_t anjay)

Retrieves a list of sockets used for communication with LwM2M servers. Returned list must not be freed nor modified.

Example usage: poll()-based application loop

struct pollfd poll_fd = { .events = POLLIN, .fd = -1 };
while (true) {
AVS_LIST(avs_net_socket_t*) sockets = anjay_get_sockets(anjay);
if (sockets) {
// assuming there is only one socket
poll_fd.fd = *(const int*)avs_net_socket_get_system(*sockets);
} else {
// sockets not initialized yet
poll_fd.fd = -1;
}
if (poll(&poll_fd, 1, 1000) > 0) {
if (poll_fd.revents & POLLIN) {
if (anjay_serve(anjay, *sockets)) {
log("anjay_serve failed");
}
}
}
}
int anjay_serve(anjay_t *anjay, avs_net_socket_t *ready_socket)
AVS_LIST[avs_net_socket_t *const] anjay_get_sockets(anjay_t *anjay)
Parameters
anjayAnjay object to operate on.
Returns
A list of valid server sockets on success, NULL when the device is not connected to any server.

◆ anjay_get_version()

const char* anjay_get_version ( void  )
Returns
pointer to the string representing current version of the library.

◆ anjay_new()

anjay_t* anjay_new ( const anjay_configuration_t config)

Creates a new Anjay object.

Parameters
configInitial configuration. For details, see anjay_configuration_t .
Returns
Created Anjay object on success, NULL in case of error.

◆ anjay_ongoing_registration_exists()

bool anjay_ongoing_registration_exists ( anjay_t anjay)

Returns false if registration to all LwM2M Servers either succeeded or failed with no more retries pending and true if a registration or bootstrap is in progress.

◆ anjay_sched_calculate_wait_time_ms()

int anjay_sched_calculate_wait_time_ms ( anjay_t anjay,
int  limit_ms 
)

Calculates time in milliseconds the client code may wait for incoming events before the need to call anjay_sched_run .

This function combines anjay_sched_time_to_next_ms with a user-provided limit, so that a conclusive value will always be returned. It is provided as a convenience for users of system calls such as poll().

Parameters
anjayAnjay object to operate on.
limit_msThe longest amount of time the function shall return.
Returns
Relative time from now of next scheduled task, in milliseconds, if such task exists and it's scheduled to run earlier than limit_ms seconds from now, or limit_ms otherwise.

◆ anjay_sched_run()

void anjay_sched_run ( anjay_t anjay)

Runs all scheduled events which need to be invoked at or before the time of this function invocation.

Parameters
anjayAnjay object to operate on.

◆ anjay_sched_time_to_next()

int anjay_sched_time_to_next ( anjay_t anjay,
avs_time_duration_t *  out_delay 
)

Determines time of next scheduled task.

May be used to determine how long the device may wait before calling anjay_sched_run .

Parameters
anjayAnjay object to operate on.
[out]out_delayRelative time from now of next scheduled task.
Returns
0 on success, or a negative value if no tasks are scheduled.

◆ anjay_sched_time_to_next_ms()

int anjay_sched_time_to_next_ms ( anjay_t anjay,
int *  out_delay_ms 
)

Determines time of next scheduled task in milliseconds.

This function is equivalent to anjay_sched_time_to_next but, as a convenience for users of system calls such as poll(), the result is returned as a single integer number of milliseconds.

Parameters
anjayAnjay object to operate on.
[out]out_delay_msRelative time from now of next scheduled task, in milliseconds.
Returns
0 on success, or a negative value if no tasks are scheduled.

◆ anjay_schedule_registration_update()

int anjay_schedule_registration_update ( anjay_t anjay,
anjay_ssid_t  ssid 
)

Schedules sending an Update message to the server identified by given Short Server ID.

The Update will be sent during the next anjay_sched_run call.

Note: This function will not schedule registration update if Anjay is in offline mode.

Parameters
anjayAnjay object to operate on.
ssidShort Server ID of the server to send Update to or ANJAY_SSID_ANY to send Updates to all connected servers. NOTE: Since Updates are not useful for the Bootstrap Server, this function does not send one for ANJAY_SSID_BOOTSTRAP ssid .
Returns
0 on success, a negative value in case of error.

◆ anjay_security_config_from_dm()

int anjay_security_config_from_dm ( anjay_t anjay,
anjay_security_config_t out_config,
const char *  uri 
)

Queries security configuration appropriate for a specified URI.

Given a URI, the Security object is scanned for instances with Server URI resource matching it in the following way:

  • if there is at least one instance with matching hostname, protocol and port number, and valid secure connection configuration, the first such instance (in the order as returned via anjay_dm_list_instances_t) is used
  • otherwise, if there is at least one instance with matching hostname and valid secure connection configuration, the first such instance (in the order as returned via anjay_dm_list_instances_t) is used

The returned security information is exactly the same configuration that is used for LwM2M connection with the server chosen with the rules described above.

Parameters
anjayAnjay object whose data model shall be queried.
out_configPointer to an anjay_security_config_t structure that will be filled with the appropriate information, if found.
uriURI for which to find security configuration.
Returns
0 for success, or a negative value in case of error, including if no suitable LwM2M Security Object instance could be found.

NOTE: The returned structure will contain pointers to buffers allocated within the anjay object. They will only be valid until next call to anjay_security_config_from_dm() or anjay_serve. Note that this is enough for direct use in anjay_fw_update_get_security_config_t implementations. If you need this information for a longer period, you will need to manually create a deep copy.

◆ anjay_serve()

int anjay_serve ( anjay_t anjay,
avs_net_socket_t *  ready_socket 
)

Reads a message from given ready_socket and handles it appropriately.

Initially, the receive method on the underlying socket is called with receive timeout set to zero. Subsequent receive requests may block with non-zero timeout values when e.g. waiting for retransmissions or subsequent BLOCK chunks - this is necessary to hide this complexity from the user callbacks in streaming mode.

This function may handle more than one request at once. Upon successful return, it is guaranteed that there is no more data to be received on the socket at the moment.

Parameters
anjayAnjay object to operate on.
ready_socketA socket to read the message from.
Returns
0 on success, a negative value in case of error. Note that it includes non-fatal errors, such as receiving a malformed packet.

◆ anjay_serve_any()

int anjay_serve_any ( anjay_t anjay,
avs_time_duration_t  max_wait_time 
)

Executes select() or poll() on all sockets currently in use and calls anjay_serve if appropriate.

This is intended as a building block for custom event loops. In particular, this code:

while (true) { anjay_serve_any(anjay, max_wait_time); anjay_sched_run(anjay); }

is equivalent to anjay_event_loop_run(anjay, max_wait_time), as long as anjay_event_loop_interrupt is never called.

CAUTION: Most of the caveats described in the documentation for anjay_event_loop_run also apply to this function. Please refer there for more information.

Parameters
anjayAnjay object to operate on.
max_wait_timeMaximum time to spend in poll() or select().
Returns
0 for success, or a negative value in case of a fatal error. Please note that errors from anjay_serve are not considered fatal.

◆ anjay_transport_enter_offline()

int anjay_transport_enter_offline ( anjay_t anjay,
anjay_transport_set_t  transport_set 
)

Puts all the transports specified by transport_set into offline mode. This should be done when the connectivity for these transports is deemed unavailable or lost.

During subsequent calls to anjay_sched_run, Anjay will close all of the sockets corresponding to the specified transport and stop attempting to make any contact with remote hosts over it, until a call to anjay_transport_exit_offline for any of the corresponding transports.

Note that offline mode also affects downloads. E.g., putting the TCP transport into offline mode will pause all ongoing downloads over TCP and prevent new such download requests from being performed.

User code shall still interface normally with the library, even if all the transports are in the offline state. This include regular calls to anjay_sched_run. Notifications (as reported using anjay_notify_changed and anjay_notify_instances_changed) continue to be tracked, and may be sent after reconnecting, depending on values of the "Notification Storing When Disabled or Offline" resource.

Parameters
anjayAnjay object to operate on.
transport_setSet of transports to put into offline mode.
Returns
0 on success, a negative value in case of error.

◆ anjay_transport_exit_offline()

int anjay_transport_exit_offline ( anjay_t anjay,
anjay_transport_set_t  transport_set 
)

Puts all the transports specified by transport_set back into online mode, if any of them were previously put into offline mode using anjay_transport_enter_offline.

Transports that are unavailable due to compile-time or runtime configuration are ignored.

During subsequent calls to anjay_sched_run, new connections to all LwM2M servers disconnected due to offline mode will be attempted, and Register or Registration Update messages will be sent as appropriate. Downloads paused due to offline mode will be resumed as well.

Parameters
anjayAnjay object to operate on.
transport_setSet of transports to put into online mode.
Returns
0 on success, a negative value in case of error.

◆ anjay_transport_is_offline()

bool anjay_transport_is_offline ( anjay_t anjay,
anjay_transport_set_t  transport_set 
)

Checks whether all the specified transports are in offline mode.

Parameters
anjayAnjay object to operate on.
transport_setSet of transports to check.
Returns
true if all of the transports speicifed by transport_set are in offline mode, false otherwise

◆ anjay_transport_schedule_reconnect()

int anjay_transport_schedule_reconnect ( anjay_t anjay,
anjay_transport_set_t  transport_set 
)

Reconnects sockets associated with all servers and ongoing downloads over the specified transports. Should be called if something related to the connectivity over those transports changes.

The reconnection will be performed during the next anjay_sched_run call and will trigger sending any messages necessary to maintain valid registration (DTLS session resumption and/or Register or Update RPCs).

In case of ongoing downloads (started via anjay_download or the fw_update module), if the reconnection fails, the download will be aborted with an error.

Note: This function puts all the transports in transport_set into online mode.

Parameters
anjayAnjay object to operate on.
transport_setSet of transports whose sockets shall be reconnected.
Returns
0 on success, a negative value in case of error.

◆ anjay_transport_set_online()

int anjay_transport_set_online ( anjay_t anjay,
anjay_transport_set_t  transport_set 
)

Puts all the transports that are enabled through the compile-time and runtime configuration, and specified in transport_set, into online mode. At the same time, puts all the other transports into offline mode.

This function combines the functionality of anjay_transport_enter_offline and anjay_transport_exit_offline into a single function. See their documentation for details about the semantics of online and offline modes.

Parameters
anjayAnjay object to operate on.
transport_setSet of transports to put into online mode.
Returns
0 on success, a negative value in case of error.

Variable Documentation

◆ ANJAY_TRANSPORT_SET_ALL

const anjay_transport_set_t ANJAY_TRANSPORT_SET_ALL
extern

anjay_transport_set_t constant with all fields set to true.

◆ ANJAY_TRANSPORT_SET_IP

const anjay_transport_set_t ANJAY_TRANSPORT_SET_IP
extern

anjay_transport_set_t constant with udp and tcp fields set to true.

NOTE: In the open-source version, ANJAY_TRANSPORT_SET_ALL and ANJAY_TRANSPORT_SET_IP are equivalent.

◆ ANJAY_TRANSPORT_SET_TCP

const anjay_transport_set_t ANJAY_TRANSPORT_SET_TCP
extern

anjay_transport_set_t constant with just the tcp field set to true.

◆ ANJAY_TRANSPORT_SET_UDP

const anjay_transport_set_t ANJAY_TRANSPORT_SET_UDP
extern

anjay_transport_set_t constant with just the udp field set to true.