LWM2M Application Programming Interface

nRF5 SDK v15.0.0

Public API of Nordic's LWM2M implementation. More...

Modules

Types
LWMW2M Bootstrap type definitions.
Defines
LWMW2M operation code and invalid object/instance definitions.

Data Structures

struct lwm2m_object_prototype_t
LWM2M object prototype structure. More...
struct lwm2m_instance_prototype_t
LWM2M instance structure. More...

Typedefs

typedef uint32_t(* lwm2m_instance_callback_t )( lwm2m_instance_prototype_t *p_instance, uint16_t resource_id, uint8_t op_code, coap_message_t *p_request)
Callback function upon requests on a given LWM2M resource instance. More...
typedef uint32_t(* lwm2m_object_callback_t )( lwm2m_object_prototype_t *p_object, uint16_t instance_id, uint8_t op_code, coap_message_t *p_request)
Callback function upon request on a given LWM2M object or instance create. More...

Functions

uint32_t lwm2m_notification ( lwm2m_notification_type_t type, lwm2m_remote_t *p_remote, uint8_t coap_code)
Callback interface from the enabler interface (bootstrap/register) to the application. More...
uint32_t lwm2m_coap_handler_root (uint8_t op_code, coap_message_t *p_request)
CoAP Request handler for the root of the object/instance/resource hierarchy. More...
uint32_t lwm2m_init (void)
Initialize LWM2M library. More...
uint32_t lwm2m_bootstrap ( lwm2m_remote_t *p_remote, lwm2m_client_identity_t *p_id, uint16_t local_port)
Send bootstrap request to a remote bootstrap server. More...
uint32_t lwm2m_register ( lwm2m_remote_t *p_remote, lwm2m_client_identity_t *p_id, lwm2m_server_config_t *p_config, uint16_t local_port, uint8_t *p_link_format_string, uint16_t link_format_len)
Register with a remote LWM2M server. More...
uint32_t lwm2m_update ( lwm2m_remote_t *p_remote, lwm2m_server_config_t *p_config, uint16_t local_port)
Update a registration with a remote server. More...
uint32_t lwm2m_deregister ( lwm2m_remote_t *p_remote, uint16_t local_port)
Deregister from a remote server. More...
uint32_t lwm2m_coap_handler_instance_add ( lwm2m_instance_prototype_t *p_instance)
Add an instance to coap_handler in order to match requests to the given instance. More...
uint32_t lwm2m_coap_handler_instance_delete ( lwm2m_instance_prototype_t *p_instance)
Delete an instance from coap_handler in order to stop matching requests to the given instance. More...
uint32_t lwm2m_coap_handler_object_add ( lwm2m_object_prototype_t *p_object)
Add an object to coap_handler in order to match requests to the given object. More...
uint32_t lwm2m_coap_handler_object_delete ( lwm2m_object_prototype_t *p_object)
Delete an object from coap_handler in order to stop matching requests to the given object. More...
uint32_t lwm2m_coap_handler_gen_link_format (uint8_t *p_buffer, uint16_t *p_buffer_len)
Generate link format string based on registered objects and instances. More...
uint32_t lwm2m_respond_with_payload (uint8_t *p_payload, uint16_t payload_len, coap_message_t *p_request)
Send CoAP 2.05 Content response with the payload provided. More...
uint32_t lwm2m_respond_with_code ( coap_msg_code_t code, coap_message_t *p_request)
Send CoAP response with a given CoAP message code. More...

Detailed Description

Public API of Nordic's LWM2M implementation.

Typedef Documentation

typedef uint32_t(* lwm2m_instance_callback_t)( lwm2m_instance_prototype_t *p_instance, uint16_t resource_id, uint8_t op_code, coap_message_t *p_request)

Callback function upon requests on a given LWM2M resource instance.

Will be called when the request is for an instance Ex. /0/1.

If no instance could be located the object callback will be called. The instance_id corresponds to the one in the URI-patch in the CoAP request and may be used to create a new instance. If the value of resource_id is set to LWM2M_INVALID_RESOURCE the callback should treated it as a call to the instance instead of a resource inside of the instance.

