anjay
Loading...
Searching...
No Matches
dm.h File Reference
#include <math.h>
#include <stdint.h>
#include <anjay/io.h>

Go to the source code of this file.

Data Structures

struct  anjay_dm_oi_attributes_t
 
struct  anjay_dm_r_attributes_t
 
struct  anjay_dm_handlers_t
 
struct  anjay_dm_object_def_struct
 
struct  anjay_resource_observation_status_t
 

Macros

#define ANJAY_DM_OID_SECURITY   0
 
#define ANJAY_DM_OID_SERVER   1
 
#define ANJAY_DM_OID_ACCESS_CONTROL   2
 
#define ANJAY_DM_OID_DEVICE   3
 
#define ANJAY_DM_OID_FIRMWARE_UPDATE   5
 
#define ANJAY_ATTRIB_INTEGER_NONE   (-1)
 
#define ANJAY_ATTRIB_PERIOD_NONE   ANJAY_ATTRIB_INTEGER_NONE
 
#define ANJAY_ATTRIB_DOUBLE_NONE   (NAN)
 
#define ANJAY_ATTRIB_VALUE_NONE   ANJAY_ATTRIB_DOUBLE_NONE
 
#define ANJAY_MAX_OBSERVATION_SERVERS_REPORTED_NUMBER   0
 
#define ANJAY_ACCESS_MASK_READ   (1U << 0)
 
#define ANJAY_ACCESS_MASK_WRITE   (1U << 1)
 
#define ANJAY_ACCESS_MASK_EXECUTE   (1U << 2)
 
#define ANJAY_ACCESS_MASK_DELETE   (1U << 3)
 
#define ANJAY_ACCESS_MASK_CREATE   (1U << 4)
 
#define ANJAY_ACCESS_MASK_FULL
 
#define ANJAY_ACCESS_MASK_NONE   0
 
#define ANJAY_ACCESS_LIST_OWNER_BOOTSTRAP   UINT16_MAX
 

Typedefs

typedef struct anjay_dm_object_def_struct anjay_dm_object_def_t
 
typedef int anjay_dm_object_read_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_ssid_t ssid, anjay_dm_oi_attributes_t *out)
 
typedef int anjay_dm_object_write_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_ssid_t ssid, const anjay_dm_oi_attributes_t *attrs)
 
typedef int anjay_dm_list_instances_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_dm_list_ctx_t *ctx)
 
typedef int anjay_dm_instance_reset_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid)
 
typedef int anjay_dm_instance_remove_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid)
 
typedef int anjay_dm_instance_create_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid)
 
typedef int anjay_dm_instance_read_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_ssid_t ssid, anjay_dm_oi_attributes_t *out)
 
typedef int anjay_dm_instance_write_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_ssid_t ssid, const anjay_dm_oi_attributes_t *attrs)
 
typedef int anjay_dm_list_resources_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_dm_resource_list_ctx_t *ctx)
 
typedef int anjay_dm_resource_read_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_output_ctx_t *ctx)
 
typedef int anjay_dm_resource_write_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_input_ctx_t *ctx)
 
typedef int anjay_dm_resource_execute_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_execute_ctx_t *ctx)
 
typedef int anjay_dm_resource_reset_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid)
 
typedef int anjay_dm_list_resource_instances_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_dm_list_ctx_t *ctx)
 
typedef int anjay_dm_resource_read_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_ssid_t ssid, anjay_dm_r_attributes_t *out)
 
typedef int anjay_dm_resource_write_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_ssid_t ssid, const anjay_dm_r_attributes_t *attrs)
 
typedef int anjay_dm_resource_instance_read_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_ssid_t ssid, anjay_dm_r_attributes_t *out)
 
typedef int anjay_dm_resource_instance_write_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_ssid_t ssid, const anjay_dm_r_attributes_t *attrs)
 
typedef int anjay_dm_transaction_begin_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)
 
