LwM2M carrier

You can use the LwM2M carrier library in your nRF91 application in order to connect to the LwM2M operator network. Integrating this library into an application causes the device to connect to the operator’s device management platform autonomously. Two examples of such device management platforms are Verizon’s Thingspace and AT&T’s IoT Platform.

Important

It is mandatory to include the LwM2M carrier library in any Verizon or AT&T certified products.

This library uses LwM2M protocol to communicate with device manager platforms, but it does not expose an LwM2M API to your application. If you want to use LwM2M for other purposes, see Lightweight M2M (LWM2M).

The nRF9160: LwM2M carrier sample demonstrates how to run this library in an application. The LwM2M carrier library is also used in the nRF9160: Asset Tracker application.

API documentation

Header files: lib/bin/lwm2m_carrier/include
Source files: lib/bin/lwm2m_carrier

LWM2M carrier library API

group lwm2m_carrier_api

LWM2M carrier library events.

LWM2M_CARRIER_EVENT_MODEM_INIT

Modem library initialized.

LWM2M_CARRIER_EVENT_CONNECTING

Connecting to the LTE network.

LWM2M_CARRIER_EVENT_CONNECTED

Connected to the LTE network.

LWM2M_CARRIER_EVENT_DISCONNECTING

Disconnecting from the LTE network.

LWM2M_CARRIER_EVENT_DISCONNECTED

Disconnected from the LTE network.

LWM2M_CARRIER_EVENT_BOOTSTRAPPED

LWM2M carrier bootstrapped.

LWM2M_CARRIER_EVENT_REGISTERED

LWM2M carrier registered.

LWM2M_CARRIER_EVENT_DEFERRED

LWM2M carrier operation is deferred.

LWM2M_CARRIER_EVENT_FOTA_START

Modem update started.

LWM2M_CARRIER_EVENT_REBOOT

Application will reboot.

LWM2M_CARRIER_EVENT_LTE_READY

LTE network is ready to be used.

LWM2M_CARRIER_EVENT_ERROR

An error occurred.

LWM2M_CARRIER_EVENT_CERTS_INIT

CA certificates need to be initialized.

LWM2M carrier library event deferred reasons.

LWM2M_CARRIER_DEFERRED_NO_REASON

No reason given.

LWM2M_CARRIER_DEFERRED_PDN_ACTIVATE

Failed to activate PDN.

LWM2M_CARRIER_DEFERRED_BOOTSTRAP_NO_ROUTE

No route to bootstrap server.

LWM2M_CARRIER_DEFERRED_BOOTSTRAP_CONNECT

Failed to connect to bootstrap server.

LWM2M_CARRIER_DEFERRED_BOOTSTRAP_SEQUENCE

Bootstrap sequence not completed.

LWM2M_CARRIER_DEFERRED_SERVER_NO_ROUTE

No route to server.

LWM2M_CARRIER_DEFERRED_SERVER_CONNECT

Failed to connect to server.

LWM2M_CARRIER_DEFERRED_SERVER_REGISTRATION

Server registration sequence not completed.

LWM2M_CARRIER_DEFERRED_SERVICE_UNAVAILABLE

Server in maintenance mode.

LWM2M carrier library event error codes.

LWM2M_CARRIER_ERROR_NO_ERROR

< No error. Failed to connect to the LTE network.

LWM2M_CARRIER_ERROR_CONNECT_FAIL

Failed to disconnect from the LTE network.

LWM2M_CARRIER_ERROR_DISCONNECT_FAIL

LWM2M carrier bootstrap failed.

LWM2M_CARRIER_ERROR_BOOTSTRAP

Update package rejected.

LWM2M_CARRIER_ERROR_FOTA_PKG

Protocol error.

LWM2M_CARRIER_ERROR_FOTA_PROTO

Connection error.

LWM2M_CARRIER_ERROR_FOTA_CONN

Connection lost.

LWM2M_CARRIER_ERROR_FOTA_CONN_LOST

Update failed.

LWM2M_CARRIER_ERROR_FOTA_FAIL

Illegal object configuration detected.

LWM2M_CARRIER_ERROR_CONFIGURATION

LWM2M device power sources types.

LWM2M_CARRIER_POWER_SOURCE_DC
LWM2M_CARRIER_POWER_SOURCE_INTERNAL_BATTERY
LWM2M_CARRIER_POWER_SOURCE_EXTERNAL_BATTERY
LWM2M_CARRIER_POWER_SOURCE_ETHERNET
LWM2M_CARRIER_POWER_SOURCE_USB
LWM2M_CARRIER_POWER_SOURCE_AC
LWM2M_CARRIER_POWER_SOURCE_SOLAR

LWM2M device error codes.

