Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/wakaama update on new version #20930

Merged
merged 4 commits into from
Nov 13, 2024
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: 1 addition & 1 deletion examples/lwm2m/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ menu "Application configuration"

config LWM2M_SERVER_URI
string "LwM2M Server URI to register/bootstrap with"
default "coap://[fd00:dead:beef::1]:5684"
default "coaps://[fd00:dead:beef::1]:5684"
help
The host part of the URI MUST be a valid IPv6 address.

Expand Down
4 changes: 2 additions & 2 deletions examples/lwm2m/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ USEPKG += tinydtls
USEMODULE += prng_sha1prng

## Application-specific Configuration options
LWM2M_SERVER_URI ?= '"coap://[fd00:dead:beef::1]:5684"'
LWM2M_SERVER_URI ?= '"coaps://[fd00:dead:beef::1]:5684"'
LWM2M_SERVER_SHORT_ID ?= 1

CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE='(3*1024)'
CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE='(4*1024)'

include $(RIOTBASE)/Makefile.include

Expand Down
20 changes: 20 additions & 0 deletions examples/lwm2m/Makefile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@ BOARD_INSUFFICIENT_MEMORY := \
airfy-beacon \
arduino-mkr1000 \
b-l072z-lrwan1 \
bastwan \
blackpill-stm32f103c8 \
blackpill-stm32f103cb \
bluepill-stm32f030c8 \
bluepill-stm32f103c8 \
bluepill-stm32f103cb \
calliope-mini \
cc1350-launchpad \
cc2538dk \
cc2650-launchpad \
cc2650stk \
e104-bt5010a-tb \
e104-bt5011a-tb \
feather-m0-lora \
feather-m0-wifi \
firefly \
gd32vf103c-start \
generic-cc2538-cc2592-dk \
hamilton \
hifive1 \
hifive1b \
i-nucleo-lrwan1 \
im880b \
lobaro-lorabox \
lsn50 \
maple-mini \
microbit \
Expand All @@ -34,16 +41,29 @@ BOARD_INSUFFICIENT_MEMORY := \
nucleo-f302r8 \
nucleo-f303k8 \
nucleo-f334r8 \
nucleo-f410rb \
nucleo-g070rb \
nucleo-g071rb \
nucleo-g431rb \
nucleo-l011k4 \
nucleo-l031k6 \
nucleo-l053r8 \
nucleo-l073rz \
nucleo-l412kb \
olimexino-stm32 \
omote \
opencm904 \
openmote-b \
openmote-cc2538 \
pba-d-01-kw2x \
remote-pa \
remote-reva \
remote-revb \
samd10-xmini \
saml10-xpro \
saml11-xpro \
samr21-xpro \
samr30-xpro \
seeedstudio-gd32 \
sipeed-longan-nano \
sipeed-longan-nano-tft \
Expand Down
8 changes: 8 additions & 0 deletions pkg/wakaama/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ config LWM2M_DEVICE_TTL
help
Lifetime of the device on the LwM2M server, expressed in seconds.

config LWM2M_COAP_DEFAULT_BLOCK_SIZE
int "CoAP block size"
range 4 10
default 10
help
Block transfer options support only power-of-two block sizes, from 2**4 (16) to 2**10 (1024) bytes.
This option represents the exponent of 2, which will be used for the block size.

config LWM2M_LOCAL_PORT
string "Port for the local LwM2M CoAP"
default "5683"
Expand Down
7 changes: 5 additions & 2 deletions pkg/wakaama/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PKG_NAME=wakaama
PKG_URL=https://github.com/eclipse/wakaama.git
PKG_VERSION=da74b3c91570b9716fbb424e90935806b2b29814
PKG_VERSION=ee0c98da7495e1ab43358b49e970dbc97f73ce3b
PKG_LICENSE=EDL-1.0,EPL-1.0

include $(RIOTBASE)/pkg/pkg.mk
Expand All @@ -12,8 +12,11 @@ CFLAGS += -Wno-cast-align
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42145
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90710#c1
CFLAGS += -Wno-maybe-uninitialized
CFLAGS += -DLWM2M_SUPPORT_TLV

