Skip to content
Permalink
Browse files

net: lwm2m: use server record to set default observe notify timing

Server records contain the default PMIN and PMAX settings for how
often we can send observe notifications.  We are currently using
arbitrary defaults which cannot be changed when compiled or
during runtime.

Let's add Kconfig settings for the default settings to use and
also lookup the current values in the active server record when
an observe is added.

The actual PMIN/PMAX values can still be set via WRITE_ATTRIBUTE
operation.

Signed-off-by: Michael Scott <mike@foundries.io>
  • Loading branch information...
mike-scott authored and jukkar committed Jul 29, 2019
1 parent bd709c7 commit c0e313aae1966abd40404829c75467d38705ea08
@@ -107,6 +107,23 @@ config LWM2M_SECURITY_KEY_SIZE
This setting establishes the size of the key (pre-shared / public)
resources in the security object instances.

config LWM2M_SERVER_DEFAULT_PMIN
int "Default server record PMIN"
default 10
help
Default minimum amount of time in seconds the client must wait
between notifications. If a resource has to be notified during this
minimum time period, the notification must be sent after the time
period expires.

config LWM2M_SERVER_DEFAULT_PMAX
int "Default server record PMAX"
default 60
help
Default maximum amount of time in seconds the client may wait
between notifications. When this time period expires a notification
must be sent.

config LWM2M_SERVER_INSTANCE_COUNT
int "Maximum # of LWM2M Server object instances"
default 1
@@ -83,10 +83,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#define COAP_OPTION_BUF_LEN 13
#endif

/* TODO: grab this from server obj */
#define DEFAULT_SERVER_PMIN 10
#define DEFAULT_SERVER_PMAX 60

#define MAX_TOKEN_LEN 8

struct observe_node {
@@ -414,8 +410,6 @@ static int engine_add_observer(struct lwm2m_message *msg,
struct observe_node *obs;
struct notification_attrs attrs = {
.flags = BIT(LWM2M_ATTR_PMIN) | BIT(LWM2M_ATTR_PMAX),
.pmin = DEFAULT_SERVER_PMIN,
.pmax = DEFAULT_SERVER_PMAX,
};
int i, ret;

@@ -430,9 +424,11 @@ static int engine_add_observer(struct lwm2m_message *msg,
return -EINVAL;
}

/* TODO: get server object for default pmin/pmax
* and observe dup checking
*/
/* defaults from server object */
attrs.pmin = lwm2m_server_get_pmin(msg->ctx->sec_obj_inst);
attrs.pmax = lwm2m_server_get_pmax(msg->ctx->sec_obj_inst);

/* TODO: observe dup checking */

/* make sure this observer doesn't exist already */
SYS_SLIST_FOR_EACH_CONTAINER(&engine_observer_list, obs, node) {
@@ -2535,9 +2531,9 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
continue;
}

/* TODO: grab default from server obj */
nattrs.pmin = DEFAULT_SERVER_PMIN;
nattrs.pmax = DEFAULT_SERVER_PMAX;
/* defaults from server object */
nattrs.pmin = lwm2m_server_get_pmin(msg->ctx->sec_obj_inst);
nattrs.pmax = lwm2m_server_get_pmax(msg->ctx->sec_obj_inst);

ret = update_attrs(obj, &nattrs);
if (ret < 0) {
@@ -102,6 +102,9 @@ size_t lwm2m_engine_get_opaque_more(struct lwm2m_input_context *in,
int lwm2m_security_inst_id_to_index(u16_t obj_inst_id);
int lwm2m_security_index_to_inst_id(int index);

s32_t lwm2m_server_get_pmin(u16_t obj_inst_id);
s32_t lwm2m_server_get_pmax(u16_t obj_inst_id);

#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT)
u8_t lwm2m_firmware_get_update_state(void);
void lwm2m_firmware_set_update_state(u8_t state);
@@ -98,6 +98,32 @@ static int update_trigger_cb(u16_t obj_inst_id)
#endif
}

static s32_t server_get_instance_s32(u16_t obj_inst_id, s32_t *data,
s32_t default_value)
{
int i;

for (i = 0; i < ARRAY_SIZE(inst); i++) {
if (inst[i].obj && inst[i].obj_inst_id == obj_inst_id) {
return data[i];
}
}

return default_value;
}

s32_t lwm2m_server_get_pmin(u16_t obj_inst_id)
{
return server_get_instance_s32(obj_inst_id, default_min_period,
CONFIG_LWM2M_SERVER_DEFAULT_PMIN);
}

s32_t lwm2m_server_get_pmax(u16_t obj_inst_id)
{
return server_get_instance_s32(obj_inst_id, default_max_period,
CONFIG_LWM2M_SERVER_DEFAULT_PMAX);
}

static struct lwm2m_engine_obj_inst *server_create(u16_t obj_inst_id)
{
int index, i = 0;
@@ -128,8 +154,8 @@ static struct lwm2m_engine_obj_inst *server_create(u16_t obj_inst_id)
server_flag_store_notify[index] = 0U;
server_id[index] = index + 1;
lifetime[index] = CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME;
default_min_period[index] = 0U;
default_max_period[index] = 0U;
default_min_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMIN;
default_max_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMAX;
disabled_timeout[index] = 86400U;
strcpy(transport_binding[index], "U");

0 comments on commit c0e313a

Please sign in to comment.
You can’t perform that action at this time.