Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Typedefs | Enumerations | Functions
LWM2M Server

Routines to create Servers talking the LWM2M protocol. More...

Typedefs

typedef struct
sol_lwm2m_client_info 
sol_lwm2m_client_info
 A handle that contains information about a registered LWM2M client. More...
 
typedef struct sol_lwm2m_server sol_lwm2m_server
 A handle to a LWM2M server. More...
 

Enumerations

enum  sol_lwm2m_registration_event { SOL_LWM2M_REGISTRATION_EVENT_REGISTER, SOL_LWM2M_REGISTRATION_EVENT_UPDATE, SOL_LWM2M_REGISTRATION_EVENT_UNREGISTER, SOL_LWM2M_REGISTRATION_EVENT_TIMEOUT }
 Enum that expresses a LWM2M client lifecycle changes. More...
 

Functions

const struct
sol_network_link_addr
sol_lwm2m_client_info_get_address (const struct sol_lwm2m_client_info *client)
 Gets the client address. More...
 
enum sol_lwm2m_binding_mode sol_lwm2m_client_info_get_binding_mode (const struct sol_lwm2m_client_info *client)
 Gets the client binding mode. More...
 
int sol_lwm2m_client_info_get_lifetime (const struct sol_lwm2m_client_info *client, uint32_t *lifetime)
 Gets the client lifetime in seconds. More...
 
const char * sol_lwm2m_client_info_get_location (const struct sol_lwm2m_client_info *client)
 Gets the client location path in the LWM2M server. More...
 
const char * sol_lwm2m_client_info_get_name (const struct sol_lwm2m_client_info *client)
 Gets the name of client. More...
 
const struct sol_ptr_vectorsol_lwm2m_client_info_get_objects (const struct sol_lwm2m_client_info *client)
 Get client's objects. More...
 
const char * sol_lwm2m_client_info_get_objects_path (const struct sol_lwm2m_client_info *client)
 Gets the client objects path. More...
 
const char * sol_lwm2m_client_info_get_sms_number (const struct sol_lwm2m_client_info *client)
 Gets the client SMS number. More...
 
int sol_lwm2m_server_add_observer (struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, void(*sol_lwm2m_server_content_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code, enum sol_lwm2m_content_type content_type, struct sol_str_slice content), const void *data)
 Observes a client object, instance or resource. More...
 
int sol_lwm2m_server_add_registration_monitor (struct sol_lwm2m_server *server, void(*sol_lwm2m_server_registration_event_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *cinfo, enum sol_lwm2m_registration_event event), const void *data)
 Adds a registration monitor. More...
 
int sol_lwm2m_server_create_object_instance (struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, struct sol_lwm2m_resource *resources, size_t len, void(*sol_lwm2m_server_management_status_response_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code), const void *data)
 Creates an object instance on a client. More...
 
void sol_lwm2m_server_del (struct sol_lwm2m_server *server)
 Deletes a server instance. More...
 
int sol_lwm2m_server_del_observer (struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, void(*sol_lwm2m_server_content_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code, enum sol_lwm2m_content_type content_type, struct sol_str_slice content), const void *data)
 Unobserve a client object, instance or resource. More...
 
int sol_lwm2m_server_del_registration_monitor (struct sol_lwm2m_server *server, void(*sol_lwm2m_server_registration_event_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *cinfo, enum sol_lwm2m_registration_event event), const void *data)
 Removes a registration monitor. More...
 
int sol_lwm2m_server_delete_object_instance (struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, void(*sol_lwm2m_server_management_status_response_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code), const void *data)
 Deletes an object instance on a client. More...
 
int sol_lwm2m_server_execute_resource (struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, const char *args, void(*sol_lwm2m_server_management_status_response_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code), const void *data)
 Executes an resource on a client. More...
 
const struct sol_ptr_vectorsol_lwm2m_server_get_clients (const struct sol_lwm2m_server *server)
 Gets all registerd clients. More...
 
struct sol_lwm2m_serversol_lwm2m_server_new (uint16_t coap_port, uint16_t num_sec_modes,...)
 Creates a new LWM2M server. More...
 
int sol_lwm2m_server_read (struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, void(*sol_lwm2m_server_content_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code, enum sol_lwm2m_content_type content_type, struct sol_str_slice content), const void *data)
 Reads an object, instance or resource from a client. More...
 