all:
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/core -f $(RIOTBASE)/Makefile.base MODULE=wakaama_core
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/core/er-coap-13 -f $(RIOTBASE)/Makefile.base MODULE=wakaama_core_coap13
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/coap/er-coap-13 -f $(RIOTBASE)/Makefile.base MODULE=wakaama_core_coap13
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/coap -f $(RIOTBASE)/Makefile.base MODULE=wakaama_core_coap
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/data -f $(CURDIR)/wakaama_data.mk
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/examples/client -f $(CURDIR)/wakaama_client.mk
4 changes: 2 additions & 2 deletions pkg/wakaama/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USEMODULE += wakaama_core wakaama_core_coap13 wakaama_client
USEMODULE += wakaama_core wakaama_core_coap wakaama_core_coap13 wakaama_data wakaama_client

# include contrib code (platform adaption and client implementation)
USEMODULE += wakaama_contrib
Expand All @@ -12,7 +12,6 @@ USEMODULE += wakaama_objects
USEMODULE += wakaama_objects_device
USEMODULE += wakaama_objects_security


ifneq (,$(filter wakaama_objects_barometer,$(USEMODULE)))
USEMODULE += wakaama_objects_ipso_sensor_base
endif
Expand All @@ -39,6 +38,7 @@ endif

USEMODULE += ztimer
USEMODULE += ztimer_sec
USEMODULE += random
USEPKG += tlsf

# If logs for the package are active, we need fmt
Expand Down
11 changes: 10 additions & 1 deletion pkg/wakaama/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
DIRS += $(RIOTBASE)/pkg/wakaama/contrib

INCLUDES += -I$(RIOTBASE)/pkg/wakaama/include
INCLUDES += -I$(PKGDIRBASE)/wakaama/include
INCLUDES += -I$(PKGDIRBASE)/wakaama/core
INCLUDES += -I$(PKGDIRBASE)/wakaama/core/er-coap-13
INCLUDES += -I$(PKGDIRBASE)/wakaama/data
INCLUDES += -I$(PKGDIRBASE)/wakaama/coap/er-coap-13