LWM2M_CARRIER_ERROR_CODE_NO_ERROR
LWM2M_CARRIER_ERROR_CODE_LOW_CHARGE
LWM2M_CARRIER_ERROR_CODE_EXTERNAL_SUPPLY_OFF
LWM2M_CARRIER_ERROR_CODE_GPS_FAILURE
LWM2M_CARRIER_ERROR_CODE_LOW_SIGNAL
LWM2M_CARRIER_ERROR_CODE_OUT_OF_MEMORY
LWM2M_CARRIER_ERROR_CODE_SMS_FAILURE
LWM2M_CARRIER_ERROR_CODE_IP_CONNECTIVITY_FAILURE
LWM2M_CARRIER_ERROR_CODE_PERIPHERAL_MALFUNCTION

LWM2M device battery status.

Note

These values are only valid for the LWM2M Device INTERNAL_BATTERY if present.

LWM2M_CARRIER_BATTERY_STATUS_NORMAL
LWM2M_CARRIER_BATTERY_STATUS_CHARGING
LWM2M_CARRIER_BATTERY_STATUS_CHARGE_COMPLETE
LWM2M_CARRIER_BATTERY_STATUS_DAMAGED
LWM2M_CARRIER_BATTERY_STATUS_LOW_BATTERY
LWM2M_CARRIER_BATTERY_STATUS_NOT_INSTALLED
LWM2M_CARRIER_BATTERY_STATUS_UNKNOWN

LWM2M portfolio identity types.

LWM2M_CARRIER_IDENTITY_ID
LWM2M_CARRIER_IDENTITY_MANUFACTURER
LWM2M_CARRIER_IDENTITY_MODEL
LWM2M_CARRIER_IDENTITY_SW_VERSION

Functions

int lwm2m_carrier_init(const lwm2m_carrier_config_t *config)

Initialize the LWM2M carrier library.

Note

The library does not copy the contents of pointers in the config parameters. The application has to make sure that the provided parameters are valid throughout the application lifetime (i. e. placed in static memory or in flash).

Note

The first time this function is called after a modem firmware update, (FOTA) it may take several seconds to return in order to complete the procedure.

Parameters
  • config[in] Configuration parameters for the library.

Returns

0 on success, negative error code on error.

void lwm2m_carrier_run(void)

LWM2M carrier library main function.

This is a non-return function, intended to run on a separate thread.

void lwm2m_carrier_time_read(int32_t *utc_time, int *utc_offset, const char **tz)

Function to read all time parameters.

Parameters
  • utc_time[out] Pointer to time since Epoch in seconds.

  • utc_offset[out] Pointer to UTC offset in minutes.

  • tz[out] Pointer to null-terminated timezone string pointer.

int32_t lwm2m_carrier_utc_time_read(void)

Function to read current UTC time.

Note

This function can be implemented by the application, if custom time management is needed.

Returns

Current UTC time since Epoch in seconds.

int lwm2m_carrier_utc_offset_read(void)

Function to read offset to UTC time.

Note

This function can be implemented by the application, if custom time management is needed.

Returns

UTC offset in minutes.

const char *lwm2m_carrier_timezone_read(void)

Function to read timezone.

Note

This function can be implemented by the application, if custom time management is needed.

Returns

Null-terminated timezone string pointer, IANA Timezone (TZ) database format.

int lwm2m_carrier_utc_time_write(int32_t time)

Function to write current UTC time (LWM2M server write operation)

Note

This function can be implemented by the application, if custom time management is needed.

Parameters
  • time[in] Time since Epoch in seconds.

Returns

0 on success, negative error code on error.

int lwm2m_carrier_utc_offset_write(int offset)

Function to write UTC offset (LWM2M server write operation)

Note

This function can be implemented by the application, if custom time management is needed.

Parameters
  • offset[in] UTC offset in minutes.

Returns

0 on success, negative error code on error.

int lwm2m_carrier_timezone_write(const char *tz)

Function to write timezone (LWM2M server write operation).

Note

This function can be implemented by the application, if custom time management is needed.

Parameters
  • tz[in] Null-terminated timezone string pointer.

Returns

0 on success, negative error code on error.

int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *event)

LWM2M carrier library event handler.

This function will be called by the LWM2M carrier library whenever some event significant for the application occurs.

Note

This function has to be implemented by the application.

Parameters
  • event[in] LWM2M carrier event that occurred.

Returns

In case of LWM2M_CARRIER_EVENT_REBOOT events if non-zero is returned, the LwM2M carrier library will not reboot the device. The application should to reboot at the earliest convenient time.

int lwm2m_carrier_avail_power_sources_set(const uint8_t *power_sources, uint8_t power_source_count)