int sol_lwm2m_server_write (struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, struct sol_lwm2m_resource *resources, size_t len, void(*sol_lwm2m_server_management_status_response_cb)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code), const void *data)
 Writes an object instance or resource. More...
 

Detailed Description

Routines to create Servers talking the LWM2M protocol.

Typedef Documentation

A handle that contains information about a registered LWM2M client.

See Also
sol_lwm2m_server_get_clients()

A handle to a LWM2M server.

See Also
sol_lwm2m_server_new()

Enumeration Type Documentation

Enum that expresses a LWM2M client lifecycle changes.

See Also
sol_lwm2m_server_add_registration_monitor()
Enumerator
SOL_LWM2M_REGISTRATION_EVENT_REGISTER 

Indicates that a client was registered in the server.

SOL_LWM2M_REGISTRATION_EVENT_UPDATE 

Indicates that a client updated itself in the server.

SOL_LWM2M_REGISTRATION_EVENT_UNREGISTER 

Indicates that a client was unregistered.

SOL_LWM2M_REGISTRATION_EVENT_TIMEOUT 

Indicates that the server is discarding a client, since the server did not hear from it after some time.

Function Documentation

const struct sol_network_link_addr* sol_lwm2m_client_info_get_address ( const struct sol_lwm2m_client_info client)

Gets the client address.

Parameters
clientThe LWM2M client info.
Returns
The client address or NULL on error.
enum sol_lwm2m_binding_mode sol_lwm2m_client_info_get_binding_mode ( const struct sol_lwm2m_client_info client)

Gets the client binding mode.

Parameters
clientThe LWM2M client info.
Returns
The client binding mode or SOL_LWM2M_BINDING_MODE_UNKNOWN on error.
int sol_lwm2m_client_info_get_lifetime ( const struct sol_lwm2m_client_info client,
uint32_t *  lifetime 
)

Gets the client lifetime in seconds.

Parameters
clientThe LWM2M client info.
lifetimeThe client lifetime to be set.
Returns
0 on success, -errno on error.
const char* sol_lwm2m_client_info_get_location ( const struct sol_lwm2m_client_info client)

Gets the client location path in the LWM2M server.

This value is specified by the LWM2M server and it will be used by the client to identify itself.

Parameters
clientThe LWM2M client info.
Returns
The client location path or NULL on error.
const char* sol_lwm2m_client_info_get_name ( const struct sol_lwm2m_client_info client)

Gets the name of client.

Parameters
clientThe LWM2M client info.
Returns
The client name or NULL on error.
Examples:
/src/samples/coap/lwm2m-server.c.

Referenced by create_cb(), location_changed_cb(), and registration_cb().

const struct sol_ptr_vector* sol_lwm2m_client_info_get_objects ( const struct sol_lwm2m_client_info client)

Get client's objects.

Parameters
clientThe LWM2M client info.
Returns
A array of sol_lwm2m_client_object or NULL on error.
Note
One must not add or remove elements from the returned vector.
Be advised that it's not recommended to store object pointers, because during the client's update method, all the objects are renewed.
See Also
sol_lwm2m_client_object
Examples:
/src/samples/coap/lwm2m-server.c.

Referenced by get_location_object_status().

const char* sol_lwm2m_client_info_get_objects_path ( const struct sol_lwm2m_client_info client)

Gets the client objects path.

A LWM2M client may specify an alternate objects path.

Parameters
clientThe LWM2M client info.
Returns
The objects path or NULL.
Note
The objects path may be NULL.
const char* sol_lwm2m_client_info_get_sms_number ( const struct sol_lwm2m_client_info client)

Gets the client SMS number.

A client may specify an SMS number to be used for communication.

Parameters
clientThe LWM2M client info.
Returns
The SMS number or NULL.
int sol_lwm2m_server_add_observer ( struct sol_lwm2m_server server,
struct sol_lwm2m_client_info client,
const char *  path,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code, enum sol_lwm2m_content_type content_type, struct sol_str_slice content)  sol_lwm2m_server_content_cb,
const void *  data 
)

Observes a client object, instance or resource.

Every time the observed path changes, the client will notify the LWM2M server.

Parameters
serverThe LWM2M server.
clientThe LWM2M client to be observed.
pathThe path to be observed (Example: /3/0/0).
sol_lwm2m_server_content_cbA callback to be called when the observed path changes, used to inform a observable/read response. - server The LWM2M server; client The LWM2M client; path The client's path; response_code The response code; content_type The response content type; content The response content; data User data.
dataUser data to sol_lwm2m_server_content_cb
Returns
0 on success, -errno on error.
See Also
sol_lwm2m_server_del_observer()
Examples:
/src/samples/coap/lwm2m-server.c.

