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 v2 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_MODEM_DOMAIN

Modem domain event received.

LWM2M_CARRIER_EVENT_ERROR

An error occurred.

LWM2M_CARRIER_EVENT_CERTS_INIT

CA certificates need to be initialized.

LwM2M carrier library modem domain event types.

LWM2M_CARRIER_MODEM_EVENT_ME_OVERHEATED

Mobile Equipment (ME) is overheated and therefore the modem is deactivated.

LWM2M_CARRIER_MODEM_EVENT_ME_BATTERY_LOW

Mobile Equipment (ME) battery voltage is low and therefore the modem is deactivated.

LWM2M_CARRIER_MODEM_EVENT_RESET_LOOP

Modem has detected a reset loop and will restrict Attach attempts for the next 30 minutes.

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_DEFERRED_SIM_MSISDN

Waiting for SIM MSISDN.

LwM2M carrier library event error codes.

LWM2M_CARRIER_ERROR_NO_ERROR

No error.

LWM2M_CARRIER_ERROR_CONNECT_FAIL

Failed to connect to the LTE network.

LWM2M_CARRIER_ERROR_DISCONNECT_FAIL

Failed to disconnect from the LTE network.

LWM2M_CARRIER_ERROR_BOOTSTRAP

LwM2M carrier bootstrap failed.

LWM2M_CARRIER_ERROR_FOTA_PKG

Update package rejected.

LWM2M_CARRIER_ERROR_FOTA_PROTO

Protocol error.

LWM2M_CARRIER_ERROR_FOTA_CONN

Connection error.

LWM2M_CARRIER_ERROR_FOTA_CONN_LOST

Connection lost.

LWM2M_CARRIER_ERROR_FOTA_FAIL

Update failed.

LWM2M_CARRIER_ERROR_CONFIGURATION

Illegal object configuration detected.

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.

Return values
  • 0 – If success.

  • -EIO – Failed to initialize modem library or unable to read IMEI.

  • -E2BIG – The provided PSK is too large to be stored in the modem.

void lwm2m_carrier_run(void)

LwM2M carrier library main function.

Intended to run on a separate thread. The function will exit only on non-recoverable errors.

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

Function to read all time parameters.

Input NULL for the parameters to ignore.

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.

Return values
  • 0 – If success.

  • -EINVAL – If value of time is less then 0.

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.

Return values

0 – If success.

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.

Return values

0 – If success.

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.

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

  • -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.

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.

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

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

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

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.

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

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

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

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.

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

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

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

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.

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

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

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

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.

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

  • -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.

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.

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

  • -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.

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.

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

  • -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.

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.

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

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

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.

Return values
  • 0 – If the error has been removed successfully.

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

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

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.

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

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

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.

Return values
  • 0 – If the operation was successful.

  • -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.

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.

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

  • -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.

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.

Return values
  • 0 – If the instance has been created successfully.

  • -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.

int lwm2m_carrier_location_set(double latitude, double longitude, float altitude, uint32_t timestamp, float uncertainty)

Set or update the latest location information provided by GPS.

Parameters
  • latitude[in] Latitude in degrees. Must be between -90.0 and 90.0.

  • longitude[in] Longitude in degrees. Must be between -180.0 and 180.0.

  • altitude[in] Altitude is meters over sea level.

  • timestamp[in] Unix timestamp of the current GPS measurement. Must not be older than the previous timestamp passed to this function.

  • uncertainty[in] Positioning uncertainty given as a radius in meters.

Return values
  • 0 – If the location data has been updated successfully.

  • -EINVAL – If at least one input argument is incorrect.

int lwm2m_carrier_velocity_set(int heading, float speed_h, float speed_v, float uncertainty_h, float uncertainty_v)

Set or update the latest velocity information provided by GPS.

Note

Optional float arguments shall be set to NAN if they are not available to the user.

Parameters
  • heading[in] Horizontal direction of movement in degrees clockwise from North. Valid range is 0 to 359.

  • speed_h[in] Horizontal speed in meters per second. Must be non-negative.

  • speed_v[in] Optional. Vertical speed in meters per second. Positive value indicates upward motion. Negative value indicates downward motion.

  • uncertainty_h[in] Optional. Horizontal uncertainty speed, i.e. maximal deviation from the true speed, given in meters per second. Must be non-negative.

  • uncertainty_v[in] Optional. Vertical uncertainty speed in meters per second. Must be non-negative.

Return values
  • 0 – If the velocity data has been updated successfully.

  • -EINVAL – If at least one input argument is incorrect.

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

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>

LwM2M carrier library deferred event structure.

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 *server_uri

URI of the LwM2M Bootstrap-Server or LwM2M Server, null-terminated string.

bool is_bootstrap_server