# NOTE: Use wakaama in client mode
CFLAGS += -DLWM2M_CLIENT_MODE
Expand All @@ -17,5 +19,12 @@ ifneq (,$(or $(CONFIG_LWM2M_WITH_LOGS),$(filter -DCONFIG_LWM2M_WITH_LOGS=1,$(CFL
CFLAGS += -DLWM2M_WITH_LOGS=1
endif

# NOTE: "Default CoAP block size; Used if not set on a per-target basis"
ifeq (,$(CONFIG_LWM2M_COAP_DEFAULT_BLOCK_SIZE))
CFLAGS += -DLWM2M_COAP_DEFAULT_BLOCK_SIZE=1024
else
CFLAGS += -DLWM2M_COAP_DEFAULT_BLOCK_SIZE='1<<$(CONFIG_LWM2M_COAP_DEFAULT_BLOCK_SIZE)'
endif

PSEUDOMODULES += wakaama
PSEUDOMODULES += wakaama_client_dtls
3 changes: 0 additions & 3 deletions pkg/wakaama/contrib/lwm2m_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ static credman_tag_t _get_credential(const sock_udp_ep_t *ep, uint8_t security_m
/* prepare query */
lwm2m_uri_t query_uri = {
.objectId = LWM2M_SECURITY_OBJECT_ID,
// .resourceId = LWM2M_SECURITY_URI_ID,
.flag = LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID
};

lwm2m_list_t *instance = sec->instanceList;
Expand Down Expand Up @@ -413,7 +411,6 @@ void lwm2m_client_refresh_dtls_credentials(void)
/* prepare query */
lwm2m_uri_t query_uri = {
.objectId = LWM2M_SECURITY_OBJECT_ID,
.flag = LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID
};

lwm2m_list_t *instance = sec->instanceList;
Expand Down
1 change: 0 additions & 1 deletion pkg/wakaama/contrib/lwm2m_client_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
lwm2m_client_data_t *client_data = (lwm2m_client_data_t *)user_data;
lwm2m_client_connection_t *new_conn;

DEBUG("[lwm2m_connect_server] Connecting to server in security instance %" PRIu16 "\n", sec_obj_inst_id);

Check warning on line 107 in pkg/wakaama/contrib/lwm2m_client_connection.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

new_conn = _connection_create(sec_obj_inst_id, client_data);
if (new_conn) {
Expand Down Expand Up @@ -284,7 +284,6 @@
.objectId = LWM2M_SECURITY_URI_ID,
.instanceId = sec_obj_inst_id,
.resourceId = LWM2M_SECURITY_URI_ID,
.flag = LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID
};

int res = lwm2m_get_string(client_data, &resource_uri, uri, &uri_len);
Expand Down
5 changes: 5 additions & 0 deletions pkg/wakaama/contrib/lwm2m_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "ztimer.h"
#include "tlsf.h"
#include "random.h"

#include "lwm2m_platform.h"
#include "lwm2m_client_config.h"
Expand Down Expand Up @@ -106,6 +107,10 @@ time_t lwm2m_gettime(void)
return (time_t)(ztimer_now(ZTIMER_SEC));
}

int lwm2m_seed(void) {
leandrolanzieri marked this conversation as resolved.
Show resolved Hide resolved
return random_uint32();
}

/* For clang we need to specify that the first argument will be a format string
* for print
*/
Expand Down
4 changes: 2 additions & 2 deletions pkg/wakaama/contrib/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
data->id = uri->resourceId;

/* read the resource from the specified instance */
uint8_t res = object->readFunc(uri->instanceId, &data_num, &data, object);
uint8_t res = object->readFunc(client_data->lwm2m_ctx, uri->instanceId, &data_num, &data, object);

Check warning on line 79 in pkg/wakaama/contrib/objects/common.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
if (res != COAP_205_CONTENT || data->type != expected_type) {
result = -EINVAL;
goto out;
Expand Down Expand Up @@ -245,7 +245,7 @@
}

/* write the resource of the specified instance */
uint8_t res = object->writeFunc(uri->instanceId, 1, data, object);
uint8_t res = object->writeFunc(client_data->lwm2m_ctx, uri->instanceId, 1, data, object, LWM2M_WRITE_PARTIAL_UPDATE);

Check warning on line 248 in pkg/wakaama/contrib/objects/common.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
lwm2m_resource_value_changed(client_data->lwm2m_ctx, uri);

if (res != COAP_204_CHANGED) {
Expand Down
32 changes: 19 additions & 13 deletions pkg/wakaama/contrib/objects/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static bool reboot;
/**
* @brief 'Execute' callback for the Device object.
*
* @param[in] context LWM2M Context
* @param[in] instance_id Instance ID. Should be 0 as a single instance exists.
* @param[in] resource_id ID of the resource to execute.
* @param[in] buffer Information needed for the execution.
Expand All @@ -47,12 +48,13 @@ static bool reboot;
* @return COAP_400_BAD_REQUEST when wrong information has been sent
* @return COAP_405_METHOD_NOT_ALLOWED when trying to execute a resource that is not supported
*/
static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length,
lwm2m_object_t *object);
static uint8_t _execute_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id,
moritzholzer marked this conversation as resolved.
Show resolved Hide resolved
uint8_t * buffer, int length, lwm2m_object_t * object);

/**
* @brief 'Read' callback for the Device object.
*
* @param[in] context LWM2M Context
* @param[in] instance_id Instance ID. Should be 0 as a single instance exists.
* @param[in, out] num_data Number of resources requested. 0 means all.
* @param[in, out] data_array Initialized data array to output the values,
Expand All @@ -63,12 +65,13 @@ static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *
* @return COAP_404_NOT_FOUND when resource can't be found
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise
*/
static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object);
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
lwm2m_data_t ** data_array, lwm2m_object_t * object);

/**
* @brief 'Discover' callback for the Device object.
*
* @param[in] context LWM2M Context
* @param[in] instance_id Instance ID. Should be 0 as a single instance exists.
* @param[in, out] num_data Number of resources requested. 0 means all.
* @param[in, out] data_array Initialized data array to determine if the resource exists,
Expand All @@ -79,8 +82,8 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data
* @return COAP_404_NOT_FOUND when a resource is not supported
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise
*/
static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object);
static uint8_t _discover_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
leandrolanzieri marked this conversation as resolved.
Show resolved Hide resolved
lwm2m_data_t ** data_array, lwm2m_object_t * object);

