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
Data Structures | Macros | Functions | Variables
lwm2m-client.c File Reference
#include "sol-lwm2m-client.h"
#include "sol-mainloop.h"
#include "sol-vector.h"
#include "sol-util.h"
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>

Data Structures

struct  access_control_obj_instance_ctx
 
struct  acl_instance
 
struct  client_data_ctx
 
struct  location_obj_instance_ctx
 
struct  security_obj_instance_ctx
 
struct  server_obj_instance_ctx
 

Macros

#define ACCESS_CONTROL_OBJ_ACL_RES_ID   (2)
 
#define ACCESS_CONTROL_OBJ_ID   (2)
 
#define ACCESS_CONTROL_OBJ_INSTANCE_RES_ID   (1)
 
#define ACCESS_CONTROL_OBJ_OBJECT_RES_ID   (0)
 
#define ACCESS_CONTROL_OBJ_OWNER_RES_ID   (3)
 
#define BS_SERVER_PUBLIC_KEY
 
#define CLIENT_BS_PSK_ID   ("cli1-bs")
 
#define CLIENT_BS_PSK_KEY   ("FEDCBA9876543210")
 
#define CLIENT_PRIVATE_KEY   ("D9E2707A72DA6A0504995C86EDDBE3EFC7F1CD74838F7570C8072D0A76261BD4")
 
#define CLIENT_PUBLIC_KEY
 
#define CLIENT_SERVER_PSK_ID   ("cli1")
 
#define CLIENT_SERVER_PSK_KEY   ("0123456789ABCDEF")
 
#define LIFETIME   (60)
 
#define LOCATION_OBJ_ID   (6)
 
#define LOCATION_OBJ_LATITUDE_RES_ID   (0)
 
#define LOCATION_OBJ_LONGITUDE_RES_ID   (1)
 
#define LOCATION_OBJ_TIMESTAMP_RES_ID   (5)
 
#define ONE_SECOND   (1000)
 
#define PSK_KEY_LEN   16
 
#define RPK_PRIVATE_KEY_LEN   32
 
#define RPK_PUBLIC_KEY_LEN   (2 * RPK_PRIVATE_KEY_LEN)
 
#define SECURITY_BOOTSTRAP_SERVER_ACCOUNT_TIMEOUT_RES_ID   (12)
 
#define SECURITY_CLIENT_HOLD_OFF_TIME_RES_ID   (11)
 
#define SECURITY_IS_BOOTSTRAP_RES_ID   (1)
 
#define SECURITY_OBJ_ID   (0)
 
#define SECURITY_PUBLIC_KEY_OR_IDENTITY_RES_ID   (3)
 
#define SECURITY_SECRET_KEY_RES_ID   (5)
 
#define SECURITY_SECURITY_MODE_RES_ID   (2)
 
#define SECURITY_SERVER_ID_RES_ID   (10)
 
#define SECURITY_SERVER_PUBLIC_KEY_RES_ID   (4)
 
#define SECURITY_SERVER_URI_RES_ID   (0)
 
#define SERVER_OBJ_BINDING_RES_ID   (7)
 
#define SERVER_OBJ_ID   (1)
 
#define SERVER_OBJ_LIFETIME_RES_ID   (1)
 
#define SERVER_OBJ_REGISTRATION_UPDATE_RES_ID   (8)
 
#define SERVER_OBJ_SHORT_RES_ID   (0)
 
#define SERVER_PUBLIC_KEY
 

Functions

static void bootstrap_cb (void *data, struct sol_lwm2m_client *client, enum sol_lwm2m_bootstrap_event event)
 
static bool change_location (void *data)
 
static struct sol_blobcoord_to_str (double d)
 
