Anjay Lite
Loading...
Searching...
No Matches
core.h File Reference
#include <anj/init.h>
#include <anj/defs.h>
#include <anj/dm/defs.h>
#include <anj_internal/dm/defs.h>

Go to the source code of this file.

Macros

#define ANJ_INTERNAL_INCLUDE_DM_DEFS
 
#define ANJ_DM_ERR_BAD_REQUEST   (-(int) ANJ_COAP_CODE_BAD_REQUEST)
 
#define ANJ_DM_ERR_UNAUTHORIZED   (-(int) ANJ_COAP_CODE_UNAUTHORIZED)
 
#define ANJ_DM_ERR_NOT_FOUND   (-(int) ANJ_COAP_CODE_NOT_FOUND)
 
#define ANJ_DM_ERR_METHOD_NOT_ALLOWED    (-(int) ANJ_COAP_CODE_METHOD_NOT_ALLOWED)
 
#define ANJ_DM_ERR_INTERNAL   (-(int) ANJ_COAP_CODE_INTERNAL_SERVER_ERROR)
 
#define ANJ_DM_ERR_NOT_IMPLEMENTED   (-(int) ANJ_COAP_CODE_NOT_IMPLEMENTED)
 
#define ANJ_DM_ERR_SERVICE_UNAVAILABLE    (-(int) ANJ_COAP_CODE_SERVICE_UNAVAILABLE)
 

Functions

int anj_dm_add_obj (anj_t *anj, const anj_dm_obj_t *obj)
 
int anj_dm_remove_obj (anj_t *anj, anj_oid_t oid)
 
int anj_dm_res_read (anj_t *anj, const anj_uri_path_t *path, anj_res_value_t *out_value)
 
int anj_dm_write_bytes_chunked (const anj_res_value_t *value, uint8_t *buffer, size_t buffer_len, size_t *out_bytes_len, bool *out_is_last_chunk)
 
int anj_dm_write_string_chunked (const anj_res_value_t *value, char *buffer, size_t buffer_len, bool *out_is_last_chunk)
 
void anj_dm_bootstrap_cleanup (anj_t *anj)
 

Macro Definition Documentation

◆ ANJ_DM_ERR_BAD_REQUEST

#define ANJ_DM_ERR_BAD_REQUEST   (-(int) ANJ_COAP_CODE_BAD_REQUEST)

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

◆ ANJ_DM_ERR_INTERNAL

#define ANJ_DM_ERR_INTERNAL   (-(int) ANJ_COAP_CODE_INTERNAL_SERVER_ERROR)

Unspecified error, no other error code was suitable.

◆ ANJ_DM_ERR_METHOD_NOT_ALLOWED

#define ANJ_DM_ERR_METHOD_NOT_ALLOWED    (-(int) ANJ_COAP_CODE_METHOD_NOT_ALLOWED)

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

◆ ANJ_DM_ERR_NOT_FOUND

#define ANJ_DM_ERR_NOT_FOUND   (-(int) ANJ_COAP_CODE_NOT_FOUND)

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

◆ ANJ_DM_ERR_NOT_IMPLEMENTED

#define ANJ_DM_ERR_NOT_IMPLEMENTED   (-(int) ANJ_COAP_CODE_NOT_IMPLEMENTED)

Operation is not implemented by the LwM2M Client.

◆ ANJ_DM_ERR_SERVICE_UNAVAILABLE

#define ANJ_DM_ERR_SERVICE_UNAVAILABLE    (-(int) ANJ_COAP_CODE_SERVICE_UNAVAILABLE)

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

◆ ANJ_DM_ERR_UNAUTHORIZED

#define ANJ_DM_ERR_UNAUTHORIZED   (-(int) ANJ_COAP_CODE_UNAUTHORIZED)

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

◆ ANJ_INTERNAL_INCLUDE_DM_DEFS

#define ANJ_INTERNAL_INCLUDE_DM_DEFS

Function Documentation

◆ anj_dm_add_obj()

int anj_dm_add_obj ( anj_t anj,
const anj_dm_obj_t obj 
)

Adds an Object to the data model and validates its structure.

The library does not modify the contents of obj or any of the structures it references. The ownership and lifetime of all referenced memory remain the responsibility of the caller.

