zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.98k stars 6.69k forks source link

LwM2M: Cannot set pmin/pmax on observable object #41608

Closed rerickson1 closed 2 years ago

rerickson1 commented 2 years ago

Describe the bug Code fails setting pmin first because pmax hasnt been set yet (defaults to 0) and it is less than pmin. The code never proceeds past Line 2808 of lwm2m_engine.c:

if ((nattrs.flags & (BIT(LWM2M_ATTR_PMIN) | BIT(LWM2M_ATTR_PMAX))) &&
        nattrs.pmin > nattrs.pmax) {
        LOG_DBG("pmin (%d) > pmax (%d)", nattrs.pmin, nattrs.pmax);
        return -EEXIST;
    }
rlubos commented 2 years ago

@rerickson1 I've submitted a fix proposal in https://github.com/zephyrproject-rtos/zephyr/pull/41997.

After comparing the logic within lwm2m engine with the spec, I've decided to go rather straightforward with the fix - i.e. only compare attribute values if both are set at the given level (the spec goes even further and says only to compare attributes provided in a single message). Additional sanity check is done when the observer is updated - it is verified whether to use pmax value or to ignore it.