Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ samples/boards/quark_se_c1000/power*/* @youvedeep @nashif
samples/net/* @jukkar @tbursztyka
samples/net/dns_resolve/* @jukkar @tbursztyka
samples/net/http_server/* @jukkar @tbursztyka
samples/net/lwm2m_client/* @mike-scott
samples/net/mbedtls_sslclient/* @nashif
samples/net/mqtt_publisher/* @jukkar @tbursztyka
samples/net/zoap_client/* @vcgomes
Expand All @@ -159,6 +160,7 @@ subsys/net/ip/* @jukkar @tbursztyka
subsys/net/lib/* @jukkar @tbursztyka
subsys/net/lib/dns/* @jukkar @tbursztyka
subsys/net/lib/http/* @jukkar @tbursztyka
subsys/net/lib/lwm2m/* @mike-scott
subsys/net/lib/mqtt/* @jukkar @tbursztyka
subsys/net/lib/zoap/* @vcgomes
subsys/usb @youvedeep @andyross
Expand Down
5 changes: 5 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ M: Anas Nashif <[email protected]>
M: Inaky Perez-Gonzalez <[email protected]>
F: .known-issues/

LWM2M
M: Michael Scott <[email protected]>
S: Supported
F: subsys/net/lib/lwm2m/
F: samples/net/lwm2m_client/

MAINTAINERS
M: Anas Nashif <[email protected]>
Expand Down
6 changes: 6 additions & 0 deletions doc/subsystems/networking/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ can be disabled if not needed.
:ref:`coap-server-sample` using DTLS (Datagram Transport Layer Security)
(RFC 6347) are also implemented.

* **LWM2M** OMA Lightweight Machine-to-Machine Protocol (V1.0 Feb 2017) is
supported via the "Register Device" API (Register, De-Register and Update)
and has template implementations for Securty, Server, Device Management and
Firmware objects. DTLS and Bootstrap support are currently not supported.
:ref:`lwm2m-client-sample` implements the library as an example.

* **RPL** IPv6 Routing Protocol for Low-Power and Lossy Networks (RFC 6550)
is supported. RPL is an IPv6 based mesh routing protocol.

Expand Down
16 changes: 16 additions & 0 deletions include/misc/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
(((x) >> 8) & 0xff00) | \
(((x) & 0xff00) << 8) | \
(((x) & 0xff) << 24)))
#define __bswap_64(x) ((u64_t) ((((x) >> 56) & 0xff) | \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok but why is this patch part of lwm2m patchset? You probably want to send this patch in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it here so testers could pull this as a part of the PR to test LWM2M. I will definitely submit this separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as it is in its commit, I do not think it make sense to create another PR, the commit is needed here, so it should be part of this PR, lets not go into this please, it is enough to have commits separated and have PRs be more inclusive and allow coverage of major features that touch different parts of the system.

(((x) >> 40) & 0xff00) | \
(((x) >> 24) & 0xff0000) | \
(((x) >> 8) & 0xff000000) | \
(((x) & 0xff000000) << 8) | \
(((x) & 0xff0000) << 24) | \
(((x) & 0xff00) << 40) | \
(((x) & 0xff) << 56)))

/** @def sys_le16_to_cpu
* @brief Convert 16-bit integer from little-endian to host endianness.
Expand Down Expand Up @@ -93,17 +101,25 @@
#define sys_cpu_to_be16(val) __bswap_16(val)
#define sys_le32_to_cpu(val) (val)
#define sys_cpu_to_le32(val) (val)
#define sys_le64_to_cpu(val) (val)
#define sys_cpu_to_le64(val) (val)
#define sys_be32_to_cpu(val) __bswap_32(val)
#define sys_cpu_to_be32(val) __bswap_32(val)
#define sys_be64_to_cpu(val) __bswap_64(val)
#define sys_cpu_to_be64(val) __bswap_64(val)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define sys_le16_to_cpu(val) __bswap_16(val)
#define sys_cpu_to_le16(val) __bswap_16(val)
#define sys_be16_to_cpu(val) (val)
#define sys_cpu_to_be16(val) (val)
#define sys_le32_to_cpu(val) __bswap_32(val)
#define sys_cpu_to_le32(val) __bswap_32(val)
#define sys_le64_to_cpu(val) __bswap_64(val)
#define sys_cpu_to_le64(val) __bswap_64(val)
#define sys_be32_to_cpu(val) (val)
#define sys_cpu_to_be32(val) (val)
#define sys_be64_to_cpu(val) (val)
#define sys_cpu_to_be64(val) (val)
#else
#error "Unknown byte order"
#endif
Expand Down
159 changes: 159 additions & 0 deletions include/net/lwm2m.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright (c) 2017 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef __LWM2M_H__
#define __LWM2M_H__

#include <net/net_context.h>

/* LWM2M Objects defined by OMA */

