nRF5 IoT SDK  v0.9.0
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LWM2M Application Programming Interface

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_instancePointer to the located resource if it already exists.
[in]resource_idId of the resource requested.
[in]op_codeOpcode of the request. Values of the opcodes are defined in Types.
[in]p_requestPointer to the CoAP request message.
Return values
NRF_SUCCESSWill 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_objectPointer to the located object.
[in]instance_idId of the instance requested.
[in]op_codeOpcode of the request. Values of the opcodes are defined in Types.
[in]p_requestPointer to the CoAP request message.
Return values
NRF_SUCCESSWill 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_remotePointer to the structure holding connection information of the remote LWM2M bootstrap server.
[in]p_idPointer to the structure holding the Id of the client.
[in]local_portPort number of the local port to be used to send the bootstrap request.
Return values
NRF_SUCCESSIf bootstrap request to the LWM2M bootstrap server was sent successfully.
NRF_ERROR_NULLIf 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_bufferPointer 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_lenAs 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_SUCCESSIf generation of link format string was successfull.
NRF_ERROR_NO_MEMIf 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_instancePointer to the instance to add.
Return values
NRF_SUCCESSIf registration was successfull.
NRF_ERROR_NO_MEMIf 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_instancePointer to the instance to delete.
Return values
NRF_SUCCESSIf unregistration was a success.
NRF_ERROR_NOT_FOUNDIf 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_objectPointer to the object to add.
Return values
NRF_SUCCESSIf registration was successfull.
NRF_ERROR_NO_MEMIf 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_objectPointer to the object to delete.
Return values
NRF_SUCCESSIf unregistration was a success.
NRF_ERROR_NOT_FOUNDIf 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_codeLWM2M operation code.
[in]p_requestPointer to CoAP request message.
Return values
NRF_SUCCESSIf 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_remotePointer to the structure holding connection information of the remote LWM2M server.
[in]local_portPort number of the local port to be used to send the deregister request.
Return values
NRF_SUCCESSIf deregister request to the LWM2M server was sent out successfully.
uint32_t lwm2m_init ( void  )

Initialize LWM2M library.

Return values
NRF_SUCCESSIf initialization was successfull.
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]typeNotification type. The types are defined in lwm2m_notification_type_t.
[in]p_remoteremote that answered the request
[in]coap_codecoap op code from the response
Return values
NRF_SUCCESSIf 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_remotePointer to the structure holding connection information of the remote LWM2M server.
[in]p_idPointer to the structure holding the Id of the client.
[in]p_configRegistration parameters.
[in]local_portPort number of the local port to be used to send the register request.
[in]p_link_format_stringPointer to a link format encoded string to send in the register request.
[in]link_format_lenLength of the link format string provided.
Return values
NRF_SUCCESSIf 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]codeCoAP response code to send.
[in]p_requestOriginal CoAP request. Must not be NULL.
Return values
NRF_SUCCESSIf 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_payloadPointer to the payload to send. Must not be NULL.
[in]payload_lenSize of the payload.
[in]p_requestOriginal CoAP request. Must not be NULL.
Return values
NRF_SUCCESSIf 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_remotePointer to the structure holding connection information of the remote LWM2M server.
[in]p_configRegistration parameters.
[in]local_portPort number of the local port to be used to send the update request.
Return values
NRF_SUCCESSIf update request to the LWM2M server was sent out successfully.