Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ccc745a
net: lwm2m: make lwm2m_engine_exec_cb_t more generic
mike-scott May 15, 2018
ccb7909
net: lwm2m: introduce user-code callbacks for obj create/delete
mike-scott May 15, 2018
9458fba
net: lwm2m: use ARRAY_SIZE to calculate # of options
mike-scott May 15, 2018
0a83502
net: lwm2m: read past not supported TLV resources
mike-scott May 24, 2018
82c5d82
net: lwm2m: add lwm2m_engine_context_close() to engine
mike-scott May 24, 2018
5be0b47
net: lwm2m: security obj: add client_identity buffer
mike-scott May 24, 2018
1a96fd7
net: lwm2m: security obj: add server key storage
mike-scott May 24, 2018
d63f319
net: lwm2m: add security index/instance lookup functions
mike-scott May 24, 2018
dc33bec
net: lwm2m: add config LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
mike-scott May 24, 2018
f7611e8
net: lwm2m: set MAX_RESOURCE_LEN to 16 and make it public
mike-scott May 24, 2018
1822865
net: lwm2m: server obj: update RW flags for bootstrap
mike-scott May 24, 2018
07cb4ec
net: lwm2m: WIP: RD client BS support, use security instance info
mike-scott May 25, 2018
b106031
net: lwm2m: add BOOTSTRAP_WRITE handling to TLV formatter
mike-scott May 25, 2018
e0c4587
net: lwm2m: don't trigger engine update during bootstrap
mike-scott May 25, 2018
ee9285f
net: lwm2m: ignore empty OPAQUE data and continue
mike-scott May 25, 2018
6b4debf
net: lwm2m: update do_discovery for bootstrap mode
mike-scott May 25, 2018
0a16453
net: lwm2m: add BOOTSTRAP_DELETE handling
mike-scott May 25, 2018
cb1fe67
net: lwm2m: add "Bootstrap-Finish" handling
mike-scott May 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions include/net/lwm2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#define IPSO_OBJECT_TEMP_SENSOR_ID 3303
#define IPSO_OBJECT_LIGHT_CONTROL_ID 3311

/* #####/###/##### + NULL */
#define MAX_RESOURCE_LEN 16

/**
* @brief LwM2M context structure
*
Expand Down Expand Up @@ -58,13 +61,10 @@ struct lwm2m_ctx {
struct coap_reply replies[CONFIG_LWM2M_ENGINE_MAX_REPLIES];
struct k_delayed_work retransmit_work;

#if defined(CONFIG_NET_APP_DTLS)
/** Pre-Shared Key Information*/
unsigned char *client_psk;
size_t client_psk_len;
char *client_psk_id;
size_t client_psk_id_len;
/* current security object index */
int sec_obj_inst;