Referenced by observe_location().

int sol_lwm2m_server_add_registration_monitor ( struct sol_lwm2m_server server,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *cinfo, enum sol_lwm2m_registration_event event)  sol_lwm2m_server_registration_event_cb,
const void *  data 
)

Adds a registration monitor.

This function registers a monitor, making it easier to observe a LWM2M client's life cycle. This means that every time a LWM2M client is registered, updated, deleted or timed out, sol_lwm2m_server_registration_event_cb will be called.

Parameters
serverThe LWM2M server.
sol_lwm2m_server_registration_event_cbA callback that is used to inform a LWM2M client registration event - data User data; server The LWM2M server; cinfo The client that generated the registration event; event The registration event itself.
dataThe user data to sol_lwm2m_server_registration_event_cb.
Returns
0 on success, -errno on error.
See Also
sol_lwm2m_server_del_registration_monitor()
Examples:
/src/samples/coap/lwm2m-server.c.

Referenced by main().

int sol_lwm2m_server_create_object_instance ( struct sol_lwm2m_server server,
struct sol_lwm2m_client_info client,
const char *  path,
struct sol_lwm2m_resource resources,
size_t  len,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code)  sol_lwm2m_server_management_status_response_cb,
const void *  data 
)

Creates an object instance on a client.

Parameters
serverThe LWM2M server.
clientThe LWM2M client info to create an object instance.
pathThe object path to be created (Example /1).
resourcesAn array of sol_lwm2m_resource which contains the required resources to create an object.
lenThe length of resources.
sol_lwm2m_server_management_status_response_cbA callback to be called when the create operation is completed. - server The LW2M server; client The LWM2M client; path The client's path; response_code The operation's response_code; data User data.
dataUser data to sol_lwm2m_server_management_status_response_cb
Returns
0 on success, -errno on error.
Note
All data is sent using TLV.
Examples:
/src/samples/coap/lwm2m-server.c.

Referenced by create_location_obj().

void sol_lwm2m_server_del ( struct sol_lwm2m_server server)

Deletes a server instance.

Use this function to stop the LWM2M server and release its resources.

Parameters
serverThe LWM2M server to be deleted.
See Also
sol_lwm2m_server_new()
Examples:
/src/samples/coap/lwm2m-server.c.

Referenced by main().

int sol_lwm2m_server_del_observer ( struct sol_lwm2m_server server,
struct sol_lwm2m_client_info client,
const char *  path,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code, enum sol_lwm2m_content_type content_type, struct sol_str_slice content)  sol_lwm2m_server_content_cb,
const void *  data 
)

Unobserve a client object, instance or resource.

Parameters
serverThe LWM2M server.
clientThe LWM2M client to be unobserved.
pathThe path to be unobserved (Example: /3/0/0).
sol_lwm2m_server_content_cbThe previous registered callback. - server The LWM2M server; client The LWM2M client; path The client's path; @ response_code The response code; content_type The response content type; content The response content; data User data.
dataUser data to sol_lwm2m_server_content_cb
Returns
0 on success, -errno on error.
Note
In order do completly unobserve a path, all observers must be deleted.
See Also
sol_lwm2m_server_add_observer()
int sol_lwm2m_server_del_registration_monitor ( struct sol_lwm2m_server server,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *cinfo, enum sol_lwm2m_registration_event event)  sol_lwm2m_server_registration_event_cb,
const void *  data 
)

Removes a registration monitor.

Parameters
serverThe LWM2M server.
sol_lwm2m_server_registration_event_cbThe previous registered callback. - data User data; server The LWM2M server; cinfo The client that generated the registration event; event The registration event itself.
dataThe user data to sol_lwm2m_server_registration_event_cb.
Returns
0 on success, -errno on error.
See Also
sol_lwm2m_server_add_registration_monitor()
int sol_lwm2m_server_delete_object_instance ( struct sol_lwm2m_server server,
struct sol_lwm2m_client_info client,
const char *  path,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code)  sol_lwm2m_server_management_status_response_cb,
const void *  data 
)

Deletes an object instance on a client.