#define LWM2M_OBJECT_SECURITY_ID 0
#define LWM2M_OBJECT_SERVER_ID 1
#define LWM2M_OBJECT_ACCESS_CONTROL_ID 2
#define LWM2M_OBJECT_DEVICE_ID 3
#define LWM2M_OBJECT_CONNECTIVITY_MONITORING_ID 4
#define LWM2M_OBJECT_FIRMWARE_ID 5
#define LWM2M_OBJECT_LOCATION_ID 6
#define LWM2M_OBJECT_CONNECTIVITY_STATISTICS_ID 7

/* IPSO Alliance Objects */

#define IPSO_OBJECT_TEMP_SENSOR_ID 3303

/* callback can return 1 if handled (don't update value) */
typedef void *(*lwm2m_engine_get_data_cb_t)(u16_t obj_inst_id,
size_t *data_len);
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);


/* LWM2M Device Object */

#define LWM2M_DEVICE_PWR_SRC_TYPE_DC_POWER 0
#define LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT 1
#define LWM2M_DEVICE_PWR_SRC_TYPE_BAT_EXT 2
#define LWM2M_DEVICE_PWR_SRC_TYPE_UNUSED 3
#define LWM2M_DEVICE_PWR_SRC_TYPE_PWR_OVER_ETH 4
#define LWM2M_DEVICE_PWR_SRC_TYPE_USB 5
#define LWM2M_DEVICE_PWR_SRC_TYPE_AC_POWER 6
#define LWM2M_DEVICE_PWR_SRC_TYPE_SOLAR 7
#define LWM2M_DEVICE_PWR_SRC_TYPE_MAX 8

#define LWM2M_DEVICE_ERROR_NONE 0
#define LWM2M_DEVICE_ERROR_LOW_POWER 1
#define LWM2M_DEVICE_ERROR_EXT_POWER_SUPPLY_OFF 2
#define LWM2M_DEVICE_ERROR_GPS_FAILURE 3
#define LWM2M_DEVICE_ERROR_LOW_SIGNAL_STRENGTH 4
#define LWM2M_DEVICE_ERROR_OUT_OF_MEMORY 5
#define LWM2M_DEVICE_ERROR_SMS_FAILURE 6
#define LWM2M_DEVICE_ERROR_NETWORK_FAILURE 7
#define LWM2M_DEVICE_ERROR_PERIPHERAL_FAILURE 8

#define LWM2M_DEVICE_BATTERY_STATUS_NORMAL 0
#define LWM2M_DEVICE_BATTERY_STATUS_CHARGING 1
#define LWM2M_DEVICE_BATTERY_STATUS_CHARGE_COMP 2
#define LWM2M_DEVICE_BATTERY_STATUS_DAMAGED 3
#define LWM2M_DEVICE_BATTERY_STATUS_LOW 4
#define LWM2M_DEVICE_BATTERY_STATUS_NOT_INST 5
#define LWM2M_DEVICE_BATTERY_STATUS_UNKNOWN 6

int lwm2m_device_add_pwrsrc(u8_t pwr_src_type); /* returns index */
int lwm2m_device_remove_pwrsrc(int index);
int lwm2m_device_set_pwrsrc_voltage_mv(int index, int voltage_mv);
int lwm2m_device_set_pwrsrc_current_ma(int index, int current_ma);
int lwm2m_device_add_err(u8_t error_code);


/* LWM2M Firemware Update Object */