typedef int anjay_dm_transaction_validate_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)
 
typedef int anjay_dm_transaction_commit_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)
 
typedef int anjay_dm_transaction_rollback_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)
 
typedef uint16_t anjay_access_mask_t
 

Enumerations

enum  anjay_dm_con_attr_t { ANJAY_DM_CON_ATTR_NONE = -1 , ANJAY_DM_CON_ATTR_NON = 0 , ANJAY_DM_CON_ATTR_CON = 1 }
 
enum  anjay_security_mode_t {
  ANJAY_SECURITY_PSK = 0 , ANJAY_SECURITY_RPK = 1 , ANJAY_SECURITY_CERTIFICATE = 2 , ANJAY_SECURITY_NOSEC = 3 ,
  ANJAY_SECURITY_EST = 4
}
 
enum  anjay_sms_security_mode_t { ANJAY_SMS_SECURITY_DTLS_PSK = 1 , ANJAY_SMS_SECURITY_SECURE_PACKET = 2 , ANJAY_SMS_SECURITY_NOSEC = 3 }
 

Functions

int anjay_dm_list_instances_SINGLE (anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_dm_list_ctx_t *ctx)
 
int anjay_dm_transaction_NOOP (anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)
 
int anjay_notify_changed (anjay_t *anjay, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid)
 
int anjay_notify_instances_changed (anjay_t *anjay, anjay_oid_t oid)
 
anjay_resource_observation_status_t anjay_resource_observation_status (anjay_t *anjay, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid)
 
int anjay_register_object (anjay_t *anjay, const anjay_dm_object_def_t *const *def_ptr)
 
int anjay_unregister_object (anjay_t *anjay, const anjay_dm_object_def_t *const *def_ptr)
 
bool anjay_binding_mode_valid (const char *binding_mode)
 

Variables

const anjay_dm_oi_attributes_t ANJAY_DM_OI_ATTRIBUTES_EMPTY
 
const anjay_dm_r_attributes_t ANJAY_DM_R_ATTRIBUTES_EMPTY
 

Macro Definition Documentation

◆ ANJAY_ACCESS_LIST_OWNER_BOOTSTRAP

#define ANJAY_ACCESS_LIST_OWNER_BOOTSTRAP   UINT16_MAX

◆ ANJAY_ACCESS_MASK_CREATE

#define ANJAY_ACCESS_MASK_CREATE   (1U << 4)

◆ ANJAY_ACCESS_MASK_DELETE

#define ANJAY_ACCESS_MASK_DELETE   (1U << 3)

◆ ANJAY_ACCESS_MASK_EXECUTE

#define ANJAY_ACCESS_MASK_EXECUTE   (1U << 2)

◆ ANJAY_ACCESS_MASK_FULL

#define ANJAY_ACCESS_MASK_FULL
Value:
#define ANJAY_ACCESS_MASK_DELETE
Definition dm.h:1192
#define ANJAY_ACCESS_MASK_EXECUTE
Definition dm.h:1191
#define ANJAY_ACCESS_MASK_WRITE
Definition dm.h:1190
#define ANJAY_ACCESS_MASK_CREATE
Definition dm.h:1193
#define ANJAY_ACCESS_MASK_READ
Definition dm.h:1189

◆ ANJAY_ACCESS_MASK_NONE

#define ANJAY_ACCESS_MASK_NONE   0

◆ ANJAY_ACCESS_MASK_READ

#define ANJAY_ACCESS_MASK_READ   (1U << 0)

◆ ANJAY_ACCESS_MASK_WRITE

#define ANJAY_ACCESS_MASK_WRITE   (1U << 1)

◆ ANJAY_ATTRIB_DOUBLE_NONE

#define ANJAY_ATTRIB_DOUBLE_NONE   (NAN)

A value indicating that the Less Than/Greater Than/Step attribute is not set

◆ ANJAY_ATTRIB_INTEGER_NONE