Set the available power sources supported and used by the LWM2M device.

Note

It is necessary to call this function before any other device power source related functions listed in this file, as any updates of voltage/current measurements performed on power sources that have not been reported will be discarded.

Note

Upon consecutive calls of this function, the corresponding current and voltage measurements will be reset to 0. Similarly, the battery status will be set to UNKNOWN and the battery level to 0%.

Parameters
  • power_sources[in] Array of available device power sources.

  • power_source_count[in] Number of power sources currently used by the device.

Returns

  • -E2BIG – If the reported number of power sources is bigger than the maximum supported.

  • -EINVAL – If one or more of the power sources are not supported.

  • 0 – If the available power sources have been set successfully.

int lwm2m_carrier_power_source_voltage_set(uint8_t power_source, int32_t value)

Set or update the latest voltage measurements made on one of the available device power sources.

Note

The voltage measurement needs to be specified in millivolts (mV) and is to be assigned to one of the available power sources.

Parameters
  • power_source[in] Power source to which the measurement corresponds.

  • value[in] Voltage measurement expressed in mV.

Returns

  • -EINVAL – If the power source is not supported.

  • -ENODEV – If the power source is not listed as an available power source.

  • 0 – If the voltage measurements have been updated successfully.

int lwm2m_carrier_power_source_current_set(uint8_t power_source, int32_t value)

Set or update the latest current measurements made on one of the available device power sources.

Note

The current measurement needs to be specified in milliamperes (mA) and is to be assigned to one of the available power sources.

Parameters
  • power_source[in] Power source to which the measurement corresponds.

  • value[in] Current measurement expressed in mA.

Returns

  • -EINVAL – If the power source is not supported.

  • -ENODEV – If the power source is not listed as an available power source.

  • 0 – If the current measurements have been updated successfully.

int lwm2m_carrier_battery_level_set(uint8_t battery_level)

Set or update the latest battery level (internal battery).

Note

The battery level is to be specified as a percentage, hence values outside the range 0-100 will be ignored.

Note

The value is only valid for the Device internal battery if present.

Parameters
  • battery_level[in] Internal battery level percentage.

Returns

  • -EINVAL – If the specified battery level lies outside the 0-100% range.

  • -ENODEV – If internal battery is not listed as an available power source.

  • 0 – If the battery level has been updated successfully.

int lwm2m_carrier_battery_status_set(int32_t battery_status)

Set or update the latest battery status (internal battery).

Note

The value is only valid for the Device internal battery.

Parameters
  • battery_status[in] Internal battery status to be reported.

Returns

  • -EINVAL – If the battery status is not supported.

  • -ENODEV – If internal battery is not listed as an available power source.

  • 0 – If the battery status has been updated successfully.

int lwm2m_carrier_device_type_set(const char *device_type)

Set the LWM2M device type.

Note

Type of the LWM2M device specified by the manufacturer.

Parameters
  • device_type[in] Null terminated string specifying the type of the LWM2M device.

Returns

  • -EINVAL – If the input argument is a NULL pointer or an empty string.

  • -E2BIG – If the input string is too long.

  • -ENOMEM – If it was not possible to allocate memory storage to hold the string.

  • 0 – If the device type has been set successfully.

int lwm2m_carrier_hardware_version_set(const char *hardware_version)

Set the LWM2M device hardware version.

Note

LWM2M device hardware version.

Parameters
  • hardware_version[in] Null terminated string specifying the hardware version of the LWM2M device.

Returns

  • -EINVAL – If the input argument is a NULL pointer or an empty string.

  • -E2BIG – If the input string is too long.

  • -ENOMEM – If it was not possible to allocate memory storage to hold the string.

  • 0 – If the hardware version has been set successfully.

int lwm2m_carrier_software_version_set(const char *software_version)

Set the LWM2M device software version.

Note

High level device software version (application).

Parameters
  • software_version[in] Null terminated string specifying the current software version of the LWM2M device.

Returns

  • -EINVAL – If the input argument is a NULL pointer or an empty string.

  • -E2BIG – If the input string is too long.

  • -ENOMEM – If it was not possible to allocate memory storage to hold the string.

  • 0 – If the software version has been set successfully.

int lwm2m_carrier_error_code_add(int32_t error)

Update the device object instance error code by adding an individual error.

Note

Upon initialization of the device object instance, the error code is specified as 0, indicating no error. The error code is to be updated whenever a new error occurs.

Note

If the reported error is NO_ERROR, all existing error codes will be reset.

Note

If the reported error is already present, the error code will remain unchanged.

Parameters
  • error[in] Individual error to be added.

Returns

  • -EINVAL – If the error code is not supported.

  • 0 – If the error code has been added successfully.

