anjay
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lwm2m_gateway.h File Reference
#include <anjay/anjay.h>
#include <anjay/anjay_config.h>
#include <anjay/lwm2m_send.h>

Go to the source code of this file.

Functions

int anjay_lwm2m_gateway_install (anjay_t *anjay)
 
int anjay_lwm2m_gateway_register_device (anjay_t *anjay, const char *device_id, anjay_iid_t *inout_iid)
 
int anjay_lwm2m_gateway_deregister_device (anjay_t *anjay, anjay_iid_t iid)
 
int anjay_lwm2m_gateway_register_object (anjay_t *anjay, anjay_iid_t iid, const anjay_dm_object_def_t *const *def_ptr)
 
int anjay_lwm2m_gateway_unregister_object (anjay_t *anjay, anjay_iid_t iid, const anjay_dm_object_def_t *const *def_ptr)
 
int anjay_lwm2m_gateway_send_batch_add_int (anjay_send_batch_builder_t *builder, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, avs_time_real_t timestamp, int64_t value)
 
int anjay_lwm2m_gateway_send_batch_add_uint (anjay_send_batch_builder_t *builder, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, avs_time_real_t timestamp, uint64_t value)
 
int anjay_lwm2m_gateway_send_batch_add_double (anjay_send_batch_builder_t *builder, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, avs_time_real_t timestamp, double value)
 
int anjay_lwm2m_gateway_send_batch_add_bool (anjay_send_batch_builder_t *builder, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, avs_time_real_t timestamp, bool value)
 
int anjay_lwm2m_gateway_send_batch_add_string (anjay_send_batch_builder_t *builder, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, avs_time_real_t timestamp, const char *str)
 
int anjay_lwm2m_gateway_send_batch_add_bytes (anjay_send_batch_builder_t *builder, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, avs_time_real_t timestamp, const void *data, size_t length)
 
int anjay_lwm2m_gateway_send_batch_add_objlnk (anjay_send_batch_builder_t *builder, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, avs_time_real_t timestamp, anjay_oid_t objlnk_oid, anjay_iid_t objlnk_iid)
 
int anjay_lwm2m_gateway_send_batch_data_add_current (anjay_send_batch_builder_t *builder, anjay_t *anjay, anjay_iid_t gateway_iid, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid)
 
int anjay_lwm2m_gateway_send_batch_data_add_current_multiple (anjay_send_batch_builder_t *builder, anjay_t *anjay, anjay_iid_t gateway_iid, const anjay_send_resource_path_t *paths, size_t paths_length)
 
int anjay_lwm2m_gateway_send_batch_data_add_current_multiple_ignore_not_found (anjay_send_batch_builder_t *builder, anjay_t *anjay, anjay_iid_t gateway_iid, const anjay_send_resource_path_t *paths, size_t paths_length)
 
int anjay_lwm2m_gateway_notify_changed (anjay_t *anjay, anjay_iid_t end_dev, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid)
 
int anjay_lwm2m_gateway_notify_instances_changed (anjay_t *anjay, anjay_iid_t end_dev, anjay_oid_t oid)
 
anjay_resource_observation_status_t anjay_lwm2m_gateway_resource_observation_status (anjay_t *anjay_locked, anjay_iid_t end_dev, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid)
 

Function Documentation

◆ anjay_lwm2m_gateway_deregister_device()

int anjay_lwm2m_gateway_deregister_device ( anjay_t anjay,
anjay_iid_t  iid 
)

Deregister an End Device in LwM2M Gateway.

Parameters
anjayAnjay object to operate on
iidEnd Device Instance ID to be deregistered
Returns
0 on success, or a negative value in case of error.

◆ anjay_lwm2m_gateway_install()

int anjay_lwm2m_gateway_install ( anjay_t anjay)

Registers LwM2M Gateway Object and initializes the Gateway Module.

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

◆ anjay_lwm2m_gateway_notify_changed()