#define ANJAY_ATTRIB_INTEGER_NONE   (-1)

A value indicating that the Min/Max Period or Maximum Historical Queue attribute is not set

◆ ANJAY_ATTRIB_PERIOD_NONE

#define ANJAY_ATTRIB_PERIOD_NONE   ANJAY_ATTRIB_INTEGER_NONE

◆ ANJAY_ATTRIB_VALUE_NONE

#define ANJAY_ATTRIB_VALUE_NONE   ANJAY_ATTRIB_DOUBLE_NONE

◆ ANJAY_DM_OID_ACCESS_CONTROL

#define ANJAY_DM_OID_ACCESS_CONTROL   2

◆ ANJAY_DM_OID_DEVICE

#define ANJAY_DM_OID_DEVICE   3

◆ ANJAY_DM_OID_FIRMWARE_UPDATE

#define ANJAY_DM_OID_FIRMWARE_UPDATE   5

◆ ANJAY_DM_OID_SECURITY

#define ANJAY_DM_OID_SECURITY   0

◆ ANJAY_DM_OID_SERVER

#define ANJAY_DM_OID_SERVER   1

◆ ANJAY_MAX_OBSERVATION_SERVERS_REPORTED_NUMBER

#define ANJAY_MAX_OBSERVATION_SERVERS_REPORTED_NUMBER   0

Maximum number of servers observing a Resource reported in anjay_resource_observation_status_t structure.

Typedef Documentation

◆ anjay_access_mask_t

typedef uint16_t anjay_access_mask_t

◆ anjay_dm_instance_create_t

typedef int anjay_dm_instance_create_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid)

A handler that creates an Object Instance.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidInstance ID to create, chosen either by the server or the library. An ID that has been previously checked (using anjay_dm_list_instances_t) to not be PRESENT is guaranteed to be passed.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_instance_read_default_attrs_t

typedef int anjay_dm_instance_read_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_ssid_t ssid, anjay_dm_oi_attributes_t *out)

A handler that returns default attributes set for the Object Instance.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidChecked Object Instance ID.
ssidShort Server ID of the server requesting the operation.
[out]outReturned attributes.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_instance_remove_t

typedef int anjay_dm_instance_remove_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid)

A handler that removes an Object Instance with given Instance ID.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidChecked Object Instance ID.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_instance_reset_t

typedef int anjay_dm_instance_reset_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid)

A handler that shall reset Object Instance to its default (after creational) state.

Note: if this handler is not implemented, then non-partial write on the Object Instance (iid) will not succeed.

Parameters
anjayAnjay Object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidInstance ID to reset.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_instance_write_default_attrs_t

typedef int anjay_dm_instance_write_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_ssid_t ssid, const anjay_dm_oi_attributes_t *attrs)

A handler that sets default attributes for the Object Instance.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidChecked Object Instance ID.
ssidShort Server ID of the server requesting the operation.
attrsAttributes to set for the Object Instance.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_list_instances_t

typedef int anjay_dm_list_instances_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_dm_list_ctx_t *ctx)

A handler that enumerates all Object Instances for the Object.

The library will not attempt to call anjay_dm_instance_remove_t or anjay_dm_instance_create_t handlers inside the anjay_dm_emit calls performed from this handler, so the implementation is free to use iteration state that would be invalidated by such calls.

CAUTION: Aside from the note above, the library MAY call other data model handlers for the same Object from within the anjay_dm_emit call. Please make sure that your code is able to handle this - e.g. avoid calling anjay_dm_emit with a non-recursive object-scope mutex locked.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
ctxContext through which the Instance IDs shall be returned, see anjay_dm_emit .

Instance listing handlers MUST always return Instance IDs in a strictly ascending, sorted order. Failure to do so will result in an error being sent to the LwM2M server or passed down to internal routines that called this handler.

Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_list_resource_instances_t