int lwm2m_carrier_error_code_remove(int32_t error)

Update the device object instance error code by removing an individual error.

Note

Upon initialization of the device object instance, the error code is specified as 0, indicating no error. The error code is to be updated whenever an error is no longer present. When all the errors are removed, the error code is specified as 0, hence indicating no error again.

Parameters
  • error[in] Individual error code to be removed.

Returns

  • -EINVAL – If the error code is not supported.

  • -ENOENT – If the error to be removed is not present on the error code list.

  • 0 – If the error has been removed successfully.

int lwm2m_carrier_memory_total_set(uint32_t memory_total)

Set the total amount of storage space to store data and software in the LWM2M Device.

Note

The value is expressed in kilobytes (kB).

Parameters
  • memory_total[in] Total amount of storage space in kilobytes.

Returns

  • -EINVAL – It the reported value is bigger than INT32_MAX.

  • 0 – If the total amount of storage space has been set successfully.

int lwm2m_carrier_memory_free_read(void)

Read the estimated current available amount of storage space to store data and software in the LWM2M Device.

Note

This function must be implemented by the application in order to support the reporting of memory free, otherwise the returned value will be 0.

Returns

Available amount of storage space expressed in kB.

int lwm2m_carrier_identity_read(uint16_t instance_id, uint16_t identity_type, char *buffer, uint16_t *buffer_len)

Read the Identity field of a given Portfolio object instance.

Note

If the provided buffer is NULL, the function will perform a dry run to determine the required buffer size (including the null terminator).

Parameters
  • instance_id[in] Portfolio object instance identifier.

  • identity_type[in] Type of Identity field to be read.

  • buffer[inout] Buffer where the null-terminated response will be stored.

  • buffer_len[inout] Length of the provided buffer. Will return the number of bytes of the full response.

Returns

  • -ENOENT – If the instance does not exist.

  • -EINVAL – If the provided buffer length reference is NULL or the identity type is invalid.

  • -ENOMEM – If the provided buffer is too small.

  • 0 – If the operation was successful.

int lwm2m_carrier_identity_write(uint16_t instance_id, uint16_t identity_type, const char *value)

Set the corresponding Identity field of a Portfolio object instance to a given value.

Parameters
  • instance_id[in] Portfolio object instance identifier.

  • identity_type[in] Type of Identity field to be written.

  • value[in] Null terminated string to be written into the Identity field.

Returns

  • -EPERM – If the specified object instance ID corresponds to the Primary Host identity.

  • -EINVAL – If the input argument is a NULL pointer or an empty string, or the identity type is invalid.

  • -ENOENT – If the instance does not exist.

  • -E2BIG – If the input string is too long.

  • -ENOMEM – If it was not possible to allocate memory storage to hold the string.

  • 0 – If the Identity field has been updated successfully.

int lwm2m_carrier_portfolio_instance_create(uint16_t instance_id)

Create a new instance of the Portfolio object.

Parameters
  • instance_id[in] The identifier to be used for the new instance.

Returns

  • -ENOMEM – If it was not possible to create the instance because the maximum number of supported object instances has already been reached.

  • -EINVAL – If the provided instance identifier is already in use.

  • 0 – If the instance has been created successfully.

struct lwm2m_carrier_event_t
#include <lwm2m_carrier.h>

LWM2M carrier library event structure.

Public Members

uint32_t type

Event type.

const void *data

Event data. Can be NULL, depending on event type.

struct lwm2m_carrier_event_deferred_t
#include <lwm2m_carrier.h>

Public Members

uint32_t reason

Deferred event reason.

int32_t timeout

Time before operation is resumed (seconds).

struct lwm2m_carrier_event_error_t
#include <lwm2m_carrier.h>

LWM2M carrier library error event structure.

Public Members

uint32_t code

Error event code.

int32_t value

Error event value.

struct ca_cert_tags_t
#include <lwm2m_carrier.h>

Structure holding security tags for CA certificates to be applied by the LwM2M carrier library.

Public Members

int *tags

Pointer to static array of available security tags

int count

Number of available security tags

struct lwm2m_carrier_config_t
#include <lwm2m_carrier.h>

Structure holding LWM2M carrier library initialization parameters.

Public Members

const char *bootstrap_uri

URI of the bootstrap server, null-terminated string.

const char *psk

Pre-Shared Key for the bootstrap server, null-terminated hexadecimal string.

const char *apn

Optional custom APN, null-terminated string.

bool certification_mode

Connect to certification servers if true, connect to production servers otherwise.

LWM2M OS layer

group lwm2m_carrier_os

Defines

LWM2M_OS_MAX_WORK_QS