Parameters
serverThe LWM2M server.
clientThe LWM2M client info to delete an object
pathThe object path to be deleted (Example /1/1).
sol_lwm2m_server_management_status_response_cbA callback to be called when the delete operation is completed. - server The LW2M server; client The LWM2M client; path The client's path; response_code The operation's response_code; data User data.
dataUser data to sol_lwm2m_server_management_status_response_cb
Returns
0 on success, -errno on error.
int sol_lwm2m_server_execute_resource ( struct sol_lwm2m_server server,
struct sol_lwm2m_client_info client,
const char *  path,
const char *  args,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code)  sol_lwm2m_server_management_status_response_cb,
const void *  data 
)

Executes an resource on a client.

Parameters
serverThe LWM2M server.
clientThe LWM2M client info to execute the resource.
pathThe object path to be executed (Example /1/1/8).
argsArguments to the execute command.
sol_lwm2m_server_management_status_response_cbA callback to be called when the execute operation is completed. - server The LW2M server; client The LWM2M client; path The client's path; response_code The operation's response_code; data User data.
dataUser data to sol_lwm2m_server_management_status_response_cb
Returns
0 on success, -errno on error.
const struct sol_ptr_vector* sol_lwm2m_server_get_clients ( const struct sol_lwm2m_server server)

Gets all registerd clients.

Parameters
serverThe LWM2M Server.
Returns
a vector of sol_lwm2m_client_info or NULL on error.
Note
One must not add or remove elements from the returned vector.
See Also
sol_lwm2m_server_add_registration_monitor()
struct sol_lwm2m_server* sol_lwm2m_server_new ( uint16_t  coap_port,
uint16_t  num_sec_modes,
  ... 
)

Creates a new LWM2M server.

The server will be immediately operational and waiting for connections.

Parameters
coap_portThe UDP port to be used for the NoSec CoAP Server.
num_sec_modesThe number of DTLS Security Modes this Bootstrap Server will support.
...An uint16_t indicating the UDP port to be used for the Secure DTLS Server; and at least one sol_lwm2m_security_mode followed by its relevant parameters, as per the table below:
Security Mode Follow-up arguments Description
SOL_LWM2M_SECURITY_MODE_PRE_SHARED_KEY struct sol_lwm2m_security_psk **known_psks known_psks The Clients' Pre-Shared Keys this Server has previous knowledge of. It MUST be a NULL-terminated array.
SOL_LWM2M_SECURITY_MODE_RAW_PUBLIC_KEY struct sol_lwm2m_security_rpk *rpk, struct sol_blob **known_pub_keys rpk This Server's Key Pair - known_pub_keys The Clients' Public Keys this Bootstrap Server has previous knowledge of. It MUST be a NULL-terminated array.
Note
: SOL_LWM2M_SECURITY_MODE_CERTIFICATE is not supported yet.
Returns
The LWM2M server or NULL on error.
Examples:
/src/samples/coap/lwm2m-server.c.

Referenced by main().

int sol_lwm2m_server_read ( struct sol_lwm2m_server server,
struct sol_lwm2m_client_info client,
const char *  path,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code, enum sol_lwm2m_content_type content_type, struct sol_str_slice content)  sol_lwm2m_server_content_cb,
const void *  data 
)

Reads an object, instance or resource from a client.

Parameters
serverThe LWM2M server.
clientThe LWM2M client info to be read.
pathThe path to be read (Example /3/0/0).
sol_lwm2m_server_content_cbA callback to be called when the read operation is completed. - server The LWM2M server; client The LWM2M client; path The client's path; response_code The response code; content_type The response content type; content The response content; data User data.
dataUser data to sol_lwm2m_server_content_cb
Returns
0 on success, -errno on error.
int sol_lwm2m_server_write ( struct sol_lwm2m_server server,
struct sol_lwm2m_client_info client,
const char *  path,
struct sol_lwm2m_resource resources,
size_t  len,
void(*)(void *data, struct sol_lwm2m_server *server, struct sol_lwm2m_client_info *client, const char *path, enum sol_coap_response_code response_code)  sol_lwm2m_server_management_status_response_cb,
const void *  data 
)

Writes an object instance or resource.

Parameters
serverThe LWM2M server.
clientThe LWM2M client info to write
pathThe object path to be written (Example /1/1).
resourcesAn array of sol_lwm2m_resource
lenThe length of resources
sol_lwm2m_server_management_status_response_cbA callback to be called when the write operation is completed. - server The LW2M server; client The LWM2M client; path The client's path; response_code The operation's response_code; data User data.
dataUser data to sol_lwm2m_server_management_status_response_cb
Returns
0 on success, -errno on error.
Note
All data is sent using TLV.