typedef struct {
lwm2m_list_t list; /**< Linked list handle */
Expand All @@ -95,7 +98,7 @@ static lwm2m_object_t _device_object = {
.next = NULL,
.objID = LWM2M_DEVICE_OBJECT_ID,
.instanceList = (lwm2m_list_t *)&_instance,
.readFunc = _read_cb,
.readFunc = _read_cb,
.executeFunc = _execute_cb,
.discoverFunc = _discover_cb,
.writeFunc = NULL,
Expand All @@ -104,12 +107,13 @@ static lwm2m_object_t _device_object = {
.userData = NULL
};

static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object)
static uint8_t _discover_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
lwm2m_data_t ** data_array, lwm2m_object_t * object)
{
uint8_t result;
int i;

(void)context;
(void)object;

if (instance_id != 0) {
Expand Down Expand Up @@ -166,9 +170,10 @@ static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **
return result;
}

static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object)
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
lwm2m_data_t ** data_array, lwm2m_object_t * object)
{
(void)context;
(void)object;
int i;
DEBUG("[lwm2m:device:read]\n");
Expand Down Expand Up @@ -264,9 +269,10 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data
return COAP_205_CONTENT;
}

static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length,
lwm2m_object_t *object)
static uint8_t _execute_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id,
uint8_t * buffer, int length, lwm2m_object_t * object)
{
(void)context;
(void)buffer;
(void)object;

Expand Down
21 changes: 13 additions & 8 deletions pkg/wakaama/contrib/objects/ipso_sensor_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**
* @brief 'Read' callback for the LwM2M Illuminance Sensor object implementation.
*
* @param[in] context LWM2M Context
* @param[in] instance_id ID of the instance to read resource from.
* @param[in] num_data Number of elements in @p data_array.
* @param[in, out] data_array IDs of resources to read. Array of data structures to place values.
Expand All @@ -38,12 +39,13 @@
* @return COAP_404_NOT_FOUND if the instance was not found
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise
*/
static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object);
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
lwm2m_data_t ** data_array, lwm2m_object_t * object);

/**
* @brief 'Execute' callback for the LwM2M Illuminance Sensor object implementation.
*
* @param[in] context LWM2M Context
* @param[in] instance_id ID of the instance to execute resource from.
* @param[in] resource_id ID of the resource to execute.
* @param[in] buffer Pointer to the buffer containing the payload.
Expand All @@ -54,8 +56,8 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data
* @return COAP_404_NOT_FOUND if the instance was not found
* @return COAP_405_METHOD_NOT_ALLOWED if the resource is not executable
*/
static uint8_t _exec_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length,
lwm2m_object_t *object);
static uint8_t _exec_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id,
uint8_t * buffer, int length, lwm2m_object_t * object);

/**
* @brief Gets the current value of a given @p instance.
Expand Down Expand Up @@ -193,9 +195,11 @@ static uint8_t _get_value(lwm2m_data_t *data, lwm2m_obj_ipso_sensor_base_inst_t
return COAP_205_CONTENT;
}

static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array,
lwm2m_object_t *object)
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data,
lwm2m_data_t ** data_array, lwm2m_object_t * object)
{
(void)context;

lwm2m_obj_ipso_sensor_base_inst_t *instance;
uint8_t result;
int i = 0;
Expand Down Expand Up @@ -252,9 +256,10 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data
return result;
}

static uint8_t _exec_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length,
lwm2m_object_t *object)
static uint8_t _exec_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id,
uint8_t * buffer, int length, lwm2m_object_t * object);
{
(void)context;
(void)buffer;
(void)length;

Expand Down
Loading
Loading