typedef int anjay_dm_list_resource_instances_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_dm_list_ctx_t *ctx)

A handler that enumerates all Resource Instances of a Multiple Resource, called only if the Resource is PRESENT and is of either ANJAY_DM_RES_RM, ANJAY_DM_RES_WM or ANJAY_DM_RES_RWM kind (as returned by anjay_dm_list_resources_t).

The library will not attempt to call anjay_dm_resource_write_t or anjay_dm_resource_reset_t handlers inside the anjay_dm_emit calls performed from this handler, so the implementation is free to use iteration state that would be invalidated by such calls.

CAUTION: Aside from the note above, the library MAY call other data model handlers for the same Object from within the anjay_dm_emit call. Please make sure that your code is able to handle this - e.g. avoid calling anjay_dm_emit with a non-recursive object-scope mutex locked.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
ctxContext through which the Resource Instance IDs shall be returned, see anjay_dm_emit .

Resource instance listing handlers MUST always return Resource Instance IDs in a strictly ascending, sorted order. Failure to do so will result in an error being sent to the LwM2M server or passed down to internal routines that called this handler.

Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_list_resources_t

typedef int anjay_dm_list_resources_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_dm_resource_list_ctx_t *ctx)

A handler that enumerates SUPPORTED Resources for an Object Instance, called only if the Object Instance is PRESENT (has recently been returned via anjay_dm_list_instances_t).

CAUTION: The library MAY call other data model handlers for the same Object from within the anjay_dm_emit_res call. Please make sure that your code is able to handle this - e.g. avoid calling anjay_dm_emit_res with a non-recursive object-scope mutex locked.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ctxContext through which the Resource IDs shall be returned, see anjay_dm_emit_res .

Resource listing handlers MUST always return Resource IDs in a strictly ascending, sorted order. Failure to do so will result in an error being sent to the LwM2M server or passed down to internal routines that called this handler.

Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_object_def_t

◆ anjay_dm_object_read_default_attrs_t

typedef int anjay_dm_object_read_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_ssid_t ssid, anjay_dm_oi_attributes_t *out)

A handler that returns default attribute values set for the Object.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
ssidShort Server ID of the server requesting the operation.
[out]outAttributes struct to be filled by the handler.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_object_write_default_attrs_t

typedef int anjay_dm_object_write_default_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_ssid_t ssid, const anjay_dm_oi_attributes_t *attrs)

A handler that sets default attribute values for the Object.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
ssidShort Server ID of the server requesting the operation.
attrsAttributes struct to be set for the Object.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_resource_execute_t

typedef int anjay_dm_resource_execute_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_execute_ctx_t *ctx)

A handler that performs the Execute action on given Resource, called only if the Resource is PRESENT and of the ANJAY_DM_RES_E kind (as returned by anjay_dm_list_resources_t).

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
ctxExecute context to read the execution arguments from, using the anjay_execute_get_* function family.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_resource_instance_read_attrs_t

typedef int anjay_dm_resource_instance_read_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_ssid_t ssid, anjay_dm_r_attributes_t *out)

A handler that returns Resource Instance attributes.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
riidResource Instance ID.
ssidShort Server ID of the LwM2M Server issuing the request.
[out]outReturned Resource attributes.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_resource_instance_write_attrs_t

typedef int anjay_dm_resource_instance_write_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_ssid_t ssid, const anjay_dm_r_attributes_t *attrs)

A handler that sets attributes for given Resource Instance.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
riidResource Instance ID.
ssidShort Server ID of the LwM2M Server issuing the request.
attrsAttributes to set for this Resource.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_resource_read_attrs_t

typedef int anjay_dm_resource_read_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_ssid_t ssid, anjay_dm_r_attributes_t *out)

A handler that returns Resource attributes.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
ssidShort Server ID of the LwM2M Server issuing the request.
[out]outReturned Resource attributes.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_resource_read_t