#define STATE_IDLE 0
#define STATE_DOWNLOADING 1
#define STATE_DOWNLOADED 2
#define STATE_UPDATING 3

#define RESULT_DEFAULT 0
#define RESULT_SUCCESS 1
#define RESULT_NO_STORAGE 2
#define RESULT_OUT_OF_MEM 3
#define RESULT_CONNECTION_LOST 4
#define RESULT_INTEGRITY_FAILED 5
#define RESULT_UNSUP_FW 6
#define RESULT_INVALID_URI 7
#define RESULT_UPDATE_FAILED 8
#define RESULT_UNSUP_PROTO 9

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);


/* LWM2M Engine */

/*
* float type below use the following logic:
* val1 is the whole number portion of decimal
* val2 is the decimal portion *1000000 for 32bit, *1000000000 for 64bit
* Example: 123.456 == val1: 123, val2:456000
* Example: 123.000456 = val1: 123, val2:456
*/
typedef struct float32_value {
s32_t val1;
s32_t val2;
} float32_value_t;

typedef struct float64_value {
s64_t val1;
s64_t val2;
} float64_value_t;

int lwm2m_engine_create_obj_inst(char *pathstr);

int lwm2m_engine_set_string(char *path, char *data_ptr);
int lwm2m_engine_set_u8(char *path, u8_t value);
int lwm2m_engine_set_u16(char *path, u16_t value);
int lwm2m_engine_set_u32(char *path, u32_t value);
int lwm2m_engine_set_u64(char *path, u64_t value);
int lwm2m_engine_set_s8(char *path, s8_t value);
int lwm2m_engine_set_s16(char *path, s16_t value);
int lwm2m_engine_set_s32(char *path, s32_t value);
int lwm2m_engine_set_s64(char *path, s64_t value);
int lwm2m_engine_set_bool(char *path, bool value);
int lwm2m_engine_set_float32(char *pathstr, float32_value_t *value);
int lwm2m_engine_set_float64(char *pathstr, float64_value_t *value);

int lwm2m_engine_get_string(char *path, void *str, u16_t strlen);
u8_t lwm2m_engine_get_u8(char *path);
u16_t lwm2m_engine_get_u16(char *path);
u32_t lwm2m_engine_get_u32(char *path);
u64_t lwm2m_engine_get_u64(char *path);
s8_t lwm2m_engine_get_s8(char *path);
s16_t lwm2m_engine_get_s16(char *path);
s32_t lwm2m_engine_get_s32(char *path);
s64_t lwm2m_engine_get_s64(char *path);
bool lwm2m_engine_get_bool(char *path);
int lwm2m_engine_get_float32(char *pathstr, float32_value_t *buf);
int lwm2m_engine_get_float64(char *pathstr, float64_value_t *buf);

int lwm2m_engine_register_read_callback(char *path,
lwm2m_engine_get_data_cb_t cb);
int lwm2m_engine_register_pre_write_callback(char *path,
lwm2m_engine_get_data_cb_t cb);
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);

int lwm2m_engine_start(struct net_context *net_ctx);

/* LWM2M RD Client */

int lwm2m_rd_client_start(struct net_context *net_ctx,
struct sockaddr *peer_addr,
const char *ep_name);

#endif /* __LWM2M_H__ */
1 change: 1 addition & 0 deletions include/net/zoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ struct zoap_reply {
void *user_data;
int age;
u8_t token[8];
u16_t id;
u8_t tkl;
};

Expand Down
13 changes: 13 additions & 0 deletions samples/net/lwm2m_client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Makefile - LWM2M client test application

#
# Copyright (c) 2017 Linaro
#
# SPDX-License-Identifier: Apache-2.0
#

BOARD ?= qemu_x86
CONF_FILE ?= prj_$(BOARD).conf

include $(ZEPHYR_BASE)/Makefile.inc
include $(ZEPHYR_BASE)/samples/net/common/Makefile.ipstack
19 changes: 19 additions & 0 deletions samples/net/lwm2m_client/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. _lwm2m-client-sample:

LWM2M client
############

Overview
********

TODO

Building and Running
********************

TODO

Sample output
=============

