Skip to content

Commit b633f3a

Browse files
rlubosfabiobaltieri
authored andcommitted
net: lwm2m: Verify pmin for updated resource on notify check
When updating a resource, the LwM2M library verified pmin attribute on all resources/objects in the observer path list and chose the smallest value. While this make sense for determining the lower-boundary for the next notification time, it could lead to unnecessary notifications being generated too early if the updated resource had a higher pmin value configured on it. Therefore, when checking notification criteria for an updated resource, check the pmin value for that resource path and if set and higher than the lowest pmin value evaluated for the observer list, use it instead. Signed-off-by: Robert Lubos <[email protected]>
1 parent d021851 commit b633f3a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

subsys/net/lib/lwm2m/lwm2m_observation.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ static bool value_conditions_satisfied(const struct lwm2m_obj_path *path,
632632
int lwm2m_notify_observer_path(const struct lwm2m_obj_path *path)
633633
{
634634
struct observe_node *obs;
635-
struct notification_attrs nattrs = {0};
635+
struct notification_attrs obs_attrs = {0};
636+
struct notification_attrs res_attrs = {0};
636637
int64_t timestamp;
637638
int ret = 0;
638639
int i;
@@ -647,19 +648,35 @@ int lwm2m_notify_observer_path(const struct lwm2m_obj_path *path)
647648
SYS_SLIST_FOR_EACH_CONTAINER(&sock_ctx[i]->observer, obs, node) {
648649
if (lwm2m_notify_observer_list(&obs->path_list, path)) {
649650
/* update the event time for this observer */
650-
ret = engine_observe_attribute_list_get(&obs->path_list, &nattrs,
651+
ret = engine_observe_attribute_list_get(&obs->path_list, &obs_attrs,
651652
sock_ctx[i]->srv_obj_inst);
652653
if (ret < 0) {
653654
return ret;
654655
}
655656

657+
/* Read attributes for the updated resource path */
658+
ret = engine_observe_get_attributes(path, &res_attrs,
659+
sock_ctx[i]->srv_obj_inst);
660+
if (ret < 0) {
661+
return ret;
662+
}
663+
656664
if (!value_conditions_satisfied(path, sock_ctx[i]->srv_obj_inst)) {
657665
continue;
658666
}
659667

660-
if (nattrs.pmin) {
668+
/* In case the lowest pmin value for the observation is smaller
669+
* than the pmin configured for the updated resource, use the
670+
* resource value to prevent notification from being generated
671+
* too early.
672+
*/
673+
if (obs_attrs.pmin < res_attrs.pmin) {
674+
obs_attrs.pmin = res_attrs.pmin;
675+
}
676+
677+
if (obs_attrs.pmin) {
661678
timestamp =
662-
obs->last_timestamp + MSEC_PER_SEC * nattrs.pmin;
679+
obs->last_timestamp + MSEC_PER_SEC * obs_attrs.pmin;
663680
} else {
664681
/* Trig immediately */
665682
timestamp = k_uptime_get();

0 commit comments

Comments
 (0)