Note
Validation of the Object, its Instances, and Resources is performed only in debug builds (i.e., when the NDEBUG macro is not defined). In release builds, this function will skip internal consistency checks.
Object Instances in the obj structure must be stored in ascending order by their ID value.
Parameters
anjAnjay object to operate on.
objPointer to the Object definition struct.
Returns
0 on success, a negative value in case of error.

◆ anj_dm_bootstrap_cleanup()

void anj_dm_bootstrap_cleanup ( anj_t anj)

Removes all instances of the Server and Security objects except those associated with the Bootstrap-Server. It is recommended to call this function in case of bootstrap failure.

Parameters
anjAnjay object to operate on.

◆ anj_dm_remove_obj()

int anj_dm_remove_obj ( anj_t anj,
anj_oid_t  oid 
)

Removes Object from the data model.

Parameters
anjAnjay object to operate on.
oidID number of the Object to be removed.
Returns
0 on success, ANJ_DM_ERR_NOT_FOUND if the Object is not found.

◆ anj_dm_res_read()

int anj_dm_res_read ( anj_t anj,
const anj_uri_path_t path,
anj_res_value_t out_value 
)

Reads the value of the Resource or Resource Instance.

Parameters
anjAnjay object to operate on.
pathResource or Resource Instance path.
[out]out_valueReturned Resource value.
Returns
0 on success, a negative value in case of error.

◆ anj_dm_write_bytes_chunked()

int anj_dm_write_bytes_chunked ( const anj_res_value_t value,
uint8_t *  buffer,
size_t  buffer_len,
size_t *  out_bytes_len,
bool *  out_is_last_chunk 
)

Handles writing of a opaque data in the anj_dm_res_write_t handler.

This function is designed to assist in collecting binary data that may arrive in multiple chunks during the LwM2M Write operation. It copies a single chunk of data from the anj_res_value_t structure into the specified target buffer at the correct offset.

The function is intended to be called repeatedly for the same persistent buffer, as subsequent chunks of data are provided by the library. The anj_res_value_t structure contains all information necessary to place each chunk at the correct offset within the buffer — the user does not need to manually manage offsets or write positions.

The user is expected to provide the same buffer across invocations during the same Write operation. The buffer must be large enough to accommodate the entire expected data.

This function does not add a terminator — it is intended for binary (non-null-terminated) content.

This function is reentrant and safe to call repeatedly for the same Write operation, as long as the user correctly manages the buffer across calls.

Note
This function must be used only for Resources of type ANJ_DATA_TYPE_BYTES. For string values, use anj_dm_write_string_chunked instead.
Parameters
valueResource value to be written.
bufferTarget buffer to write into.
buffer_lenSize of the target buffer.
[out]out_bytes_lenSet to total data length if the current chunk is the last one.
[out]out_is_last_chunkSet to true if this is the last chunk of data. Optional parameter.
Returns
0 on success, or ANJ_DM_ERR_INTERNAL if the buffer is too small to accommodate the data.

◆ anj_dm_write_string_chunked()

int anj_dm_write_string_chunked ( const anj_res_value_t value,
char *  buffer,
size_t  buffer_len,
bool *  out_is_last_chunk 
)

Handles writing of a string value in the anj_dm_res_write_t handler.

This function assists with collecting a potentially fragmented string value from the anj_res_value_t structure, which may arrive in multiple chunks during the LwM2M Write operation (e.g., for larger payloads).

The function is intended to be called repeatedly for the same persistent buffer, as subsequent chunks of data are provided by the library. The anj_res_value_t structure contains all information necessary to place each chunk at the correct offset within the buffer — the user does not need to manually manage offsets or write positions.

The user is expected to provide the same buffer across invocations during the same Write operation. The buffer must be large enough to accommodate the entire expected data.

When the final chunk is received (i.e., when offset + chunk_length == full_length_hint), a null terminator (‘’\0') is appended at positionbuffer[full_length_hint]`, completing the string.

This function is reentrant and safe to call multiple times for the same Write operation, as long as the buffer passed in is appropriately managed by the user (i.e., zero-initialized or reused correctly).

Note
This function must be used only for Resources of type ANJ_DATA_TYPE_STRING.
Parameters
valueResource value to be written.
bufferTarget buffer to write the data into.
buffer_lenSize of the target buffer (must include space for the null terminator).
[out]out_is_last_chunkSet to true if this is the last chunk of data. Optional parameter.
Returns
0 on success, or ANJ_DM_ERR_INTERNAL if the buffer is too small to accommodate the data.