If a resource has been found p_instance pointer will be set, else it will be NULL.

Parameters
[in] p_instance Pointer to the located resource if it already exists.
[in] resource_id Id of the resource requested.
[in] op_code Opcode of the request. Values of the opcodes are defined in Types .
[in] p_request Pointer to the CoAP request message.
Return values
NRF_SUCCESS Will always return success.
typedef uint32_t(* lwm2m_object_callback_t)( lwm2m_object_prototype_t *p_object, uint16_t instance_id, uint8_t op_code, coap_message_t *p_request)

Callback function upon request on a given LWM2M object or instance create.

Will be called when the request is for an object Ex: /0 or /0/1 an instance and the op_code is CREATE. Depending on the CoAP request code the user might create an instance or just return the tlv of current instances. If the value of instance_id is set to LWM2M_INVALID_INSTANCE the callback should treated it as a call to the instance instead of an instance of the object.

Parameters
[in] p_object Pointer to the located object.
[in] instance_id Id of the instance requested.
[in] op_code Opcode of the request. Values of the opcodes are defined in Types .
[in] p_request Pointer to the CoAP request message.
Return values
NRF_SUCCESS Will always return success.

Function Documentation

uint32_t lwm2m_bootstrap ( lwm2m_remote_t * p_remote ,
lwm2m_client_identity_t * p_id ,
uint16_t local_port
)

Send bootstrap request to a remote bootstrap server.

Sends a bootstrap request with specified ID to the specified remote, calls the lwm2m_notification with answer from the bootstrap server.

Parameters
[in] p_remote Pointer to the structure holding connection information of the remote LWM2M bootstrap server.
[in] p_id Pointer to the structure holding the Id of the client.
[in] local_port Port number of the local port to be used to send the bootstrap request.
Return values
NRF_SUCCESS If bootstrap request to the LWM2M bootstrap server was sent successfully.
NRF_ERROR_NULL If one of the parameters was a NULL pointer.
uint32_t lwm2m_coap_handler_gen_link_format ( uint8_t * p_buffer ,
uint16_t * p_buffer_len
)

Generate link format string based on registered objects and instances.

Note
For generation of links to work properly it is required that objects is added before instances.
Parameters
[in,out] p_buffer Pointer to a buffer to fill with link format encoded string. If a NULL pointer is provided the function will dry-run the function in order to calculate how much memory that is needed for the link format string.
[in,out] p_buffer_len As input used to indicate the length of the buffer. It will return the used amount of buffer length by reference in response. If NULL pointer is provided for p_buffer, the value by reference output will be the number of bytes needed to generate the link format string.
Return values
NRF_SUCCESS If generation of link format string was successful.
NRF_ERROR_NO_MEM If the provided memory was not large enough.
uint32_t lwm2m_coap_handler_instance_add ( lwm2m_instance_prototype_t * p_instance )

Add an instance to coap_handler in order to match requests to the given instance.

Add a new LWM2M instance to the coap_handler. The application MUST initialize and allocate the additional data in the struct.

Parameters
[in] p_instance Pointer to the instance to add.
Return values
NRF_SUCCESS If registration was successful.
NRF_ERROR_NO_MEM If the module was not able to add the instance. Verify that the LWM2M_COAP_HANDLER_MAX_INSTANCES setting in sdk_config.h has a correct value.
uint32_t lwm2m_coap_handler_instance_delete ( lwm2m_instance_prototype_t * p_instance )

Delete an instance from coap_handler in order to stop matching requests to the given instance.

Parameters
[in] p_instance Pointer to the instance to delete.
Return values
NRF_SUCCESS If unregistration was a success.
NRF_ERROR_NOT_FOUND If the given instance was not located.
uint32_t lwm2m_coap_handler_object_add ( lwm2m_object_prototype_t * p_object )

Add an object to coap_handler in order to match requests to the given object.

Add a new LWM2M object to the coap_handler. The application MUST initialize and allocate the additional data in the struct.