Maximum number of work queues that the system must support.

LWM2M_OS_MAX_TIMER_COUNT

Maximum number of timers that the system must support.

LWM2M_OS_MAX_SEM_COUNT

Maximum number of semaphores that the system must support.

LWM2M_LOG_LEVEL_NONE
LWM2M_LOG_LEVEL_ERR
LWM2M_LOG_LEVEL_WRN
LWM2M_LOG_LEVEL_INF
LWM2M_LOG_LEVEL_TRC
LWM2M_OS_LTE_MODE_NONE
LWM2M_OS_LTE_MODE_CAT_M1
LWM2M_OS_LTE_MODE_CAT_NB1
LWM2M_OS_STORAGE_BASE

Range of the non-volatile storage identifiers used by the library.

Note

The application MUST NOT use the values within this range for its own non-volatile storage management as it could potentially delete or overwrite entries used by the library.

LWM2M_OS_STORAGE_END

Typedefs

typedef void lwm2m_os_work_q_t
typedef void lwm2m_os_timer_t
typedef void lwm2m_os_sem_t
typedef void (*lwm2m_os_timer_handler_t)(void *timer)

Timer callback function.

typedef void (*lwm2m_os_sms_callback_t)(struct lwm2m_os_sms_data *const data, void *context)

SMS subscriber callback function.

typedef void (*lwm2m_os_at_cmd_handler_t)(void *ctx, const char *response)

AT Command handler.

typedef int (*lwm2m_os_download_callback_t)(const struct lwm2m_os_download_evt *event)

Download client asynchronous event handler.

typedef void (*lwm2m_os_pdn_event_handler_t)(uint8_t cid, enum lwm2m_os_pdn_event event, int reason)

PDN event handler.

If assigned during PDP context creation, the event handler will receive status information relative to the Packet Data Network connection, as reported by the AT notifications CNEC and GGEV.

This handler is executed by the same context that dispatches AT notifications.

Enums

enum lwm2m_os_pdn_fam

PDN family.

Values:

enumerator LWM2M_OS_PDN_FAM_IPV4
enumerator LWM2M_OS_PDN_FAM_IPV6
enumerator LWM2M_OS_PDN_FAM_IPV4V6
enum lwm2m_os_pdn_event

PDN event.

Values:

enumerator LWM2M_OS_PDN_EVENT_CNEC_ESM
enumerator LWM2M_OS_PDN_EVENT_ACTIVATED
enumerator LWM2M_OS_PDN_EVENT_DEACTIVATED
enumerator LWM2M_OS_PDN_EVENT_IPV6_UP
enumerator LWM2M_OS_PDN_EVENT_IPV6_DOWN

Functions

int lwm2m_os_pdn_init(void)

Initialize the PDN functionality.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_ctx_create(uint8_t *cid, lwm2m_os_pdn_event_handler_t cb)

Create a Packet Data Protocol (PDP) context.

If a callback is provided via the cb parameter, generate events from the CNEC and GGEV AT notifications to report state of the Packet Data Network (PDN) connection.

Parameters
  • cid[out] The ID of the new PDP context.

  • cb – Optional event handler.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_ctx_configure(uint8_t cid, const char *apn, enum lwm2m_os_pdn_fam family)

Configure a Packet Data Protocol context.

Parameters
  • cid – The PDP context to configure.

  • apn – The Access Point Name to configure the PDP context with.

  • family – The family to configure the PDN context for.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_ctx_destroy(uint8_t cid)

Destroy a Packet Data Protocol context.

Parameters
  • cid – The PDP context to destroy.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_activate(uint8_t cid, int *esm)

Activate a Packet Data Network (PDN) connection.

Parameters
  • cid – The PDP context ID to activate a connection for.

  • esm[out] If provided, the function will block to return the ESM error reason.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_deactivate(uint8_t cid)

Deactivate a Packet Data Network (PDN) connection.

Parameters
  • cid – The PDP context ID.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_id_get(uint8_t cid)

Retrieve the PDN ID for a given PDP Context.

The PDN ID can be used to route traffic through a Packet Data Network.

Parameters
  • cid – The context ID of the PDN connection.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_default_apn_get(char *buf, size_t len)

Retrieve the default Access Point Name (APN).

The default APN is the APN of the default PDP context (zero).

Parameters
  • buf – The buffer to copy the APN into.

  • len – The size of the output buffer.

Returns

int Zero on success or an errno otherwise.

int lwm2m_os_pdn_default_callback_set(lwm2m_os_pdn_event_handler_t cb)

Set a callback for events pertaining to the default PDP context (zero).

Parameters
  • cb – The PDN event handler.

int lwm2m_os_init(void)

Initialize the LWM2M OS layer.