typedef int anjay_dm_resource_read_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_output_ctx_t *ctx)

A handler that reads the Resource or Resource Instance value, called only if the Resource is PRESENT and is one of the ANJAY_DM_RES_R, ANJAY_DM_RES_RW, ANJAY_DM_RES_RM or ANJAY_DM_RES_RWM kinds (as returned by anjay_dm_list_resources_t).

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
riidResource Instance ID, or ANJAY_ID_INVALID in case of a Single Resource.
ctxOutput context to write the resource value to using the anjay_ret_* function family.

NOTE: One of the anjay_ret_* functions MUST be called in this handler before returning successfully. Failure to do so will result in 5.00 Internal Server Error being sent to the server.

NOTE: This handler will only be called with riid set to a valid value if the Resource Instance is PRESENT (has recently been returned via anjay_dm_list_resource_instances_t).

Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, it will be used as a hint for the CoAP response code to use. The library may decide to override the returned value in case of a more specific internal error (e.g. 4.06 Not Acceptable in response to an invalid Accept option).

    Note that the CoAP response sent by the library will always be valid. If the value returned is a negative number that is not any of the ANJAY_ERR_ constant, the normal fallback response is 5.00 Internal Server Error.

◆ anjay_dm_resource_reset_t

typedef int anjay_dm_resource_reset_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid)

A handler that shall reset a Resource to its default (after creational) state. In particular, for any writeable optional resource, it shall remove it; for any writeable mandatory Multiple Resource, it shall remove all its instances.

NOTE: If this handler is not implemented for a Multiple Resource, then non-partial write on it will not succeed.

NOTE: In the current version of Anjay, this handler is only ever called on Multiple Resources. It is REQUIRED so that after calling this handler, any Multiple Resource is either not PRESENT, or PRESENT, but contain zero Resource Instances.

Parameters
anjayAnjay Object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridID of the Resource to reset.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_resource_write_attrs_t

typedef int anjay_dm_resource_write_attrs_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_ssid_t ssid, const anjay_dm_r_attributes_t *attrs)

A handler that sets attributes for given Resource.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
ssidShort Server ID of the LwM2M Server issuing the request.
attrsAttributes to set for this Resource.
Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_resource_write_t

typedef int anjay_dm_resource_write_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_input_ctx_t *ctx)

A handler that writes the Resource value, called only if the Resource is SUPPORTED and not of the ANJAY_DM_RES_E kind (as returned by anjay_dm_list_resources_t). Note that it may be called on nominally read-only Resources if the write is performed by the Bootstrap Server.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
iidObject Instance ID.
ridResource ID.
riidResource Instance ID, or ANJAY_ID_INVALID in case of a Single Resource.
ctxInput context to read the resource value from using the anjay_get_* function family.

NOTE: This handler will only be called with riid set to a valid value if the Resource has been verified to be a Multiple Resource (as returned by anjay_dm_list_resources_t).

Returns
This handler should return:
  • 0 on success,
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_transaction_begin_t

typedef int anjay_dm_transaction_begin_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)

A handler that is called when there is a request that might modify an Object and fail. Such situation often requires to rollback changes, and this handler shall implement logic that prepares for possible failure in the future.

Handlers listed below are NOT called without beginning transaction in the first place (note that if an Object does not implement transaction handlers, then it will not be possible to perform operations listed below):

Note: if an error occurs during a transaction (i.e. after successful call of this function) then the rollback handler anjay_dm_transaction_rollback_t will be executed by the library.

Parameters
anjayAnjay object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
Returns
  • 0 on success
  • a negative value in case of error

◆ anjay_dm_transaction_commit_t

typedef int anjay_dm_transaction_commit_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)

A handler that is called after transaction is finished. If it fails then anjay_dm_transaction_rollback_t handler must be called by the user code if it is necessary.