static int create_access_control_obj (void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
 
static int create_location_obj (void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
 
static int create_security_obj (void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
 
static int create_server_obj (void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
 
static int del_access_control_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
 
static int del_location_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
 
static int del_security_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
 
static int del_server_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
 
static int execute_server_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_str_slice args)
 
int main (int argc, char *argv[])
 
static int read_access_control_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
 
static int read_location_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
 
static int read_security_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
 
static int read_server_obj (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
 
static int write_access_control_res (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_lwm2m_resource *res)
 
static int write_access_control_tlv (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, struct sol_vector *tlvs)
 
static int write_or_create_acl (struct sol_vector *acl, struct sol_vector *tlvs, uint16_t *j, bool is_create)
 
static int write_security_res (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_lwm2m_resource *res)
 
static int write_security_tlv (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, struct sol_vector *tlvs)
 
static int write_server_res (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_lwm2m_resource *res)
 
static int write_server_tlv (void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, struct sol_vector *tlvs)
 

Variables

static const struct
sol_lwm2m_object 
access_control_object
 
static struct sol_blob binding
 
static struct sol_blob bootstrap_server_addr
 
static const struct
sol_lwm2m_object 
location_object
 
static const struct
sol_lwm2m_object 
security_object
 
static struct sol_blob server_addr_coap
 
static struct sol_blob server_addr_dtls
 
static const struct
sol_lwm2m_object 
server_object
 

Macro Definition Documentation

#define ACCESS_CONTROL_OBJ_ACL_RES_ID   (2)
#define ACCESS_CONTROL_OBJ_ID   (2)
#define ACCESS_CONTROL_OBJ_INSTANCE_RES_ID   (1)
#define ACCESS_CONTROL_OBJ_OBJECT_RES_ID   (0)
#define ACCESS_CONTROL_OBJ_OWNER_RES_ID   (3)
#define BS_SERVER_PUBLIC_KEY
Value:
("cd4110e97bbd6e7e5a800028079d02915c70b915ea4596402098deea585eb7ad" \
"f3e080487327f70758b13bc0583f4293d13288a0164a8e324779aa4f7ada26c1")

Referenced by main().

#define CLIENT_BS_PSK_ID   ("cli1-bs")

Referenced by main().

#define CLIENT_BS_PSK_KEY   ("FEDCBA9876543210")

Referenced by main().

#define CLIENT_PRIVATE_KEY   ("D9E2707A72DA6A0504995C86EDDBE3EFC7F1CD74838F7570C8072D0A76261BD4")
Examples:
/src/samples/coap/lwm2m-client.c.

Referenced by main().

#define CLIENT_PUBLIC_KEY
Value:
("D055EE14084D6E0615599DB583913E4A3E4526A2704D61F27A4CCFBA9758EF9A" \
"B418B64AFE8030DA1DDCF4F42E2F2631D043B1FB03E22F4D17DE43F9F9ADEE70")

Referenced by main().

#define CLIENT_SERVER_PSK_ID   ("cli1")

Referenced by main().

#define CLIENT_SERVER_PSK_KEY   ("0123456789ABCDEF")

Referenced by main().

#define LIFETIME   (60)

Referenced by main().

#define LOCATION_OBJ_ID   (6)
#define LOCATION_OBJ_LATITUDE_RES_ID   (0)
#define LOCATION_OBJ_LONGITUDE_RES_ID   (1)
#define LOCATION_OBJ_TIMESTAMP_RES_ID   (5)
#define ONE_SECOND   (1000)
#define PSK_KEY_LEN   16

Referenced by main().

#define RPK_PRIVATE_KEY_LEN   32

Referenced by main().

#define RPK_PUBLIC_KEY_LEN   (2 * RPK_PRIVATE_KEY_LEN)

Referenced by main().

#define SECURITY_BOOTSTRAP_SERVER_ACCOUNT_TIMEOUT_RES_ID   (12)
#define SECURITY_CLIENT_HOLD_OFF_TIME_RES_ID   (11)
#define SECURITY_IS_BOOTSTRAP_RES_ID   (1)
#define SECURITY_OBJ_ID   (0)
#define SECURITY_PUBLIC_KEY_OR_IDENTITY_RES_ID   (3)
#define SECURITY_SECRET_KEY_RES_ID   (5)
#define SECURITY_SECURITY_MODE_RES_ID   (2)
#define SECURITY_SERVER_ID_RES_ID   (10)
#define SECURITY_SERVER_PUBLIC_KEY_RES_ID   (4)
#define SECURITY_SERVER_URI_RES_ID   (0)
#define SERVER_OBJ_BINDING_RES_ID   (7)
#define SERVER_OBJ_ID   (1)
#define SERVER_OBJ_LIFETIME_RES_ID   (1)
#define SERVER_OBJ_REGISTRATION_UPDATE_RES_ID   (8)

Referenced by execute_server_obj().

#define SERVER_OBJ_SHORT_RES_ID   (0)
#define SERVER_PUBLIC_KEY
Value:
("3b88c213ca5ccfd9c5a7f73715760d7d9a5220768f2992d2628ae1389cbca4c6" \
"d1b73cc6d61ae58783135749fb03eaaa64a7a1adab8062ed5fc0d7b86ba2d5ca")
Examples:
/src/samples/coap/lwm2m-client.c, and /src/samples/coap/lwm2m-server.c.

Referenced by main().

Function Documentation

static void bootstrap_cb ( void *  data,
struct sol_lwm2m_client client,
enum sol_lwm2m_bootstrap_event  event 
)
static
static bool change_location ( void *  data)
static
static struct sol_blob* coord_to_str ( double  d)
static
static int create_access_control_obj ( void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
void **  instance_data,
struct sol_lwm2m_payload  payload 
)
static
static int create_location_obj ( void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
void **  instance_data,
struct sol_lwm2m_payload  payload 
)
static
static int create_security_obj ( void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
void **  instance_data,
struct sol_lwm2m_payload  payload 
)
static
static int create_server_obj ( void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
void **  instance_data,
struct sol_lwm2m_payload  payload 
)
static
static int del_access_control_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id 
)
static
static int del_location_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id 
)
static
static int del_security_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id 
)
static
static int del_server_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id 
)
static
static int execute_server_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
const struct sol_str_slice  args 
)
static
int main ( int  argc,
char *  argv[] 
)
static int read_access_control_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
struct sol_lwm2m_resource res 
)
static
static int read_location_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
struct sol_lwm2m_resource res 
)
static
static int read_security_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
struct sol_lwm2m_resource res 
)
static
static int read_server_obj ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
struct sol_lwm2m_resource res 
)
static
static int write_access_control_res ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
const struct sol_lwm2m_resource res 
)
static
static int write_access_control_tlv ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
struct sol_vector tlvs 
)
static
static int write_or_create_acl ( struct sol_vector acl,
struct sol_vector tlvs,
uint16_t *  j,
bool  is_create 
)
static
static int write_security_res ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
const struct sol_lwm2m_resource res 
)
static
static int write_security_tlv ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
struct sol_vector tlvs 
)
static
static int write_server_res ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
uint16_t  res_id,
const struct sol_lwm2m_resource res 
)
static
static int write_server_tlv ( void *  instance_data,
void *  user_data,
struct sol_lwm2m_client client,
uint16_t  instance_id,
struct sol_vector tlvs 
)
static