#if defined(CONFIG_NET_APP_DTLS)
/** DTLS support structures */
char *cert_host;
u8_t *dtls_result_buf;
Expand All @@ -81,7 +81,7 @@ typedef void *(*lwm2m_engine_get_data_cb_t)(u16_t obj_inst_id,
typedef int (*lwm2m_engine_set_data_cb_t)(u16_t obj_inst_id,
u8_t *data, u16_t data_len,
bool last_block, size_t total_size);
typedef int (*lwm2m_engine_exec_cb_t)(u16_t obj_inst_id);
typedef int (*lwm2m_engine_user_cb_t)(u16_t obj_inst_id);


/* LWM2M Device Object */
Expand Down Expand Up @@ -144,8 +144,8 @@ void lwm2m_firmware_set_write_cb(lwm2m_engine_set_data_cb_t cb);
lwm2m_engine_set_data_cb_t lwm2m_firmware_get_write_cb(void);

#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT)
void lwm2m_firmware_set_update_cb(lwm2m_engine_exec_cb_t cb);
lwm2m_engine_exec_cb_t lwm2m_firmware_get_update_cb(void);
void lwm2m_firmware_set_update_cb(lwm2m_engine_user_cb_t cb);
lwm2m_engine_user_cb_t lwm2m_firmware_get_update_cb(void);
#endif
#endif

Expand Down Expand Up @@ -205,7 +205,11 @@ int lwm2m_engine_register_pre_write_callback(char *path,
int lwm2m_engine_register_post_write_callback(char *path,
lwm2m_engine_set_data_cb_t cb);
int lwm2m_engine_register_exec_callback(char *path,
lwm2m_engine_exec_cb_t cb);
lwm2m_engine_user_cb_t cb);
int lwm2m_engine_register_create_callback(u16_t obj_id,
lwm2m_engine_user_cb_t cb);
int lwm2m_engine_register_delete_callback(u16_t obj_id,
lwm2m_engine_user_cb_t cb);

/* resource data bit values */
#define LWM2M_RES_DATA_READ_ONLY 0
Expand All @@ -226,16 +230,16 @@ int lwm2m_engine_set_net_pkt_pool(struct lwm2m_ctx *ctx,
net_pkt_get_slab_func_t tx_slab,
net_pkt_get_pool_func_t data_pool);
#endif
int lwm2m_engine_start(struct lwm2m_ctx *client_ctx,
char *peer_str, u16_t peer_port);
int lwm2m_engine_start(struct lwm2m_ctx *client_ctx, bool is_bootstrap_mode);

/* LWM2M RD Client */

/* Client events */
enum lwm2m_rd_client_event {
LWM2M_RD_CLIENT_EVENT_NONE,
LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_FAILURE,
LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_COMPLETE,
LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE,
LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETE,
LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE,
LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE,
LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE,
LWM2M_RD_CLIENT_EVENT_REG_UPDATE_FAILURE,
Expand All @@ -249,7 +253,6 @@ typedef void (*lwm2m_ctx_event_cb_t)(struct lwm2m_ctx *ctx,
enum lwm2m_rd_client_event event);

int lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx,
char *peer_str, u16_t peer_port,
const char *ep_name,
lwm2m_ctx_event_cb_t event_cb);

Expand Down
4 changes: 4 additions & 0 deletions samples/net/lwm2m_client/overlay-dtls.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=8192
CONFIG_MBEDTLS_CFG_FILE="config-coap.h"
CONFIG_LWM2M_PEER_PORT=5684

# DTLS urls
CONFIG_NET_APP_PEER_IPV6_ADDR="coaps://[2001:db8::2]:5684"
CONFIG_NET_APP_PEER_IPV4_ADDR="coaps://192.0.2.2:5684"
4 changes: 2 additions & 2 deletions samples/net/lwm2m_client/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ CONFIG_LWM2M_IPSO_TEMP_SENSOR=y
CONFIG_LWM2M_IPSO_LIGHT_CONTROL=y

CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2"
CONFIG_NET_APP_PEER_IPV6_ADDR="coap://2001:db8::2"
CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_APP_PEER_IPV4_ADDR="192.0.2.2"
CONFIG_NET_APP_PEER_IPV4_ADDR="coap://192.0.2.2"
60 changes: 39 additions & 21 deletions samples/net/lwm2m_client/src/lwm2m-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static struct lwm2m_ctx client;
NET_APP_TLS_POOL_DEFINE(dtls_pool, 10);

/* "000102030405060708090a0b0c0d0e0f" */
static unsigned char client_psk[] = {
static const unsigned char client_psk[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
Expand Down Expand Up @@ -222,8 +222,37 @@ static int firmware_block_received_cb(u16_t obj_inst_id,
static int lwm2m_setup(void)
{
struct float32_value float_value;
int ret;
char *server_url;
u16_t server_url_len;
u8_t server_url_flags;

/* setup SECURITY object */

/* Server URL */
ret = lwm2m_engine_get_res_data("0/0/0",
(void **)&server_url, &server_url_len,
&server_url_flags);
if (ret < 0) {
return ret;
}

snprintk(server_url, server_url_len, "%s",
IS_ENABLED(CONFIG_NET_IPV6) ? CONFIG_NET_APP_PEER_IPV6_ADDR :
CONFIG_NET_APP_PEER_IPV4_ADDR);

/* Bootstrap Mode */
lwm2m_engine_set_bool("0/0/1",
IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP));
/* Security Mode */
lwm2m_engine_set_u8("0/0/2", IS_ENABLED(CONFIG_NET_APP_DTLS) ? 0 : 3);
#if defined(CONFIG_NET_APP_DTLS)
lwm2m_engine_set_opaque("0/0/3",
(void *)client_psk_id, sizeof(client_psk_id));
lwm2m_engine_set_opaque("0/0/5",
(void *)client_psk, sizeof(client_psk));
#endif /* CONFIG_NET_APP_DTLS */

/* setup SERVER object */

/* setup DEVICE object */
Expand Down Expand Up @@ -309,12 +338,16 @@ static void rd_client_event(struct lwm2m_ctx *client,
/* do nothing */
break;

case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_FAILURE:
SYS_LOG_DBG("Bootstrap failure!");
case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE:
SYS_LOG_DBG("Bootstrap registration failure!");
break;

case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_COMPLETE:
SYS_LOG_DBG("Bootstrap complete");
case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETE:
SYS_LOG_DBG("Bootstrap registration complete");
break;

case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE:
SYS_LOG_DBG("Bootstrap transfer complete");
break;

case LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE:
Expand Down Expand Up @@ -367,10 +400,6 @@ void main(void)
#endif

#if defined(CONFIG_NET_APP_DTLS)
client.client_psk = client_psk;
client.client_psk_len = 16;
client.client_psk_id = (char *)client_psk_id;
client.client_psk_id_len = strlen(client_psk_id);
client.cert_host = HOSTNAME;
client.dtls_pool = &dtls_pool;
client.dtls_result_buf = dtls_result;
Expand All @@ -379,18 +408,7 @@ void main(void)
client.dtls_stack_len = K_THREAD_STACK_SIZEOF(net_app_dtls_stack);
#endif /* CONFIG_NET_APP_DTLS */

#if defined(CONFIG_NET_IPV6)
ret = lwm2m_rd_client_start(&client, CONFIG_NET_APP_PEER_IPV6_ADDR,
CONFIG_LWM2M_PEER_PORT, CONFIG_BOARD,
rd_client_event);
#elif defined(CONFIG_NET_IPV4)
ret = lwm2m_rd_client_start(&client, CONFIG_NET_APP_PEER_IPV4_ADDR,
CONFIG_LWM2M_PEER_PORT, CONFIG_BOARD,
rd_client_event);
#else
SYS_LOG_ERR("LwM2M client requires IPv4 or IPv6.");
ret = -EPROTONOSUPPORT;
#endif
ret = lwm2m_rd_client_start(&client, CONFIG_BOARD, rd_client_event);
if (ret < 0) {
SYS_LOG_ERR("LWM2M init LWM2M RD client error (%d)",
ret);
Expand Down
16 changes: 16 additions & 0 deletions subsys/net/lib/lwm2m/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,24 @@ config LWM2M_LOCAL_PORT
config LWM2M_SECURITY_INSTANCE_COUNT
int "Maximum # of LWM2M Security object instances"
default 1
default 2 if LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
range 1 10
help
This setting establishes the total count of LWM2M Security instances
available to the client.

config LWM2M_SECURITY_KEY_SIZE
int "Buffer size of the security key resources"
default 16
range 16 256
help
This setting establishes the size of the key (pre-shared / public)
resources in the security object instances.

config LWM2M_SERVER_INSTANCE_COUNT
int "Maximum # of LWM2M Server object instances"
default 1
default 2 if LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
range 1 10
help
This setting establishes the total count of LWM2M Server instances
Expand All @@ -95,6 +105,12 @@ config LWM2M_RD_CLIENT_SUPPORT
Client will use registration state machine to locate and connect to
LWM2M servers (including bootstrap server support)

config LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
bool "Enable bootstrap support"
default n
help
Enabling this setting allows the RD client to support bootstrap mode.

config LWM2M_PEER_PORT
int "LWM2M server port"
depends on LWM2M_RD_CLIENT_SUPPORT
Expand Down
Loading