TODO
45 changes: 45 additions & 0 deletions samples/net/lwm2m_client/prj_frdm_k64f.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
CONFIG_NETWORKING=y
CONFIG_NET_LOG=y
CONFIG_NET_BUF_LOG=y
CONFIG_SYS_LOG_NET_LEVEL=4
CONFIG_SYS_LOG_NET_BUF_LEVEL=2
CONFIG_SYS_LOG_LWM2M_LEVEL=4
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_IPV6=y
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2
CONFIG_NET_IPV4=y
CONFIG_NET_DHCPV4=n
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT=2
CONFIG_SYS_LOG_SHOW_COLOR=y
CONFIG_INIT_STACKS=y
CONFIG_PRINTK=y
CONFIG_NET_STATISTICS=y
CONFIG_NET_BUF_DATA_SIZE=384
CONFIG_NET_PKT_RX_COUNT=50
CONFIG_NET_PKT_TX_COUNT=50
CONFIG_NET_BUF_RX_COUNT=50
CONFIG_NET_BUF_TX_COUNT=50
CONFIG_NET_MAX_CONTEXTS=10
CONFIG_NET_CONTEXT_NET_PKT_POOL=y

CONFIG_NET_SHELL=y

CONFIG_NET_APP=y
CONFIG_NET_APP_NEED_IPV6=y
CONFIG_NET_APP_NEED_IPV4=y
CONFIG_NET_APP_CLIENT=y
CONFIG_NET_APP_SETTINGS=y

CONFIG_LWM2M=y
CONFIG_LWM2M_RD_CLIENT_INSTANCE_COUNT=2
CONFIG_LWM2M_IPSO_SUPPORT=y
CONFIG_LWM2M_IPSO_TEMP_SENSOR=y

CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
CONFIG_NET_APP_PEER_IPV6_ADDR="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_L2_ETHERNET=y
45 changes: 45 additions & 0 deletions samples/net/lwm2m_client/prj_qemu_x86.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
CONFIG_NETWORKING=y
CONFIG_NET_LOG=y
CONFIG_NET_BUF_LOG=y
CONFIG_SYS_LOG_NET_LEVEL=4
CONFIG_SYS_LOG_NET_BUF_LEVEL=2
CONFIG_SYS_LOG_LWM2M_LEVEL=4
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_IPV6=y
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2
CONFIG_NET_IPV4=y
CONFIG_NET_DHCPV4=n
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT=2
CONFIG_SYS_LOG_SHOW_COLOR=y
CONFIG_INIT_STACKS=y
CONFIG_PRINTK=y
CONFIG_NET_STATISTICS=y
CONFIG_NET_BUF_DATA_SIZE=384
CONFIG_NET_PKT_RX_COUNT=50
CONFIG_NET_PKT_TX_COUNT=50
CONFIG_NET_BUF_RX_COUNT=50
CONFIG_NET_BUF_TX_COUNT=50
CONFIG_NET_MAX_CONTEXTS=10
CONFIG_NET_CONTEXT_NET_PKT_POOL=y

CONFIG_NET_SHELL=y

CONFIG_NET_APP=y
CONFIG_NET_APP_NEED_IPV6=y
CONFIG_NET_APP_NEED_IPV4=y
CONFIG_NET_APP_CLIENT=y
CONFIG_NET_APP_SETTINGS=y

CONFIG_LWM2M=y
CONFIG_LWM2M_RD_CLIENT_INSTANCE_COUNT=2
CONFIG_LWM2M_IPSO_SUPPORT=y
CONFIG_LWM2M_IPSO_TEMP_SENSOR=y

CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
CONFIG_NET_APP_PEER_IPV6_ADDR="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_SLIP_TAP=y
8 changes: 8 additions & 0 deletions samples/net/lwm2m_client/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sample:
description: TBD
name: TBD
tests:
- test:
build_only: true
platform_whitelist: qemu_x86
tags: net lwm2m
9 changes: 9 additions & 0 deletions samples/net/lwm2m_client/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright (c) 2017 Linaro
#
# SPDX-License-Identifier: Apache-2.0
#

include $(ZEPHYR_BASE)/samples/net/common/Makefile.common

obj-y = lwm2m-client.o
Loading