NOTE: If this function fails, the data model will be left in an inconsistent state. For this reason, it may return an error value if and only if a fatal, unpredictable and irrecoverable error (e.g. physical write error) occurs. All other errors (such as invalid object state) shall be reported via anjay_dm_transaction_validate_t .

Parameters
anjayAnjay Object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
Returns
  • 0 on success
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

◆ anjay_dm_transaction_rollback_t

typedef int anjay_dm_transaction_rollback_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)

A handler that is called whenever there is a need to restore previous Object state during a transaction or during committing a transaction.

Parameters
anjayAnjay Object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
Returns
  • 0 on success
  • a negative value in case of error.

◆ anjay_dm_transaction_validate_t

typedef int anjay_dm_transaction_validate_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr)

A handler that is called after transaction is finished, but before anjay_dm_transaction_commit_t is called. It is used to check whether the commit operation may be successfully performed.

Any validation of the object's state shall be performed in this function, rather than in the commit handler. If there is a need to commit changes to multiple objects at once, this handler is called on all modified objects first, to avoid potential inconsistencies that may arise from a failing commit operation.

Returning success from this handler means that the corresponding commit function shall subsequently execute successfully. The commit handler may nevertheless fail, but if and only if a fatal, unpredictable and irrecoverable error (e.g. physical write error) occurs.

Parameters
anjayAnjay Object to operate on.
obj_ptrObject definition pointer, as passed to anjay_register_object .
Returns
  • 0 on success
  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.

Enumeration Type Documentation

◆ anjay_dm_con_attr_t

Values for the con attribute.

Enumerator
ANJAY_DM_CON_ATTR_NONE 
ANJAY_DM_CON_ATTR_NON 
ANJAY_DM_CON_ATTR_CON 

◆ anjay_security_mode_t

Possible values of the Security Mode Resource, as described in the Security Object definition.

Enumerator
ANJAY_SECURITY_PSK 
ANJAY_SECURITY_RPK 
ANJAY_SECURITY_CERTIFICATE 
ANJAY_SECURITY_NOSEC 
ANJAY_SECURITY_EST 

◆ anjay_sms_security_mode_t

Possible values of the SMS Security Mode Resource, as described in the Security Object definition.

Enumerator
ANJAY_SMS_SECURITY_DTLS_PSK 
ANJAY_SMS_SECURITY_SECURE_PACKET 
ANJAY_SMS_SECURITY_NOSEC 

Function Documentation

◆ anjay_binding_mode_valid()

bool anjay_binding_mode_valid ( const char *  binding_mode)

Checks whether the passed string is a valid LwM2M Binding Mode.

Returns
true for "U", "S", "US", "UQ", "SQ", "UQS", false in any other case.

◆ anjay_dm_list_instances_SINGLE()

int anjay_dm_list_instances_SINGLE ( anjay_t anjay,
const anjay_dm_object_def_t *const *  obj_ptr,
anjay_dm_list_ctx_t ctx 
)

Convenience function to use as the list_instances handler in Single Instance objects.

Implements a valid iteration that returns a single Instance ID: 0.

◆ anjay_dm_transaction_NOOP()

int anjay_dm_transaction_NOOP ( anjay_t anjay,
const anjay_dm_object_def_t *const *  obj_ptr 
)

Stub handler that can be substituted for any transaction operation. Does nothing. It is NOT recommended for production usage.

Returns
always 0

◆ anjay_notify_changed()

int anjay_notify_changed ( anjay_t anjay,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid 
)

Notifies the library that the value of given Resource changed. It may trigger a LwM2M Notify message, update server connections and perform other tasks, as required for the specified Resource.

Needs to be called for any Resource after its value is changed by means other than LwM2M.

Note that it should not be called after a Write performed by the LwM2M server.

Parameters
anjayAnjay object to operate on.
oidObject ID of the changed Resource.
iidObject Instance ID of the changed Resource.
ridResource ID of the changed Resource.
Returns
0 on success, a negative value in case of error.