void *lwm2m_os_malloc(size_t size)

Allocate memory.

void lwm2m_os_free(void *ptr)

Free memory.

int lwm2m_os_sem_init(lwm2m_os_sem_t **sem, unsigned int initial_count, unsigned int limit)

Initialize a semaphore.

Parameters
  • sem – Address of the pointer to the semaphore.

  • initial_count – Initial semaphore count.

  • limit – Maximum permitted semaphore count.

Returns

  • 0 – Semaphore created successfully

  • -EINVAL – Invalid values

int lwm2m_os_sem_take(lwm2m_os_sem_t *sem, int timeout)

Take a semaphore.

Parameters
  • sem – Address of the semaphore.

  • timeout – Timeout in ms or -1 for forever.

Returns

  • 0 – Semaphore taken.

  • -EBUSY – Returned without waiting.

  • -EAGAIN – Waiting period timed out.

void lwm2m_os_sem_give(lwm2m_os_sem_t *sem)

Give a semaphore.

Parameters
  • sem – Address of the semaphore.

void lwm2m_os_sem_reset(lwm2m_os_sem_t *sem)

Reset a semaphore.

Parameters
  • sem – Address of the semaphore.

int64_t lwm2m_os_uptime_get(void)

Get uptime, in milliseconds.

int64_t lwm2m_os_uptime_delta(int64_t *ref)

Get uptime delta, in milliseconds.

int lwm2m_os_sleep(int ms)

Put a thread to a sleep.

void lwm2m_os_sys_reset(void)

Reboot system.

uint32_t lwm2m_os_rand_get(void)

Get a random value.

int lwm2m_os_storage_delete(uint16_t id)

Delete a non-volatile storage entry.

int lwm2m_os_storage_read(uint16_t id, void *data, size_t len)

Read an entry from non-volatile storage.

int lwm2m_os_storage_write(uint16_t id, const void *data, size_t len)

Write an entry to non-volatile storage.

lwm2m_os_work_q_t *lwm2m_os_work_q_start(int index, const char *name)

Start a workqueue.

Parameters
  • index – number of the queue.

  • name – Name of the queue.

Returns

Workqueue.

lwm2m_os_timer_t *lwm2m_os_timer_get(lwm2m_os_timer_handler_t handler)

Reserve a timer task from the OS.

Parameters
  • handler – Function to run for this task.

Returns

Timer – task.

void lwm2m_os_timer_release(lwm2m_os_timer_t *timer)

Release a timer task.

int lwm2m_os_timer_start(lwm2m_os_timer_t *timer, int64_t timeout)

Start a timer on system work queue.

Parameters
  • timer – Timer task.

  • timeout – Delay before submitting the task in ms.

Returns

  • 0 – If timeout is NO_WAIT and work was already on a queue

  • 1 – If timeout is NO_WAIT and work was not submitted but has now been queued to workqueue; or timeout is not NO_WAIT and work has been scheduled

  • 2 – If delay is NO_WAIT and work was running and has been queued to the queue that was running it

  • -EINVAL – timer not found.

int lwm2m_os_timer_start_on_q(lwm2m_os_work_q_t *work_q, lwm2m_os_timer_t *timer, int64_t msec)

Start a timer on a specific queue.

Parameters
  • work_q – Workqueue.

  • timer – Timer task.

  • msec – Delay before submitting the task in ms.

Returns

  • 0 – If timeout is NO_WAIT and work was already on a queue

  • 1 – If timeout is NO_WAIT and work was not submitted but has now been queued to work_q; or timeout is not NO_WAIT and work has been scheduled

  • 2 – If delay is NO_WAIT and work was running and has been queued to the queue that was running it

  • -EINVAL – Timer or work_q not found.

void lwm2m_os_timer_cancel(lwm2m_os_timer_t *timer)

Cancel a timer run.

Parameters
  • timer – Timer task.

int64_t lwm2m_os_timer_remaining(lwm2m_os_timer_t *timer)

Obtain the time remaining on a timer.

Parameters
  • timer – Timer task.

Returns

Time – remaining in ms.

bool lwm2m_os_timer_is_pending(lwm2m_os_timer_t *timer)

Check if a timer task is pending.

Parameters
  • timer – Timer task.

Returns

true – if a timer task is pending.

const char *lwm2m_os_log_strdup(const char *str)

Create a string copy for a logger subsystem.

void lwm2m_os_log(int level, const char *fmt, ...)

Log a message.

void lwm2m_os_logdump(int level, const char *msg, const void *data, size_t len)

Print a data dump via logger.

Parameters
  • level – Level.

  • msg – Log message.

  • data – Data to dump.

  • len – Data length.