Parameters
[in] p_object Pointer to the object to add.
Return values
NRF_SUCCESS If registration was successful.
NRF_ERROR_NO_MEM If the module was not able to add the object. Verify that the LWM2M_COAP_HANDLER_MAX_OBJECTS setting in sdk_config.h has a correct value.
uint32_t lwm2m_coap_handler_object_delete ( lwm2m_object_prototype_t * p_object )

Delete an object from coap_handler in order to stop matching requests to the given object.

Parameters
[in] p_object Pointer to the object to delete.
Return values
NRF_SUCCESS If unregistration was a success.
NRF_ERROR_NOT_FOUND If the given object was not located.
uint32_t lwm2m_coap_handler_root ( uint8_t op_code ,
coap_message_t * p_request
)

CoAP Request handler for the root of the object/instance/resource hierarchy.

The function is called when a request is for the lwm2m root (ie no object instance or resource).

Warning
This is an interface function. MUST BE IMPLEMENTED BY APPLICATION.
Parameters
[in] op_code LWM2M operation code.
[in] p_request Pointer to CoAP request message.
Return values
NRF_SUCCESS If the handler processed the request successfully.
uint32_t lwm2m_deregister ( lwm2m_remote_t * p_remote ,
uint16_t local_port
)

Deregister from a remote server.

Parameters
[in] p_remote Pointer to the structure holding connection information of the remote LWM2M server.
[in] local_port Port number of the local port to be used to send the deregister request.
Return values
NRF_SUCCESS If deregister request to the LWM2M server was sent out successfully.
uint32_t lwm2m_init ( void )

Initialize LWM2M library.

Return values
NRF_SUCCESS If initialization was successful.
uint32_t lwm2m_notification ( lwm2m_notification_type_t type ,
lwm2m_remote_t * p_remote ,
uint8_t coap_code
)

Callback interface from the enabler interface (bootstrap/register) to the application.

Warning
This is an interface function. MUST BE IMPLEMENTED BY APPLICATION.
Parameters
[in] type Notification type. The types are defined in lwm2m_notification_type_t .
[in] p_remote remote that answered the request
[in] coap_code coap op code from the response
Return values
NRF_SUCCESS If the client application handled the notification successfully.
uint32_t lwm2m_register ( lwm2m_remote_t * p_remote ,
lwm2m_client_identity_t * p_id ,
lwm2m_server_config_t * p_config ,
uint16_t local_port ,
uint8_t * p_link_format_string ,
uint16_t link_format_len
)

Register with a remote LWM2M server.

Parameters
[in] p_remote Pointer to the structure holding connection information of the remote LWM2M server.
[in] p_id Pointer to the structure holding the Id of the client.
[in] p_config Registration parameters.
[in] local_port Port number of the local port to be used to send the register request.
[in] p_link_format_string Pointer to a link format encoded string to send in the register request.
[in] link_format_len Length of the link format string provided.
Return values
NRF_SUCCESS If registration request to the LWM2M server was sent out successfully.
uint32_t lwm2m_respond_with_code ( coap_msg_code_t code ,
coap_message_t * p_request
)

Send CoAP response with a given CoAP message code.

Parameters
[in] code CoAP response code to send.
[in] p_request Original CoAP request. Must not be NULL.
Return values
NRF_SUCCESS If the response was sent out successfully.
uint32_t lwm2m_respond_with_payload ( uint8_t * p_payload ,
uint16_t payload_len ,
coap_message_t * p_request
)

Send CoAP 2.05 Content response with the payload provided.

Parameters
[in] p_payload Pointer to the payload to send. Must not be NULL.
[in] payload_len Size of the payload.
[in] p_request Original CoAP request. Must not be NULL.
Return values
NRF_SUCCESS If the response was sent out successfully.
uint32_t lwm2m_update ( lwm2m_remote_t * p_remote ,
lwm2m_server_config_t * p_config ,
uint16_t local_port
)

Update a registration with a remote server.

Parameters
[in] p_remote Pointer to the structure holding connection information of the remote LWM2M server.
[in] p_config Registration parameters.
[in] local_port Port number of the local port to be used to send the update request.
Return values
NRF_SUCCESS If update request to the LWM2M server was sent out successfully.