Configure if server_uri is a LwM2M Bootstrap-Server or a standard LwM2M Server.

int32_t server_lifetime

Default server lifetime (in seconds), used when server_uri is a LwM2M Server.

const char *psk

Pre-Shared Key for the LwM2M 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.

bool disable_bootstrap_from_smartcard

Disable bootstrap from Smartcard mode when this is enabled by the carrier.

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_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_at_handler_callback_t)(const char *notif)

AT command error handler callback function.

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 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.

Return values

0 – If success.

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.

Return values

0 – If success.

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.

Return values

0 – If success.

int lwm2m_os_pdn_ctx_destroy(uint8_t cid)

Destroy a Packet Data Protocol context.

Parameters
  • cid – The PDP context to destroy.

Return values

0 – If success.

int lwm2m_os_pdn_activate(uint8_t cid, int *esm, enum lwm2m_os_pdn_fam *family)

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.

  • family[out] If provided, the function will block to return PDN_FAM_IPV4 if only IPv4 is supported, or PDN_FAM_IPV6 if only IPv6 is supported. Otherwise, this value will remain unchanged.

Return values

0 – If success.

int lwm2m_os_pdn_deactivate(uint8_t cid)

Deactivate a Packet Data Network (PDN) connection.

Parameters
  • cid – The PDP context ID.

Return values

0 – If success.

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.

Return values

0 – If success.

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.

Return values

0 – If success.

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.

Return values
  • 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.

Return values
  • 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 delay)

Start a timer on system work queue.

Parameters
  • timer – Timer task.

  • delay – Delay before submitting the task in ms.

Return values
  • 0 – Work placed on queue, already on queue or already running.

  • -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 delay)

Start a timer on a specific queue.

Parameters
  • work_q – Workqueue.

  • timer – Timer task.

  • delay – Delay before submitting the task in ms.

Return values
  • 0 – Work placed on queue, already on queue or already running.

  • -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.

Return values

true – If a timer task is pending.

int lwm2m_os_nrf_modem_init(void)

Initialize modem library.

Return values
  • 0 – If success.

  • -EIO – If modem initialisation failed.

Returns

A positive number nrf_modem_dfu in case of modem firmware update.

int lwm2m_os_nrf_modem_shutdown(void)

Shutdown the Modem library.

Return values
  • 0 – If success.

  • -EIO – If modem shutdown failed.

int lwm2m_os_at_init(lwm2m_os_at_handler_callback_t callback)

Initialize AT command driver.

Return values
  • 0 – If success.

  • -EIO – If AT command driver initialisation failed.

int lwm2m_os_sms_init(void)

Initialize SMS subscriber library.

void lwm2m_os_sms_uninit(void)

Uninitialize SMS subscriber library.

int lwm2m_os_sms_client_register(lwm2m_os_sms_callback_t lib_callback, void *context)

Register as an SMS client/listener.

Return values
  • 0 – If success.

  • -EIO – If unable to register as SMS listener.

void lwm2m_os_sms_client_deregister(int handle)

degister as an SMS client/listener.

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

Establish a connection with the server.

Return values

0 – If success.

int lwm2m_os_download_disconnect(void)

Disconnect from the server.

Return values

0 – If success.

int lwm2m_os_download_init(lwm2m_os_download_callback_t lib_callback)

Initialize the download client.

Return values

0 – If success.

int lwm2m_os_download_start(const char *file, size_t from)

Download a file.

Return values

0 – If success.

int lwm2m_os_download_file_size_get(size_t *size)

Retrieve size of file being downloaded.

Parameters
  • size – Size of the file being downloaded.

Return values

0 – If success.

Initialize and make a connection with the modem.

Return values

0 – If success.

Set the modem to offline mode.

int lwm2m_os_lte_power_down(void)

Set the modem to power off mode.

int32_t lwm2m_os_lte_mode_get(void)

get system mode from modem.

Return values
  • LWM2M_OS_LTE_MODE_NONE – Not connected

  • LWM2M_OS_LTE_MODE_CAT_M1 – Cat-M1 (LTE-FDD)

  • LWM2M_OS_LTE_MODE_CAT_NB1 – Cat-NB1 (NB-IOT)

int lwm2m_os_nrf_errno(void)

Translate the error number.

int lwm2m_os_sec_psk_exists(uint32_t sec_tag, bool *exists)

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.

Return values
  • 0 – If 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.

Return values
  • 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.

Return values
  • 0 – If 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.

  • -EPERM – Insufficient permissions.

int lwm2m_os_sec_identity_exists(uint32_t sec_tag, bool *exists)

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.

Return values
  • 0 – If 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.

Return values
  • 0 – If 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.

Return values
  • 0 – If 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.

  • -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_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.