int lwm2m_os_nrf_modem_init(void)

Initialize modem library.

Returns

0 on success

Returns

-1 on error

Returns

an error from nrf_modem_dfu in case of modem DFU.

int lwm2m_os_nrf_modem_shutdown(void)

Shutdown the Modem library.

Returns

0 on success, -1 otherwise.

int lwm2m_os_at_init(void)

Initialize AT command driver.

int lwm2m_os_sms_init(void)

Initialize SMS subscriber library.

void lwm2m_os_sms_uninit(void)

Uninitialize SMS subscriber library.

int lwm2m_os_at_notif_register_handler(void *context, lwm2m_os_at_cmd_handler_t handler)

Set AT command global notification handler.

int lwm2m_os_sms_client_register(lwm2m_os_sms_callback_t lib_callback, void *context)

Register as an SMS client/listener.

void lwm2m_os_sms_client_deregister(int handle)

degister as an SMS client/listener.

int lwm2m_os_at_cmd_write(const char *const cmd, char *buf, size_t buf_len)

Send an AT command and receive response immediately.

void lwm2m_os_at_params_list_free(struct lwm2m_os_at_param_list *list)

Free a list of AT parameters.

int lwm2m_os_at_params_list_init(struct lwm2m_os_at_param_list *list, size_t max_params_count)

Create a list of AT parameters.

int lwm2m_os_at_params_int_get(struct lwm2m_os_at_param_list *list, size_t index, uint32_t *value)

Get a parameter value as an integer number.

int lwm2m_os_at_params_short_get(struct lwm2m_os_at_param_list *list, size_t index, uint16_t *value)

Get a parameter value as a short number.

int lwm2m_os_at_params_string_get(struct lwm2m_os_at_param_list *list, size_t index, char *value, size_t *len)

Get a parameter value as a string.

int lwm2m_os_at_params_list_clear(struct lwm2m_os_at_param_list *list)

Clear/reset all parameter types and values.

int lwm2m_os_at_parser_params_from_str(const char *at_params_str, char **next_param_str, struct lwm2m_os_at_param_list *const list)

Parse AT command or response parameters from a string.

int lwm2m_os_at_params_valid_count_get(struct lwm2m_os_at_param_list *list)

Get the number of valid parameters in the list.

int lwm2m_os_download_connect(const char *host, const struct lwm2m_os_download_cfg *cfg)

Establish a connection with the server.

int lwm2m_os_download_disconnect(void)

Disconnect from the server.

int lwm2m_os_download_init(lwm2m_os_download_callback_t lib_callback)

Initialize the download client.

int lwm2m_os_download_start(const char *file, size_t from)

Download a file.

int lwm2m_os_download_file_size_get(size_t *size)

Retrieve size of file being downloaded.

Parameters
  • size – Size of the file being downloaded.

int lwm2m_os_lte_power_down(void)
int32_t lwm2m_os_lte_mode_get(void)
int lwm2m_os_errno(void)

Translate the error number.

const char *lwm2m_os_strerror(void)

Return a textual description for the current error.

int lwm2m_os_sec_ca_chain_exists(uint32_t sec_tag, bool *exists, uint8_t *perm)

Check if a certificate chain credential exists in persistent storage.

Parameters
  • sec_tag[in] The tag to search for.

  • exists[out] Whether the credential exists. Only valid if the operation is successful.

  • perm[out] The permission flags of the credential. Not yet implemented.

Returns

  • 0 – On success.

  • -ENOBUFS – Insufficient memory.

  • -EPERM – Insufficient permissions.

int lwm2m_os_sec_ca_chain_cmp(uint32_t sec_tag, const void *buf, size_t len)

Compare a certificate chain.

Parameters
  • sec_tag[in] Security tag associated with the certificate chain.

  • buf[in] Buffer to compare the certificate chain to.

  • len[in] Length of the certificate chain.

Returns

  • 0 – If the certificate chain match.

  • 1 – If the certificate chain do not match.

  • < – 0 On error.

int lwm2m_os_sec_ca_chain_write(uint32_t sec_tag, const void *buf, size_t len)

Provision a certificate chain or update an existing one.

Note

If used when the LTE link is active, the function will return an error and the key will not be written.

Parameters
  • sec_tag[in] Security tag for this credential.

  • buf[in] Buffer containing the credential data.

  • len[in] Length of the buffer.

Returns

  • 0 – On success.

  • -EINVAL – Invalid parameters.

  • -ENOBUFS – Internal buffer is too small.

  • -EACCES – The operation failed because the LTE link is active.

  • -ENOMEM – Not enough memory to store the credential.

  • -ENOENT – The security tag could not be written.

  • -EPERM – Insufficient permissions.