Variable Documentation

const struct sol_lwm2m_object access_control_object
static
Initial value:
= {
.resources_count = 4,
.write_resource = write_access_control_res,
}
static int write_access_control_tlv(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, struct sol_vector *tlvs)
Definition: lwm2m-client.c:1004
static int read_access_control_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
Definition: lwm2m-client.c:873
static int del_access_control_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
Definition: lwm2m-client.c:1128
static int write_access_control_res(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_lwm2m_resource *res)
Definition: lwm2m-client.c:916
static int create_access_control_obj(void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
Definition: lwm2m-client.c:1063
#define ACCESS_CONTROL_OBJ_ID
Definition: lwm2m-client.c:60
Examples:
/src/samples/coap/lwm2m-client.c.

Referenced by main().

struct sol_blob binding
static
Initial value:
= {
.parent = NULL,
.mem = (void *)"U",
.size = sizeof("U") - 1,
.refcnt = 1
}
const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE
Blob type object for the nofree implementation.

Referenced by main().

struct sol_blob bootstrap_server_addr
static
Initial value:
= {
.parent = NULL,
.mem = (void *)"coaps://localhost:5783",
.size = sizeof("coaps://localhost:5783") - 1,
.refcnt = 1
}
const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE
Blob type object for the nofree implementation.
Examples:
/src/samples/coap/lwm2m-client.c.

Referenced by main().

const struct sol_lwm2m_object location_object
static
Initial value:
= {
.resources_count = 6
}
static int create_location_obj(void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
Definition: lwm2m-client.c:223
static int read_location_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
Definition: lwm2m-client.c:312
#define LOCATION_OBJ_ID
Definition: lwm2m-client.c:46
static int del_location_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
Definition: lwm2m-client.c:859
Examples:
/src/samples/coap/lwm2m-client.c.

Referenced by main().

const struct sol_lwm2m_object security_object
static
Initial value:
= {
.resources_count = 12,
.write_resource = write_security_res,
.write_tlv = write_security_tlv
}
static int del_security_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
Definition: lwm2m-client.c:651
#define SECURITY_OBJ_ID
Definition: lwm2m-client.c:66
static int read_security_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
Definition: lwm2m-client.c:348
static int write_security_tlv(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, struct sol_vector *tlvs)
Definition: lwm2m-client.c:461
static int write_security_res(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_lwm2m_resource *res)
Definition: lwm2m-client.c:408
static int create_security_obj(void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
Definition: lwm2m-client.c:554
Examples:
/src/samples/coap/lwm2m-client.c.

Referenced by main().

struct sol_blob server_addr_coap
static
Initial value:
= {
.parent = NULL,
.mem = (void *)"coap://localhost:5683",
.size = sizeof("coap://localhost:5683") - 1,
.refcnt = 1
}
const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE
Blob type object for the nofree implementation.
Examples:
/src/samples/coap/lwm2m-client.c.
struct sol_blob server_addr_dtls
static
Initial value:
= {
.parent = NULL,
.mem = (void *)"coaps://localhost:5684",
.size = sizeof("coaps://localhost:5684") - 1,
.refcnt = 1
}
const struct sol_blob_type SOL_BLOB_TYPE_NO_FREE
Blob type object for the nofree implementation.
Examples:
/src/samples/coap/lwm2m-client.c.
const struct sol_lwm2m_object server_object
static
Initial value:
= {
.resources_count = 9,
.read = read_server_obj,
.create = create_server_obj,
.write_resource = write_server_res,
.write_tlv = write_server_tlv,
.execute = execute_server_obj
}
static int execute_server_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_str_slice args)
Definition: lwm2m-client.c:837
#define SERVER_OBJ_ID
Definition: lwm2m-client.c:54
static int write_server_tlv(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, struct sol_vector *tlvs)
Definition: lwm2m-client.c:729
static int read_server_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, struct sol_lwm2m_resource *res)
Definition: lwm2m-client.c:668
static int del_server_obj(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id)
Definition: lwm2m-client.c:848
static int create_server_obj(void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, void **instance_data, struct sol_lwm2m_payload payload)
Definition: lwm2m-client.c:780
static int write_server_res(void *instance_data, void *user_data, struct sol_lwm2m_client *client, uint16_t instance_id, uint16_t res_id, const struct sol_lwm2m_resource *res)
Definition: lwm2m-client.c:697
Examples:
/src/samples/coap/lwm2m-client.c.

Referenced by main().