int anjay_lwm2m_gateway_notify_changed ( anjay_t anjay,
anjay_iid_t  end_dev,
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.
end_devEnd Device Instance ID.
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_lwm2m_gateway_notify_instances_changed()

int anjay_lwm2m_gateway_notify_instances_changed ( anjay_t anjay,
anjay_iid_t  end_dev,
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.
end_devEnd Device Instance ID.
oidObject ID of the changed Object.
Returns
0 on success, a negative value in case of error.

◆ anjay_lwm2m_gateway_register_device()

int anjay_lwm2m_gateway_register_device ( anjay_t anjay,
const char *  device_id,
anjay_iid_t inout_iid 
)

Register an End Device in LwM2M Gateway and assign the necessary Resources. /0 Device ID Resource is set as device_id parameter. /1 Prefix Resource is assigned automatically as "dev<x>" where <x> is the Device ID returned with iid inout parameter. /3 IoT Device Object Resource is generated as Corelnk format upon Read Request according to the Data Model set with anjay_lwm2m_gateway_register_object calls

Note: if *inout_iid is set to ANJAY_ID_INVALID then the Instance id is generated automatically, otherwise value of *inout_iid is used as a new Gateway Instance ID.

Parameters
anjayAnjay object to operate on
device_idGlobally Unique Device ID (/0 Resource) as a NULL-terminated string. It's value is not copied, so the pointer must remain valid
inout_iidGateway Instance ID to use or ANJAY_ID_INVALID . Treated also as End IoT Device ID which shall be used with further API calls to specify the End Device entity in Gateway
Returns
0 on success, or a negative value in case of error.

◆ anjay_lwm2m_gateway_register_object()

int anjay_lwm2m_gateway_register_object ( anjay_t anjay,
anjay_iid_t  iid,
const anjay_dm_object_def_t *const *  def_ptr 
)

Register an Object in LwM2M Gateway End Device Data Model.

Parameters
anjayAnjay object to operate on
iidEnd Device Instance ID
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, or a negative value in case of error.

◆ anjay_lwm2m_gateway_resource_observation_status()

anjay_resource_observation_status_t anjay_lwm2m_gateway_resource_observation_status ( anjay_t anjay_locked,
anjay_iid_t  end_dev,
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.
end_devEnd Device Instance ID.
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_lwm2m_gateway_send_batch_add_bool()

int anjay_lwm2m_gateway_send_batch_add_bool ( anjay_send_batch_builder_t builder,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid,
anjay_riid_t  riid,
avs_time_real_t  timestamp,
bool  value 
)

Adds a value to batch builder. This function is intended to be used with LwM2M Gateway End Device objects.

IMPORTANT NOTE: If timestamp is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"

Parameters
builderPointer to batch builder
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
riidResource Instance ID, UINT16_MAX for no RIID
timestampTime related to value being sent (e.g. when the measurement corresponding to the passed value was made)
valueValue to add to the batch.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_add_bytes()

int anjay_lwm2m_gateway_send_batch_add_bytes ( anjay_send_batch_builder_t builder,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid,
anjay_riid_t  riid,
avs_time_real_t  timestamp,
const void *  data,
size_t  length 
)

Adds bytes to batch builder. This function is intended to be used with LwM2M Gateway End Device objects.

IMPORTANT NOTE: If timestamp is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"

Parameters
builderPointer to batch builder
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
riidResource Instance ID, UINT16_MAX for no RIID
timestampTime related to bytes being send (e.g. when the measurement corresponding to the passed bytes was made)
dataPointer to data. No longer required by batch builder after call to this function, because internal copy is made. Can be NULL only if length is 0.
lengthLength of data in bytes.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_add_double()

int anjay_lwm2m_gateway_send_batch_add_double ( anjay_send_batch_builder_t builder,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid,
anjay_riid_t  riid,
avs_time_real_t  timestamp,
double  value 
)

Adds a value to batch builder. This function is intended to be used with LwM2M Gateway End Device objects.

IMPORTANT NOTE: If timestamp is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"

Parameters
builderPointer to batch builder
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
riidResource Instance ID, UINT16_MAX for no RIID
timestampTime related to value being sent (e.g. when the measurement corresponding to the passed value was made)
valueValue to add to the batch.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_add_int()

int anjay_lwm2m_gateway_send_batch_add_int ( anjay_send_batch_builder_t builder,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid,
anjay_riid_t  riid,
avs_time_real_t  timestamp,
int64_t  value 
)

Adds a value to batch builder. This function is intended to be used with LwM2M Gateway End Device objects.

IMPORTANT NOTE: If timestamp is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"

Parameters
builderPointer to batch builder
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
riidResource Instance ID, UINT16_MAX for no RIID
timestampTime related to value being sent (e.g. when the measurement corresponding to the passed value was made)
valueValue to add to the batch.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_add_objlnk()

int anjay_lwm2m_gateway_send_batch_add_objlnk ( anjay_send_batch_builder_t builder,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid,
anjay_riid_t  riid,
avs_time_real_t  timestamp,
anjay_oid_t  objlnk_oid,
anjay_iid_t  objlnk_iid 
)

Adds an Object Link to batch builder. This function is intended to be used with LwM2M Gateway End Device objects.

IMPORTANT NOTE: If timestamp is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"

Parameters
builderPointer to batch builder
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
riidResource Instance ID, UINT16_MAX for no RIID
timestampTime related to Object Link being send (e.g. when the measurement corresponding to the passed Object Link was made)
objlnk_oidOID of Object Link
objlnk_iidIID of Object Link
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_add_string()

int anjay_lwm2m_gateway_send_batch_add_string ( anjay_send_batch_builder_t builder,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid,
anjay_riid_t  riid,
avs_time_real_t  timestamp,
const char *  str 
)

Adds a string to batch builder. This function is intended to be used with LwM2M Gateway End Device objects.

IMPORTANT NOTE: If timestamp is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"

Parameters
builderPointer to batch builder
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
riidResource Instance ID, UINT16_MAX for no RIID
timestampTime related to string being send (e.g. when the measurement corresponding to the passed string was made)
strPointer to a NULL-terminated string. Must not be NULL. No longer required by batch builder after call to this function, because internal copy is made.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_add_uint()

int anjay_lwm2m_gateway_send_batch_add_uint ( anjay_send_batch_builder_t builder,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid,
anjay_riid_t  riid,
avs_time_real_t  timestamp,
uint64_t  value 
)

Adds a value to batch builder. This function is intended to be used with LwM2M Gateway End Device objects.

IMPORTANT NOTE: If timestamp is earlier than 1978-07-04 21:24:16 UTC (2**28 seconds since Unix epoch), then it's assumed to be relative to some arbitrary point in time, and will be encoded as relative to "now". Otherwise, the time is assumed to be an Unix timestamp, and encoded as time since Unix epoch. See also: RFC 8428, "Requirements and Design Goals"

Parameters
builderPointer to batch builder
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
riidResource Instance ID, UINT16_MAX for no RIID
timestampTime related to value being sent (e.g. when the measurement corresponding to the passed value was made)
valueValue to add to the batch.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_data_add_current()

int anjay_lwm2m_gateway_send_batch_data_add_current ( anjay_send_batch_builder_t builder,
anjay_t anjay,
anjay_iid_t  gateway_iid,
anjay_oid_t  oid,
anjay_iid_t  iid,
anjay_rid_t  rid 
)

Reads value from data model of the End Device (without checking access privileges) and adds it to the builder with timestamp set to avs_time_real_now().

May possibly add multiple entries if /prefix/oid/iid/rid is a Multiple Resource.

Parameters
builderPointer to batch builder, MUST NOT be NULL
anjayPointer to Anjay object, MUST NOT be NULL
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
oidObject ID, MUST NOT be UINT16_MAX , 0 (Security object ID) or 21 (OSCORE object ID).
iidInstance ID, MUST NOT be UINT16_MAX
ridResource ID, MUST NOT be UINT16_MAX
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_data_add_current_multiple()

int anjay_lwm2m_gateway_send_batch_data_add_current_multiple ( anjay_send_batch_builder_t builder,
anjay_t anjay,
anjay_iid_t  gateway_iid,
const anjay_send_resource_path_t paths,
size_t  paths_length 
)

Reads value from data model of the End Device (without checking access privileges) and adds them to the builder with the same timestamp for every value. Timestamp is set to avs_time_real_now().

IMPORTANT: All paths must point to the objects of the same End Device.

Parameters
builderPointer to batch builder, MUST NOT be NULL
anjayPointer to Anjay object, MUST NOT be NULL
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
pathsPointer to array of anjay_send_resource_path_t .
paths_lengthLength of paths array.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_send_batch_data_add_current_multiple_ignore_not_found()

int anjay_lwm2m_gateway_send_batch_data_add_current_multiple_ignore_not_found ( anjay_send_batch_builder_t builder,
anjay_t anjay,
anjay_iid_t  gateway_iid,
const anjay_send_resource_path_t paths,
size_t  paths_length 
)

Reads value from data model of the End Device (without checking access privileges) and adds them to the builder with the same timestamp for every value. Timestamp is set to avs_time_real_now().

IMPORTANT: All paths must point to the objects of the same End Device.

If a resource is not found, it's ignored, the error isn't returned and the function adds next resources from the paths. Hoverer, if the End Device is not present, the error is returned.

Parameters
builderPointer to batch builder, MUST NOT be NULL
anjayPointer to Anjay object, MUST NOT be NULL
gateway_iidEnd Device Instance ID, MUST NOT be UINT16_MAX
pathsPointer to array of anjay_send_resource_path_t .
paths_lengthLength of paths array.
Returns
0 on success, negative value otherwise. In case of failure, the builder is left unchanged.

◆ anjay_lwm2m_gateway_unregister_object()

int anjay_lwm2m_gateway_unregister_object ( anjay_t anjay,
anjay_iid_t  iid,
const anjay_dm_object_def_t *const *  def_ptr 
)

Unregister an Object in LwM2M Gateway End Device Data Model.

Parameters
anjayAnjay object to operate on
iidEnd Device Instance ID
def_ptrPointer to the Object definition struct.
Returns
0 on success, or a negative value in case of error.