int lwm2m_os_sec_psk_exists(uint32_t sec_tag, bool *exists, uint8_t *perm_flags)

Check if a pre-shared key exists in persistent storage.

Parameters
  • sec_tag[in] The tag to search for.

  • exists[out] Whether the credential exists. Only valid if the operation is successful.

  • perm_flags[out] The permission flags of the credential. Only valid if the operation is successful and exists is true. Not yet implemented.

Returns

  • 0 – On success.

  • -ENOBUFS – Internal buffer is too small.

  • -EPERM – Insufficient permissions.

  • -EIO – Internal error.

int lwm2m_os_sec_psk_write(uint32_t sec_tag, const void *buf, uint16_t len)

Provision a new pre-shared key or update an existing one.

Note

If used when the LTE link is active, the function will return an error and the key will not be written.

Parameters
  • sec_tag[in] Security tag for this credential.

  • buf[in] Buffer containing the credential data.

  • len[in] Length of the buffer.

Returns

  • 0 – On success.

  • -EINVAL – Invalid parameters.

  • -ENOBUFS – Internal buffer is too small.

  • -ENOMEM – Not enough memory to store the credential.

  • -EACCES – The operation failed because the LTE link is active.

  • -ENOENT – The security tag could not be written.

  • -EPERM – Insufficient permissions.

  • -EIO – Internal error.

int lwm2m_os_sec_psk_delete(uint32_t sec_tag)

Delete pre-shared key.

Note

If used when the LTE link is active, the function will return an error and the key will not be deleted.

Parameters
  • sec_tag[in] Security tag for this credential.

Returns

  • 0 – On success.

  • -ENOBUFS – Internal buffer is too small.

  • -EACCES – The operation failed because the LTE link is active.

  • -ENOENT – No credential associated with the given sec_tag and cred_type.

  • -EPERM – Insufficient permissions.

int lwm2m_os_sec_identity_exists(uint32_t sec_tag, bool *exists, uint8_t *perm_flags)

Check if an identity credential exists in persistent storage.

Parameters
  • sec_tag[in] The tag to search for.

  • exists[out] Whether the credential exists. Only valid if the operation is successful.

  • perm_flags[out] The permission flags of the credential. Only valid if the operation is successful and exists is true. Not yet implemented.

Returns

  • 0 – On success.

  • -ENOBUFS – Internal buffer is too small.

  • -EPERM – Insufficient permissions.

  • -EIO – Internal error.

int lwm2m_os_sec_identity_write(uint32_t sec_tag, const void *buf, uint16_t len)

Provision a new identity credential or update an existing one.

Note

If used when the LTE link is active, the function will return an error and the key will not be written.

Parameters
  • sec_tag[in] Security tag for this credential.

  • buf[in] Buffer containing the credential data.

  • len[in] Length of the buffer.

Returns

  • 0 – On success.

  • -EINVAL – Invalid parameters.

  • -ENOBUFS – Internal buffer is too small.

  • -ENOMEM – Not enough memory to store the credential.

  • -EACCES – The operation failed because the LTE link is active.

  • -ENOENT – The security tag could not be written.

  • -EPERM – Insufficient permissions.

  • -EIO – Internal error.

int lwm2m_os_sec_identity_delete(uint32_t sec_tag)

Delete identity credential.

Note

If used when the LTE link is active, the function will return an error and the key will not be deleted.

Parameters
  • sec_tag[in] Security tag for this credential.

Returns

  • 0 – On success.

  • -ENOBUFS – Internal buffer is too small.

  • -EACCES – The operation failed because the LTE link is active.

  • -ENOENT – No credential associated with the given sec_tag and cred_type.

  • -EPERM – Insufficient permissions.

struct lwm2m_os_sms_deliver_address
#include <lwm2m_os.h>
struct lwm2m_os_sms_udh_app_port
#include <lwm2m_os.h>
struct lwm2m_os_sms_deliver_header
#include <lwm2m_os.h>
union lwm2m_os_sms_header
#include <lwm2m_os.h>

Public Members

struct lwm2m_os_sms_deliver_header deliver
struct lwm2m_os_sms_data
#include <lwm2m_os.h>

SMS PDU data.

Public Members

union lwm2m_os_sms_header header

SMS header.

int payload_len

Length of the data in data buffer.

char *payload

SMS message data.

struct lwm2m_os_at_param_list
#include <lwm2m_os.h>

List of AT parameters that compose an AT command or response.

struct lwm2m_os_download_evt
#include <lwm2m_os.h>

Download client event.

Public Members

int id

Event ID.

int error

Error cause.

struct lwm2m_os_download_cfg
#include <lwm2m_os.h>

Download client configuration options.