◆ anjay_notify_instances_changed()

int anjay_notify_instances_changed ( anjay_t anjay,
anjay_oid_t  oid 
)

Notifies the library that the set of Instances existing in a given Object changed. It may trigger a LwM2M Notify message, update server connections and perform other tasks, as required for the specified Object ID.

Needs to be called for each Object, after an Instance is created or removed by means other than LwM2M.

Note that it should not be called after a Create or Delete performed by the LwM2M server.

Parameters
anjayAnjay object to operate on.
oidObject ID of the changed Object.
Returns
0 on success, a negative value in case of error.

◆ anjay_register_object()

int anjay_register_object ( anjay_t anjay,
const anjay_dm_object_def_t *const *  def_ptr 
)

Registers the Object in the data model, making it available for access by the LwM2M Servers.

NOTE: def_ptr MUST stay valid up to and including the corresponding anjay_delete or anjay_unregister_object call.

Parameters
anjayAnjay object to operate on.
def_ptrPointer to the Object definition struct. The exact value passed to this function will be forwarded to all data model handler calls.
Returns
0 on success, a negative value in case of error.

◆ anjay_resource_observation_status()

anjay_resource_observation_status_t anjay_resource_observation_status ( anjay_t anjay,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid 
)

Gets information whether and how a given Resource is observed. See anjay_resource_observation_status_t for details.

NOTE: This API is a companion to anjay_notify_changed. There is no analogous API that would be a companion to anjay_notify_instances_changed. Any changes to set of instances of any LwM2M Object MUST be considered observed at all times and notified as soon as possible.

Parameters
anjayAnjay object to operate on.
oidObject ID of the Resource to check.
iidObject Instance ID of the Resource to check.
ridResource ID of the Resource to check.
Returns
Observation status of a given Resource. If the arguments do not specify a valid Resource path, data equivalent to a non-observed Resource will be returned.

NOTE: This function may be used to implement notifications for Resources that require active polling by the client application. A naive implementation could look more or less like this (pseudocode):

status = anjay_resource_observation_status(anjay, oid, iid, rid); if (status.is_observed && current_time >= last_check_time + status.min_period) { new_value = read_resource_value(); if (new_value != old_value) { anjay_notify_changed(anjay, oid, iid, rid); } last_check_time = current_time; }

However, please note that such implementation may not be strictly conformant to the LwM2M specification. For example, in the following case:

[time] –|-----—|-*---—|--> | - intervals between resource reads |<---—>| * - point in time when underlying state min_period actually changes

the specification would require the notification to be sent exactly at the time of the (*) event, but with this naive implementation, will be delayed until the next (|).

◆ anjay_unregister_object()

int anjay_unregister_object ( anjay_t anjay,
const anjay_dm_object_def_t *const *  def_ptr 
)

Unregisters an Object in the data model, so that it is no longer available for access by the LwM2M Servers.

def_ptr MUST be a pointer previously passed to anjay_register_object for the same anjay object.

After a successful unregister, any resources used by the actual object may be safely freed up.

NOTE: This function MUST NOT be called from within any data model handler callback function (i.e. any of the anjay_dm_handlers_t members). Doing so is undefined behavior.

Parameters
anjayAnjay object to operate on.
def_ptrPointer to the Object definition struct.
Returns
0 on success, a negative value if def_ptr does not correspond to any known registered object.

Variable Documentation

◆ ANJAY_DM_OI_ATTRIBUTES_EMPTY

const anjay_dm_oi_attributes_t ANJAY_DM_OI_ATTRIBUTES_EMPTY
extern

Convenience Object/Object Instance attributes constant, filled with "attribute not set" values

◆ ANJAY_DM_R_ATTRIBUTES_EMPTY

const anjay_dm_r_attributes_t ANJAY_DM_R_ATTRIBUTES_EMPTY
extern

Convenience Resource attributes constant, filled with "attribute not set" values