Commit graph

831 commits

Author SHA1 Message Date
Marin Jurjević 0ab6bc6626 net: lwm2m: update client tx timestamp before sending message
Update client tx timestamp right after message is added to list
of outgoing messages. Delay between when message is generated and
sent is negligible. This will prevents bugs that appear when using
queue mode, where internal engine logic depends on timestamp being
updated when message is generated.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-04-13 13:59:58 -07:00
Veijo Pesonen 1105017ce0 net: lwm2m: Makes OMA TLV content fmt conditional
With LwM2M v1.1 usage of the OMA TLV content format is discouraged.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-13 13:28:34 -07:00
Veijo Pesonen d1751cafd3 net: lwm2m: adds LwM2M specific shell command
First available subcommand is for doing a send operation. Send operation
is supported by the LwM2M version 1.1.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-12 09:57:20 +02:00
Seppo Takalo 43c988d43e net: lwm2m: Clean up context on stop
When lwm2m_rd_client_stop() was called and immediately
followed by lwm2m_rd_client_start() it leaked the file
handle for existing socket.

Problem can be fixed when rd_client_stop() does not
move state machine to IDLE, but instead DEREGISTER
and then allow state machine to move forward.

I added a blocking wait for rd_client_stop() because
it needs to wait for proper clean up.

I also move couple of lwm2m_engine_context_close() to
set_sm_state() event handler or similarly in lwm2m_engine.c
there was couple of places where context was not properly
cleaned.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-04-05 11:16:58 +02:00
Juha Heiskanen ba2354a277 net: lwm2m: Support for "Mute Server" resource
Added support for server Mute send operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-04 10:29:07 -05:00
Juha Heiskanen d75b986151 net: lwm2m: SenML Json Base compare fix
Fixed wrong initialized base name objed id.
Base name was added to every object instance.
Fix will save message size.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-04 10:28:01 -05:00
Juha Heiskanen 164680d696 net: lwm2m: Senml Opaque BASE64URL support and fix padding
LwM2M specification is only mentioning BASE64 encoding but SenML-JSON
specification is talking about BASE64URL encoding.
This change is silently accepting both formats and automatically pads the
data if padding is dropped.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-04 11:16:26 +02:00
Benjamin Bigler 28e368de59 net: lwm2m: Fix missing context_close
Added missing lwm2m_context_close if set TLS_HOSTNAME failed

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2022-03-31 14:33:04 -05:00
Benjamin Bigler 6807d75e16 net: lwm2m: Fix TLS_HOSTNAME is always set
LWM2M Client Sample with DTLS enabled fails because TLS_HOSTNAME is set
but MBEDTLS_X509_CRT_PARSE_C is disabled which leads to error
'net_lwm2m_engine: Failed to set TLS_HOSTNAME option: 109'
Add new field hostname_verify to let the application decide if hostname
should be checked.

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2022-03-31 14:33:04 -05:00
Benjamin Bigler 493b940248 net: lwm2m: Fix address length at connect
If NET_IPV4 and NET_SOCKETS_PACKET is enabled, NET_SOCKADDR_MAX_SIZE will
be bigger than the ipv4 address length.
This is a problem when DTLS is used as the address comparison will fail
because of the different length of the received and the stored address.
This is also a problem if NET_IPV6 and NET_IPV4 is enabled and the remote
address is a ipv4 address

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2022-03-31 10:31:01 +02:00
Andreas Pettersson df59335541 net: lib: lwm2m: Use defines for update state and result pathstrs
Use defines instead of hardcoded strings to avoid future errors if the
values would change.

Signed-off-by: Andreas Pettersson <andreaspettersson95@gmail.com>
2022-03-31 10:30:40 +02:00
Marin Jurjević 683868f3d2 net: lwm2m: fix potential invalid pointer dereference in reset message
Sometimes message is being reset from multiple locations in code.
If message has already been reset, pointer to context is invalid.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-03-22 12:33:31 +01:00
Juha Heiskanen 0c6ea8eec4 net: lwm2m: Fix Read operation for /object
Read operation must return empty payload when read /object_id
if there is no created object instances.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-22 12:32:45 +01:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Juha Heiskanen 9777ba7354 net: lwm2m: SenML JSON dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to SenML JSON.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-17 11:41:42 +01:00
Juha Heiskanen 6cb662a495 net: lwm2m: Composite Observation update
Added support for Composite observation for LwM2M v1.1.
Updated current Observation node to support linked path list.
Rename typos lwm_ to lwm2m_.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-16 10:26:01 +01:00
Juha Heiskanen 6970addc12 net: lwm2m: Observation pmin and pmax refactor
Removed to store pmin and pmax at oberservation node structure and
use attribute list store for calculate time for next Notification.
Observation class use timestamp for triggering notification based on
resource update which use pmin and default pmax behaviour.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-16 10:26:01 +01:00
Marin Jurjević 2a4e47a912 net: lwm2m: fix registration update event in queue mode
When queue mode is enabled, state machine will enter state
ENGINE_REGISTRATION_DONE_RX_OFF. This state needs to be
taken into account during registration update to send
correct event.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-03-15 10:06:22 +01:00
Juha Heiskanen 0b38be9d3a net: lwm2m: Inteagrate LwM2M new API's
Remove local path to string and string to path functionality
and use utility library API.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-14 22:04:32 -04:00
Juha Heiskanen c95dd9a9c5 net: lwm2m: lwm2m utility API update
New API's
- lwm2m_string_to_path
- lwm2m_path_to_string
- lwm2m_atou16

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-14 22:04:32 -04:00
Juha Heiskanen 6d624e5e18 net: lwm2m: Senml Json Base name dynamical update
SenML Json support dynamical basename for composite operation.
Changes simplify base name generation and compres message better.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-14 11:29:13 +01:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Juha Heiskanen 3d44738b19 net: lwm2m: Fix SenML Json Name parser
Bug fix for case when base name is not included at message.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-03-07 10:54:57 +01:00
Veijo Pesonen 0032f0bcff net: lwm2m: obj inst processing per formatter
It depends from a content formatter is there need to put constructs
with a path level deeper than object instance. In other words with
resource- or resource-instance-level.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-03-07 10:52:58 +01:00
Veijo Pesonen 2231287e27 net: lwm2m: Resource Instance level read access.
Makes possible to read a single resource instance at a time with
plaint text, JSON and TLV content formats.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-02-25 10:12:23 -08:00
Juha Heiskanen 6904915a35 net: lwm2m: LwM2M engine default content format select
LwM2M version 1.1 will select SenML Json for default content format.
Version 1.0 will use TLV format.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen 312dd7f887 net: lwm2m: Composite Observe operation placeholder
Added detetction for Composite Observervation request and cancel.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen 98cd71eef2 net: lwm2m2: LwM2M Composite-Write operation
CoAP method iPATCH enable LwM2M Composite-Write operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen 3bec5de0fb net: lwm2m: LwM2M Composite read support
Adeed enabler for composite read to LwM2M engine.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen 906feebb33 net: lwm2m: Added LwM2M Send operation support
LwM2M engine Send operation support /dp.
Send operation based on Composite Read functionality
which is not enabled at engine side like composite write.
Added Kconfig configurable for composite read path list size.
Created generic Read object instance which is shared between
general read and Composite Read operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Juha Heiskanen a9c1b8d0f2 net: lwm2m: Added SenML JSON support for Read & Write
LwM2M SenML JSON contain format support for Read / Write operation.
Added Kconfig configurable for enable SenML JSON format.
LwM2m read validate read operation and report out of memory.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-23 17:25:36 +01:00
Robert Lubos 9ac83be650 net: lwm2m: Add proper resource-level discovery attribute handling
In case an individual resource is being discovered, the LwM2M client
should not only fill the attributes assinged at the resource level, but
also the ones inherited from the object and object instance levels.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:12:27 -08:00
Robert Lubos ac8881f170 net: lwm2m: Allow to write attributes for resource instances
LwM2M 1.1 allows to write attributes for resource instances as well.

Resource instance level attributes need also to be taken into
consideration when adding/updating observers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:12:27 -08:00
Robert Lubos 3e861c04e9 net: lwm2m: Add LwM2M 1.1 discovery support
LwM2M adds Resource Instance reporting in Discovery response, along with
attributes assinged at the Resource Instance level.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-22 10:12:27 -08:00
Seppo Takalo f1e0b5413c net: lwm2m: Allow changing the protocol version to 1.1
This is a bare minimal changes to tell the server that we are using
LwM2M 1.1 version. Queue-mode parameter has changed between 1.0 and
1.1 so it must be changed in the same time.

Other 1.1 features may follow on separate commits. This is still
an experimental feature that allows developing and testing of
1.1 features.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-02-21 22:18:34 -05:00
Veijo Pesonen 37b9bb87f0 net: lwm2m: Adds semantics for handling time
This far time values have been synonymous to integer values. Content
formats like CBOR do use different representation.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-02-21 22:07:01 -05:00
Juha Heiskanen 3e04783bbb net: lwm2m: LwM2M Portfolio object id support
Added support for Portfolio object support because LwM2M v1.1 conformance
test requirement that. This object is only for conformance test purposing.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 22:02:44 -05:00
Andreas Chmielewski b52f1cdb59 net: lwm2m: fixed "LwM2M message is invalid"
Do not retransmit a message that just has been send successfully.

This case can in particular happen quite frequently if the modem
connection/throughput is quite bad and so there is a high latency.

A message that has to be acknowledged is scheduled for retransmission.
Before retransmission a ack for this message is received that will
cause a reset of the original message. In this case you see a
"LwM2M message is invalid" error message.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-02-21 21:59:59 -05:00
Juha Heiskanen dde5c16709 net: lwm2m: JSON dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to JSON.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen 7b3a1f31fe net: lwm2m: Plain Text dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to Plain text.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen fcbf84b5d7 net: lwm2m: OMA TLV dynamic Resource instance allocation
Integrated dynamic resouce instance allocation to OMA TLV.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen 1d2f5b471e net: lwm2m: Resource instance dynamic allocation
Added support for allocate dynamically resource instance.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:53:48 -05:00
Juha Heiskanen 60088b18d4 net: lwm2m: Fix Read operation for /object
Read operation must return empty payload when read /object_id
if there is no created object instances.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:01:23 -05:00
Juha Heiskanen 392088ea13 net: lwm2m: OMA TLV Multi Resource TLV update
Added support for handle Multi Resource TLV for Write and Create operation.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-21 21:00:36 -05:00
Henning Fleddermann 7eb25df526 net: lib: lwm2m: add lwm2m_engine_is_observed function
add helper function to check wether a specific lwm2m
path is observed

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2022-02-21 20:50:52 -05:00
Henning Fleddermann 3018279c30 net: lib: lwm2m: make pathstr parameter const correct
many functions in the lwm2m librarys api take a pathstr argument
that is never written to, so make it const

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2022-02-08 07:27:30 -05:00
Jarno Lamsa 98f99a37a2 net: lib: lwm2m: Use snprintk instead of snprintf
Use kernel print function to reduce the memory impact.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-02-07 17:22:38 +01:00
Jarno Lamsa c2550d56c8 net: lib: lwm2m: Correct path for update result
The path was erroneously pointing to update state
resource instead of update result causing a wrong
resource value to be updated.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-02-07 17:22:38 +01:00
Marin Jurjević 2f4ab97168 net: lwm2m: add missing optional resource to firmware object
Firmware Update Protocol Support resource initialization
has been left out in #41402.
Initialise the resource in object creation function.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-02-04 11:19:07 +01:00
Yong Cong Sin 731241f8d0 kernel: workq: Fix type errors in delayable work handlers
A common pattern here was to take the work item as the subfield of a
containing object. But the contained field is not a k_work, it's a
k_work_delayable.

Things were working only because the work field was first, so the
pointers had the same value. Do things right and fix things to
produce correct code if/when that field ever moves within delayable.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-02 18:43:12 -05:00
Marin Jurjević 57a66648ae net: lwm2m: fix context close race condition
Calling lwm2m_rd_client_stop causes the client context to be closed.
Doing this from arbitrary thread other than internal lwm2m engine thread
causes racing condition on lwm2m engine context pointers.

Fixes #42358

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-02-02 08:58:40 -05:00
Juha Heiskanen a03deb8ef3 net: lwm2m: Fix Server Object SSID access
Server Object SSID should only have Read access.
LightweightM2M-1.1-int-256 confirmance test validate
that write operation to SSID should return error.
Overwrite SSID affect dead block for lwm2m engine and
only reset will heal.

Fix by adding bootstrap overwrite access for Security and
Server object when bootstrap is active.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-02-02 11:18:53 +01:00
Robert Lubos 9c8d30f099 net: lwm2m: Prevent snprintk warnings on different platforms
Use explicit casting to long long within `snprintk()` and logger
functions to prevent compiler warnings with different
platforms/toolchins (as 64-bit integer can be either represented
as ld or lld depending on platform).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 486e0a8ff6 net: lwm2m: Fix lwm2m_parse_peerinfo misuse
`lwm2m_parse_peerinfo()` expects a boolean value, not a pointer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 21e5cc7a31 tests: net: lwm2m: Add link-format content writer tests
Add unit tests for LwM2M link-format content encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 735fd86c0e tests: net: lwm2m: Add OMA TLV content writer tests
Add unit tests for LwM2M OMA TLV conent encoder/decoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos e42c1ed924 net: lwm2m: Fix OMA TLV objlnk encoding
At some point OMA TLV integer encoding was optimised to use the smallest
size possible. This broke the objlnk encoding, which internally used
`put_s32()`, but should always be 4 bytes long. In case the result
32-bit integer would fit into 16 or 8 bytes, it'd get optimized.

Fix this, by creating and writing TLV manually for objlnk instead of
relying on int32 encoder.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 3595a7cdb5 net: lwm2m: Fix lwm2m_atof for integer input
In case a string with an integer was provided to the function (no
decimal point), the function did not update the output pointer value.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos cb6c5f37ca net: lwm2m: Improve content writers error handling in engine
Verify the restult of the content writer functions and return an error
if content writer fails to read/write field in the message.

This solves an issue when for example malformed packet was sent to the
server if the payload did not fit in the message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 1a727b8571 net: lwm2m: Improve JSON content encoder/decoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 9e2bf49103 net: lwm2m: Improve TLV content encoder/decoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Make `buf_read()` return -ENODATA instead of -ENOMEM if there's not
enough data in the packet to serve the request, which is more meaningful
for this scenario.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos f1d86a0cd2 net: lwm2m: Improve plain-text content encoder/decoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 1c3dbd5af3 net: lwm2m: Improve link-format content encoder error handling
It's now possible to return an error code instead of 0 where
appropriate.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Robert Lubos 54ddf70945 net: lwm2m: Allow to return error codes by content encoders/decoders
Rework the content encoder/decoder API to allow to return negative
values as well. This allows a proper error reporting and error handling,
as it's now possible to differentiate when there is no content to write
(retuned 0) or and error occured, and further processing should be
aborted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-02-02 11:12:56 +01:00
Jarno Lamsa a1c80e7374 net: lib: lwm2m: Add missing function declarations
Get-function declarations for fw update state and result were
missing from the engine header.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-02-01 14:14:29 -06:00
Ryan Erickson c6ace45a6c net: lwm2m: add uCIFI Battery object (3411)
Add the uCIFI Battery object to support
monitoring a devices battery.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-01-21 11:32:08 -05:00
Robert Lubos d002f8a524 net: lwm2m: Fix attribute sanity check
Validate the respective attribute parameters only if both are provided
at given level. This prevents from comparing for instance unset pmax
value (equal to 0) with some new pmin value sent by the server.

Additionally, fix the sanity check for the `pmax` value set on observer,
after fetching the attribute value at all levels (including the default
value at from the server object). Instead of using wrong max(pmin, pmax)
formula, set the pmax value only if it's a valid one (>= pmin),
otherwise ignore the value and set it to 0. This makes the notification
engine ignore the pmax value set for observation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-01-21 11:31:20 -05:00
Andrew Hedin 7f004f1b35 net: lwm2m: Add LwM2M gateway object
Add support for the gateway object [EXPERIMENTAL] used by the
MG100, BT510, and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2022-01-18 13:19:12 -05:00
Jarno Lamsa 8f4a1fd906 net: lwm2m: Instance specific callbacks
Provide possibility to have instance specific callbacks
for writing the FW image and executing the update

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-13 10:34:25 +01:00
Jarno Lamsa eedbbdc61a net: lwm2m: Provide backwards compatibility for single object 5
Previously the object 5 was only single instance object. Provide
backwards compatibility, so it can be continued to use with single
instance.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-13 10:34:25 +01:00
Veijo Pesonen 9782f86450 net: lwm2m: separate FW update object instances - /5/*
This is a proof-of-concept implementation.

A device might have multiple firmware images which needs to be updated
separately. For example a single device might have

	* A bootloader image
	* An application image
	* External firmware image

Instead of pushing all these updates through the object instance 0 -
/5/0 - here a split to multiple has been made possible.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-01-13 10:34:25 +01:00
Andreas Chmielewski fbae13122f net: lwm2m: enable monitoring of fw update state/result
The intention behind this patch is to know the current state/result
of a firmware update process in the application code. It makes it
possible to use pre/post_write_callbacks to get the proper value
of state (5/0/3) and result (5/0/5) resource.

Signed-off-by: Andreas Chmielewski <andreas.chmielewski@grandcentrix.net>
2022-01-11 11:52:50 +01:00
Jarno Lamsa 5c3fd79bdc net: lwm2m: Security object resource correct type
Changed resource IDs 11 and 12 of the security object to use
signed integer as they are defined in the OMA specification.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-04 09:08:55 -05:00
Jarno Lamsa 60160fb82f net: lwm2m: Update security object to 1.1
Add 1.1 version of the LWM2M security object.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-04 09:08:55 -05:00
Jarno Lamsa 50ebb0e233 net: lwm2m: Update connectivity monitor object
Update the connectivity monitor object to version 1.2.
OMA core specification for the object adds 2 optional
resources.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-01-04 09:08:38 -05:00
Michal Ciesielski 8b3d7f2a43 net: lwm2m: Add LWM2M object 9 software management
Adds support for LWM2M object 9 Software management.
This is implemented according to this release:
http://openmobilealliance.org/release/LWM2M_SWMGMT/V1_0_1-20200616-A/

Note that the XML is lacking some resources and for that reason those
resources are not included. This is a known problem by OMA and will be
fixed in a later releases.

This uses the lwm2m_pull_context to pull binaries in case
FIRMWARE_PULL_SUPPORT is enabled

Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
2021-12-21 13:36:50 +01:00
Michal Ciesielski 06b0a9c59d net: lwm2m: Make lwm2m_pull_context reusable
Add a semaphore to control that no collisions occur when multiple
sources want to use the pull_context

Add struct firmware_pull_context *ctx as an argument to the result_cb of
the context. This allows the receiver to do some kind of differentiation
on the source.

Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
2021-12-21 13:36:50 +01:00
Michal Ciesielski 2f046da6a1 net: lwm2m: FW Pull separate generic pull logic
Make it possible to reuse the pull logic from firmware_pull.c by
separating it to a separate file.

The firmware_pull_context is still owned and statically allocated in
firmware_pull.c and is being passed into lwm2m_pull_context.c as a
pointer.

In other words, pull_context, does not keep any state except for a
pointer to the context currently in use.

Signed-off-by: Michal Ciesielski <michal.m.ciesielski@voiapp.io>
2021-12-21 13:36:50 +01:00
Juha Heiskanen 87f4210450 net: lwm2m: Update LwM2m server object to v1.1
Added Kconfig configurable choise option for enable Server
object version 1.0 or 1.1.

Server Object v1.1 enable by default server initiated bootstrap
trigger when CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP is enabled.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2021-12-20 17:00:28 +01:00
Jair Jack 0b06a06814 net: lwm2m: Supported Protocol to pull firmware update must be optional
The supported protocol must be delivered to the firmware update object
as optional, then configured in the application.

This information is device/server dependent so does not can be fixed
in library.

Signed-off-by: Jair Jack <jack@icatorze.com.br>
2021-11-26 10:26:32 -05:00
Maik Vermeulen f2ca6a8c22 net: lwm2m: Add observe callback for observe and notification events
Added an observe callback so that the application can register to
receive events like observer added/deleted, and notification acked/
timed out. The notifications can be traced back to the exact data
contained within them by use of the user_data pointer.

Fixes #38531.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-11-25 10:45:36 -05:00
Andrew Hedin a6f831fea6 net: lwm2m: Add IPSO filling sensor object
Add support for the filling sensor object used by the MG100
and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-11-09 11:19:12 +01:00
Andrew Hedin e0715556e7 net: lwm2m: Add IPSO current sensor object
Add support for the current sensor object used by the MG100
and BT610 LwM2M demo.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-11-08 11:01:22 -05:00
Jair Jack 5b5417a1dd net: lwm2m: Way to pass a destination hostname to socket
net: lwm2m: When mbedtls CONFIG_MBEDTLS_SERVER_NAME_INDICATION is
enabled, a destination hostname must be passed to socket to properly
connect do lwm2m server.

Passing lwm2m context to lwm2m_parse_peerinfo

Signed-off-by: Jair Jack <jack@icatorze.com.br>
2021-11-06 21:37:12 -04:00
Sebastian Salveter 4d2e46ddd6 net: lwm2m: Add option to configure device service period
The device service creates a notification of the current time resource
every 10s. This commit adds the possibility to change this timer to a
different value thus giving more control over the way the device object
is notified.

Signed-off-by: Sebastian Salveter <sebastian.salveter@grandcentrix.net>
2021-11-04 07:30:29 -04:00
Marin Jurjević b6ffd3cac8 net: lwm2m: add missing resources to Firmware Update object
Firmware Update object did not initialise resources PkgName,
PkgVersion and Firmware Update Protocol Support. Initialise
Firmware Update Protocol Support on creation and report CoAP
as default transfer protocol.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2021-11-03 15:34:15 +01:00
Robert Lubos 96b8ed85ad net: lwm2m: Fix removed engine_observer_list usage
`engine_remove_observer_by_path()` was not updated during some recent
LwM2M observer changes, still using the `engine_observer_list` which got
moved into the `lwm2m_context` structure. Update the function to align
with these changes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-11-03 11:19:40 +01:00
Robert Lubos 3a7016d99e net: lwm2m: Fix meaningless operant result coverity issue
There is no need to veirfy the result value of the strtol() operation,
as we copy the result to a 64 bit buffer anyway.

CID: 240696

Fixes #39810

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-10-31 15:31:05 -04:00
Tjerand Bjornsen 938e0e4966 net: lwm2m: Add default firmware update port
If a firmware update is fetched from a server, and no port number is set
in the URI (e.g. coap://example.com/fw_update), the client will try
to connect on the port specified by CONFIG_LWM2M_PEER_PORT.
If a port different from the peer port is to be used for firmware
update, this has to be set explicitly in the URI:
coap://example.com:5683/fw_update.

This fix adds CONFIG_LWM2M_FIRMWARE_PORT, which will be used when
fetching a firmware update without specifying the port number in the
URI.

Signed-off-by: Tjerand Bjornsen <tjerand.bjornsen@nordicsemi.no>
2021-10-14 16:34:48 -04:00
Robert Lubos 875c75c4f9 net: lwm2m: Replace float32_value_t with double
Replace the custom float32_value_t LwM2M type with native double, to
facilitate LwM2M API and improve floating point precission.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-10-13 10:13:32 -04:00
Tjerand Bjornsen 872f560981 net: lwm2m: Fix device obj missing error code ri
From the OMA LwM2M Object and Resource Registry: "When the single Device
Object Instance is initiated, there is only one error code Resource
Instance whose value is equal to 0 that means no error."

This fix creates that initial error code resource instance, and makes
sure that it doesn't get deleted by the Reset Error Code resource.

Signed-off-by: Tjerand Bjornsen <tjerand.bjornsen@nordicsemi.no>
2021-10-07 15:44:46 -04:00
Ryan Erickson f7208bbb62 net: lwm2m: Add option to force close the connection
Add an option to force close the LwM2M connection
instead of always trying to deregister.
If on a cellular connection and the connection is dropped,
deregistering will never complete and take a long time
before retries fail. This option allows the app to close the
socket and quickly re-establish the connection when the
network connection is available again.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-10-05 19:23:59 -04:00
Veijo Pesonen b3bc827366 net: lwm2m: Decouple CoAP message- and block size
If blockwise transfer is not in use it must be possible to send bigger
CoAP messages than what is the block size used with blockwise transfers.

To compensate for the increased memory usage number of in-flight packets
allowed could be decreased.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-05 19:22:54 -04:00
Veijo Pesonen 32b4ec44fe net: lwm2m: Fix Kconfig help about allowed...
...range for LWM2M_COAP_BLOCK_SIZE.

The range has been set to start from 64 bytes and now the help text has
been brought up to date.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2021-10-05 19:22:54 -04:00
Robert Lubos 2160e0fc36 net: lwm2m: Fix Registration failue reporting
In case LwM2M server or bootstrap server rejected
Registration/Registration Update/Deregsitration attempt, there were no
reasonable notification to the application. Fix this by reporting
LWM2M_RD_CLIENT_EVENT_*_FAILURE in such case.

Addtitionaly, remove pointless ENGINE_DEREGISTER_FAILED event, which
have no use in the state machine.

Finally, simplify the response code logging to prevent code duplication.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-21 09:32:31 -05:00
Robert Lubos 88c06aeb24 net: lwm2m: Fix IPSO Push Button counter incrementation
The Counter resource in the IPSO Push Button object was incremented
silently by the post write handler of the State resource. This prevented
the resource from being marked as updated, effectively preventing
the engine from sending notifications to observers.

Fix this, by setting the new counter value with `lwm2m_engine_set_u64()`
instead. This will update the resource value, and trigger the engine to
send notifications if needed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-20 05:59:28 -04:00
Robert Lubos 81595ed4db net: lwm2m: Fix binary to float32_value_t conversion
The helper function to conver 32-bit binary float value to
float32_value_t incorrectly identified the "hidden" bit, resulting in
invalid conversion when TLV encoding was used to write a resource
(the output value was divided by 2).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos 36a72dd101 net: lwm2m: Fix JSON write handling
There were several issues preventing JSON format writes to work
correctly:

1. The formatter wrongly assumed that Base Name and Relative Name values
   read from the message are NULL terminated, which in result could give
   invalid results when combining them.
2. The formatter wrongly assumed that Relative Name is always present,
   which is not always the case. In result, it failed to parse messages,
   which contained full path in their Base Name Field
3. There were no boundaries check when reading JSON variable name/value,
   which could lead to buffer overflow in case malformed data was
   received.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos a98d47b8eb net: lwm2m: Fix JSON floating point handling
Just like plain text, JSON parser ignored leading zeros after decimal
point, giving invalid results. Fix this in a similar way as for the
plain text.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos 20a4d181e1 net: lwm2m: Fix plain text floating point handling
Floating point parser for plain text format was parsing floats wrongly,
ignoring leading zeros after decimal points.

Fix this, by reusing atof32() function, already avaialbe in a different
part of the engine, which did the parsing correctly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos b6f69a6df1 net: lwm2m: Align float handling with specification
According to the specificaion, resources are not predefined to use 32 or
64 bit floating point numbers, but should rather accept any of them (as
indicated by the size of the TLV in the message). This lead to issues
for instance with Eclipse Leshan LWM2M server, where Leshan sent 64-bit
value, while Zephyr expected 32-bit, making it impossible to write
the resource.

Therefore, unify the float usage to 32-bit float representation and fix
the TLV parsing functions, to accept values sent as either 32 or 64 bit
float.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-16 19:04:52 -04:00
Robert Lubos 083f3065b4 net: lwm2m: Remove LWM2M_RES_TYPE_U64 type
Since it's not possible to encode full range of 64-bit unsigned integer,
remove this type from the LwM2M implementation, and replace its uses
with 64-bit signed integer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-10 11:04:41 +02:00
Robert Lubos b474e0a8c3 net: lwm2m: Fix unsigned integers ecoding in TLV
As the resource values represented by the unsigned integers were casted
to integers of a corresponding size in the read handler, they were not
ecoded properly if the unsigned value was larger than the maximum
integer value of the corresponding size (i.e. they were encoded as
negative values).

Fix this by casting the unsinged value to a wider integer type, to
prevent incorrect interpratetion of the data provided. The TLV encoding
functions take care of the optimization (i. e. encoding integers on the
minimum number of bytes needed), so it should prevent bandwith waste if
the unsigned value would actually fit into the integer of the
corresponding size.

Similar case is for the write hander, where unsigned integers encoded at
8 bytes were not processed correctly. Fix this by using wider decoder as
well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-10 11:04:41 +02:00
Maik Vermeulen 7a2a28b9d5 net: lwm2m: Synchronized functions mutating the RD client's state
A mutex is used to syncrhonize the start, stop and service() functions
of the RD client. Previously it could happen that while service() was
working on e.g. bootstrapping, a stop() call by another thread would
close the socket. Then the bootstrapping process would detect it as a
network error, and restart the process.

Fixes #37170.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-08-03 10:22:10 -04:00
Robert Lubos 0722e1d896 net: lwm2m: Prevent notifications on non-readable resources
In case a non-readable resource gets updated (either by the server or
with an API), it makes no sense to send a notification in such case, as
no such resources are not included in notifications anyway.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-20 13:33:22 +02:00
Robert Lubos b369156e28 net: lwm2m: Fix how payload offset is calculated
Instead of manually computing payload offset, let the CoAP library do
the work, and use the payload pointer returned by the
`coap_packet_get_payload()` function instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-07 07:40:55 -05:00
Markus Rekdal 3221a1e8e7 net: lwm2m: Fix handling of multi instance resources with one instance
This will fix a bug caused by creating a multi instance resource with
only a single resource. Previously this was treated as a single instance
resource. This is now properly treated as a multi instance resource with
one instance
Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2021-07-02 08:30:28 -04:00
John Power 3138d89fd9 net: lwm2m: notify timeout handling
Added notify_timeout_cb to struct lwm2m_ctx to allow application to
 handle notify timeout
Added lwm2m_rd_client_update to lwm2m.h to allow application to
 trigger registration update
Added notify_message_timeout_cb which calls notify_timeout_cb from
 struct lwm2m_ctx and logs an error message

Fixes #31499

Signed-off-by: John Power <john.power@xylem.com>
2021-06-23 08:02:06 -04:00
Kiril Petrov 613677daf8 net: lwm2m: fix build with bootstrap enabled
After lwm2m async io was introduced with 32989a38f0,
one instance of function lwm2m_send_message() was left unchanged,
and makes build to fail when boostrap support is enabled.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2021-06-14 14:10:36 +03:00
Kiril Petrov a0fd010455 net: lwm2m: code clean-up after switch to async socket io
Three is no need to check return code as lwm2m_send_message_async()
never fails.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2021-06-14 14:10:36 +03:00
Dominik Dess f55c473a06 net: lwm2m: lwm2m stops sending messages after encountering signals on send
Fixed issue that caused message to be not correctly reset even after
 it is consumed after send sets errno to EAGAIN or EWOULDBLOCK

Signed-off-by: Dominik Dess <dominik.dess@grandcentrix.net>
2021-06-12 08:51:08 -05:00
Henning Fleddermann 05b2018ffa lwm2m: keep track of observations per client
this has a number of advantages:
- allows to only create notifications for each client if there are no
  messages already waiting to be send, in practice prioritizing the
  memory for messages for answers, thus staying more "responsive".
- saves a fair bit of memory by eliminationg now redundant client_ctx
  pointer per observer.
- fixes a potential subtle bug: previously, an observer reset would've
  stopped the first observation found with a matching token, which
  might've belonged to a differen client.

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2021-06-07 10:39:37 +03:00
Henning Fleddermann 32989a38f0 lwm2m: use asynchronous socket io
This restructures the lwm2m_engine to use a non-blocking socket access
instead of the previously used blocking style, and eliminates any
socket-access from outside of the main work loop.

The main motivation behind this is an issue within nordics
nrf_modem_lib/modem-fw on nrf9160, that leads to socket send() calls to
block indefinitely when the shared memory used for
rpc-communication with the modem is already exhausted because of
incoming data.

This lead to the lwm2m_engine locking up on send calls when there is
also a large amount of incoming data.

This works around this issue, by only issuing send calls when poll
reports the socket to be ready for sending, and (more importantly) by
always receiving all buffered incoming data before sending anything.

There might still be a (perhaps academic) possibility where this
situation might be triggered, when  the scheduler interrupts the lwm2m
thread in-between receiving and sending, but for now we have not yet
observed this.

Besides working around the aforementioned issue, this also simplifies
the way resends are handled as they are no longer send from the main
system-workqueue, and limits all interaction with the sockets to a
single thread.

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2021-06-07 10:39:37 +03:00
Benjamin Lindqvist f0f1a4d724 net: lwm2m: no duplicate device error codes
The resource description on the OMA LwM2M registry states that only the
first instance of a particular error should trigger creation of a new
error code instance.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2021-05-21 04:55:26 -05:00
Jan Buenker 6815ef4a46 net: lwm2m: Only parse TLV from the first block
This was already implemented for firmware update packages.
For other opaque resources it failed to determine the target resource
id, which is now stored in the block_context.

Signed-off-by: Jan Buenker <jan.buenker@grandcentrix.net>
2021-05-13 22:07:25 -04:00
Robert Lubos 126da28620 net: lwm2m: Trigger registration update only when registered
Add extra check for the LwM2M client state, to allow triggering of the
Registration Update message only when registered.

This fixes an issue, when the `trigger_update` flag could be set during
the bootstrap procedure (when the value of the Lifetime resource was
set), which resulted in an uneccessary Registration Update message just
after the successful registration.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-05-05 14:04:41 -05:00
Robert Lubos 0d1577f7fe net: lwm2m: Add API function to delete object instance
Since the API already has a function to create an LwM2M object instance,
it makes sense to add a corresponding delete funtion, allowing the
application to delete created objects.

Additionally, for the remote delete set the Registration Update trigger
only when not in bootstrap mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-29 09:51:54 -04:00
Robert Lubos 66c5fdc984 net: lwm2m: Fix Registration Update send on object creation
The Registration Update message should be sent whenever an object
instance is created or deleted. Currently this was only the case when an
object instance was created by the server and not by the application.
Fix this by triggerng the Registration Update from the API function
as well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-29 09:51:54 -04:00
Robert Lubos 653c987762 net: lwm2m: Fix lwm2m_path_log_strdup buffer usage
Currently the lwm2m_path_log_strdup allocates a temporary buffer on a
stack, and then passes it to the log_strdup function to create a copy
of the string for the logger. log_strdup however will not copy the
string if for instance immediate logging is used, therefore the logging
function will still use the memory address of the already invalid buffer
allocated within lwm2m_path_log_strdup.

Fix this by passing an addittional `buf` parameter to the
lwm2m_path_log_strdup function, therefore allowing the user to provide
the buffer within a valid scope.

CID: 220536
Fixes #34005

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-28 19:30:09 +02:00
Maik Vermeulen 4d85426688 net: lwm2m: Made pmin and pmax attributes optional
Made the LwM2M engine checks for pmin and pmax optional to adhere to
the LwM2M specificattion. We now first check that pmin and pmax are
actually set. Also changed the default CONFIG values for the attributes
pmin and pmax to 0 to indicate that they are not active by default.

Fixes #34329.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-04-16 15:32:04 -04:00
Robert Lubos 19e7451c34 net: lwm2m: Fix unitialized variable error in Link Format writer
The `init_string` array could have been used uninitialized, fix this
by initializing it as an empty string, which is a desired content in
case it's not overwritten.

CID: 220302
Fixes #33839

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-14 14:36:35 -05:00
Peter Bigot 188cb2cb7c net: Conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-14 07:07:40 -04:00
Benjamin Lindqvist e3f8757b70 net: lwm2m: Allow cancel-observe to match path
The specification states that the server can cancel observations "at any
moment, by sendinga GET request with Observe option=1, the LwM2M Server
cancancel an “Observe”operation on a specified Resource, or specified
Object Instance(s)."

It does not mention any token matching requirement, but RFC 7641 does.
The correct interpretation is not obvious. The EMQx LwM2M implementation
uses a new token for instance, which does not work with Zephyrs token
matching cancel-observe.

This commit introduces cancel-observe via path matching as a Kconfig
option. This could hypothetically introduce problems when we are
connected to multiple peers simultaneously, but since that is not likely
to be supported for a long time (if ever), this change should be fairly
uncontroversial since path matching is only used as a fallback.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2021-04-01 09:42:56 +03:00
Robert Lubos 539e4edcc6 net: lwm2m: Remove obsolete LWM2M_IPSO_TIMESTAMP_EXTENSIONS option
All IPSO objects that utilized the non-standard timestamp extension now
implement their model in version 1.1, which contains the Timestamp
resource. As it's no longer needed to add timestamp in a non-standard
way, simply remove LWM2M_IPSO_TIMESTAMP_EXTENSIONS option.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos 1efc8e7353 net: lwm2m: Add IPSO Buzzer object in version 1.1
Update IPSO Buzzer object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos 885dd5ff1f net: lwm2m: Add IPSO Push Button object in version 1.1
Update IPSO Push Button object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos 8853730dec net: lwm2m: Add IPSO On/Off Switch object in version 1.1
Update IPSO On/Off Switch object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos 9b1f0e3da0 net: lwm2m: Add IPSO Accelerometer object in version 1.1
Update IPSO Accelerometer object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos ca21c03e8c net: lwm2m: Add IPSO Pressure Sensor object in ver. 1.1
Update IPSO Pressure Sensor object implementation to support object
model version 1.1.

Add missing optional resources for the object model version 1.0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos 7546c5bf29 net: lwm2m: Add IPSO Humidity Sensor object in ver. 1.1
Update IPSO Humidity Sensor object implementation to support object
model version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos 1bd6e5bde3 net: lwm2m: Add IPSO Generic Sensor object in version 1.1
Update IPSO Generic Sensor object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos c83fca2784 net: lwm2m: Add IPSO Temperature object in version 1.1
Update IPSO Temperature object implementation to support object model
version 1.1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos 49b0e2cc76 net: lwm2m: Unify reusable resources creation
Some of the objects redefined reusable resources IDs, while others used
a common header which defines resource IDs. Unify the approach and use
the header in every object.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos c9f5337a91 net: lwm2m: Add support for object versioning
Each object now have to specify the object version it implements.
Based on this information the LwM2M engine can decide whether it's
needed to report the object version during Registration/Discovery
operations or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-29 13:42:11 -04:00
Robert Lubos c50c0f6d07 net: lwm2m: Use link_format writer for Register/Update
The payload of the Register/Register Update message is also formatted as
application/link-format. Therefore it's reasonable to reuse the new
content writer instead of filling the payload manually.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Robert Lubos b17555eb9e net: lwm2m: Add application/link-format content writer
This commit adds a new content writer, application/link-format, which
can be used during the Discovery procedure, to fill the content of the
response payload.

Introducing this new content writer, which encapsulates some of the
details like attribute handling which is different for bootstrap/regular
discovery, allows to unify the discovery handler in the lwm2m_engine,
thus it's no longer needed to have spearate handler functions for
bootstrap/regular discovery.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Robert Lubos 6ba362b11b net: lwm2m: Remove .well-known/core handling
`.well-known/core` resource is described by the CoAP RFC as an optional
method of resource discovery. The LwM2M specification though makes no
mentionon about this mechanism and provides an alternative method of
resource discovery instead (Device Management Discover, sec 5.4.2, and
Bootstrap Discovery, sec 5.2.7.3).

Since LwM2M does not require to implement `.well-known/core` resource
and it complicates the existing Discovery mechanism (and likely cause a
security concern) remove its handling from the LwM2M implementation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Robert Lubos d53fb5700d net: lwm2m: Introduce attribute handling helper functions
Introduce LwM2M engine helper functions that allows to work with LwM2M
attributes outside of lwm2m_engine.c.

This is a groundwork for application/lwm2m-format content writer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-18 10:18:57 +01:00
Robert Lubos 6a90baa21a net: lwm2m: Make validation cb support optional
Add option to disable validation callback support by setting the
validation buffer size to 0, which allows to save some memory in case
it's not needed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-10 14:55:22 -05:00
Robert Lubos 31e5ec79b8 net: lwm2m: Add data validation callback
Add a data validation callback to the resource structure, which can be
registered by an application. It allows to verify the data before
actually modifying the resource data.

If the callback is registered for a resource, the data is decoded into a
temporary buffer first, and only copied into the actual resource buffer
if the validation is successfull. If no validation is required (and thus
no callback registered) the resource value is decoded directly into the
resource buffer, as it used to be.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-10 14:55:22 -05:00
Robert Lubos 64c836d5e2 net: lwm2m: Check return value of option encoding on deregistration
Verify the result of option encoding while forming Deregister message
instead of silently ignoring it.

Coverity ID: 215373
Fixes #33096

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-09 09:23:48 -05:00
Robert Lubos 7f3537f0d3 net: lwm2m: Initialize the variable to silence compiler warning
The compiler generates a warning regarding a variable being used
w/o being initialized in certian configuration. According to the logic
that's not the case, so just add some initial value to the variable to
silence the compiler.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-04 14:53:05 -05:00
Robert Lubos 651e4ac62b net: lwm2m: Make sure that endpoint string is NULL terminated
In case the endpoint string provided by the application is longer or
equal to CLIENT_EP_LEN - 1, the strncpy() function will not add the NULL
terminator. As the endpoint buffer is treated as a C-string in other
places in the code, make sure it's NULL terminated by adding NULL
explicitly at the end of the buffer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-02 09:16:01 -05:00
Robert Lubos f14a9556d6 net: lwm2m: Make query buffer large enough to encode all query strings
Make sure query string used by the lwm2m_rd_client is large enough to
encode any query string that can be sent during bootstrap/registration.
As the maximum query string length is related to the endpoint name,
which is limited by `CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH`,
make the query string corellated to the value of this config.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-02 09:16:01 -05:00
Thomas LE ROUX 37dca20444 net: lwm2m: Utility functions added to LWM2M Engine
Added 3 utility functions :
- lwm2m_engine_update_period_service() which updates the period of a
given service.
- lwm2m_engine_update_period_min_observer() which updates the
min_period_sec for a given observe node.
- lwm2m_engine_update_period_max_observer() which updates the
max_period_sec for a given observe node.

Signed-off-by: Thomas LE ROUX <thomas.leroux@smile.fr>
2021-02-19 10:52:08 +02:00
Hubert Miś 22687c34e3 net: coap: define default CoAP version
RFC 7252 (CoAP) specifies value of the Version (Ver) field in the
protocol header to value 1. This patch defines value of the Version
field to make packet initialization easier. All samples and tests
are updated to use the new COAP_VERSION_1 field when initializing
a CoAP packet.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-02-02 14:03:01 -05:00
Robert Lubos 538e19ee2e net: coap: Rework pending retransmission logic
Introduce retransmission counter to the coap_pending structure. This
allows to simplify the retransmission logic and allows to keep track of
the number of remaining retranmissions.

Additionally, extend the `coap_pending_init()` function with `retries`
parameter, which allows to set the retransmission count individually for
each confirmable transaction.

Fixes #28117

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-18 23:22:37 -05:00
Robert Lubos 366a2147cc net: lwm2m: Add dimension discovery support
Multi-instance resources shall report its dimension (number of
resource instances) on discovery. Since it was not possible to tell
simply on the instance count whether the resource is multi-instance or
not (there could be a multi-instance resource with only one instance
avaialble) add a new parameter to the structure representing resource,
indicating whether it's multi-instance or not.

Add dimension information to the discovery result.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-18 11:59:50 +01:00
Robert Lubos 18cfc3761e net: lwm2m: Cleanup Device Management Discovery
Remove any references of Bootstrap Discovery from Device Management
Discovery procedure and fix some of it's logic following the
specification.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-18 11:59:50 +01:00
Robert Lubos 1c9fb5488b net: lwm2m: Implement bootstrap discovery
Bootstrap discovery was not implemented properly in the LwM2M engine.

Although, there were some indications in the source code that it is
implemented, it was not done according to spec (and actually broken).

Given that Bootstrap Discovery procedure differs a lot from the regular
Device Management Discovery (different permissions, different
information returned), it's easier to implement it as a separate
function (`bootstrap_discovery()`) instead of making the existing
`do_discovery_op()` function even more complicated.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-01-18 11:59:50 +01:00
Maik Vermeulen f03d1177d0 net: lwm2m: Direct firmware_transfer() call instead of work-item
The LwM2M firmware pull object no longer uses the system workqueue
to execute firmware_transfer(), but directly executes it itself.
Previously, the workqueue would be blocked because firmware_transfer()
indirectly calls a blocking connect(). This would lead to problems
with e.g. modem drivers that use UART to interface with the modem
hardware, as some UART drivers use the workqueue.

Fixes #31053.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2021-01-08 15:46:57 +02:00
Maik Vermeulen 4cfd2a1943 net: lwm2m: Added execute arguments support
A dedicated LwM2M execute callback type has been implemented which
supports execute arguments. The lwm2m engine, lwm2m_client sample and
lwm2m objects have been updated accordingly. Also the API change has
been documented, and the lwm2m engine reference has been updated.

Fixes #30551.

Signed-off-by: Maik Vermeulen <maik.vermeulen@innotractor.com>
2020-12-13 15:39:08 -05:00
Henning Fleddermann 061de0376a net: lwm2m: fix buffer length check in lwm2m_engine_set
Previously, lwm2m_engine set would check against the max_data_len
parameter of the ressource, but didn't take into consideration the
(possibly changed) max_data_len returned by the pre_write callback.

Fixes #30541

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
2020-12-09 11:21:48 +02:00
Robert Lubos 7eefde36c3 net: lwm2m: Fix msg find based on pending/reply
The message should only be returned if the requested pending/reply
pointer is not NULL. Otherwise it could get an incorrect match (for
instance if specific pending pointer is searched for and reply is NULL
the function could return any message that doesn't expect a reply (and
thus has its reply pointer set to NULL).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-12-03 13:53:33 -05:00
Robert Lubos 4331c05f17 net: lwm2m: Allow to acknowledge request early from the callback
LwM2M engine by default sends piggybacked responses for requests after
all callbacks are executed. This approach however isn't good enough if
the application callback executes some lenghty operations (for instance
during FW update). Delaying the ACK may result in unnecessary
retransmissions.

This commits adds an API function which allows to send an early empty
ACK from the application callback. This prevents further retransmissions
from the server side. After all callbacks are executed, the LwM2M engine
will send the response as a separate CON message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-12-03 13:53:33 -05:00
Robert Lubos b27c14e355 net: lwm2m: Verify if block transfer is used before skipping TLV parsing
Verify if block tranfer is used and not an initial block when skipping
directly to data processing during FW update in PUSH mode.

This fixes a bug, which caused TLV not to be processed when the FW
object was updated as a whole, and actual resource number was encoded in
a TLV (for instance when writing FW Update URI).

Fixes #30135

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-12-01 11:26:55 -05:00
Robert Lubos 1c8f52a670 net: lwm2m: Rework bootstrap DELETE operation
Rework the bootstrap DELETE operation, to support deletion of multiple
resources.

Current implementation had several oversimplifications, making it not
spec-compliant:
* DELETE `/` removed only Security object instances (!= 0)
* DELETE `/x` was handled as DELETE `/x/0`, therefore not removing all
  of the object instances.

Since the above is only supported during bootstrap and not regular
Device management, this functionality was implemented in the
`bootstrap_delete` function, which now will be called for all DELETE
operations initiated during bootstrap. The regular LwM2M DELETE handler
will only be called during regular Device management, as it has more
strict limitations on what can be deleted.

Additionally, handle empty URI Path option as `/`, therefore indicating
deletion of all resources.

Fixes #29964

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-12-01 11:17:12 -05:00
Jukka Rissanen f02fd19706 net: Adjust the thread priorities
If networking pre-emptive thread priorities are enabled,
then use the proper macro to enable them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-11-20 12:57:29 +02:00
Kiril Petrov 539c3e7fa8 lwm2m: handle return code from lwm2m_socket_add
Handle return code from lwm2m_socket_add

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2020-11-16 14:28:08 +02:00
Robert Lubos 7127f0a742 net: lwm2m: Notify the application on network error
Add a simple backoff mechanism between consecutive registration attempts
in case of registration failures. Finally, notify the application in
case the registration failed several times.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-06 12:58:14 +01:00
Robert Lubos 571b65830b net: lwm2m: Move bootstrap registration send into a separate function
Refactor the boostrap regstration procedure, by splitting the message
creation and sending into a separate function, in similar manner as
it's done with regular registration.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-06 12:58:14 +01:00
Robert Lubos 397b2a71fa net: lwm2m: Add a callback to notify socket errors to engine users
Currently, when socket errors occur during receive, the LwM2M engine
restarts the state machine and registers again to the server. While this
works in simple use case (only RD client socket open), it's not a valid
approach when more sockets are open (FW update socket).

Fix this by introducing socket fault callback, which is registered by
the LwM2M engine users. This way, a proper socket owner is notified on
error and can pertake appropriate action.

For RD socket errors the behaviour remains the same - the state machine
is reset and the client registers again to the server. For FW update
socket, handle the error by reopening the socket and retransmitting the
last request. This allows to resume the download from the point the
error occured, w/o a need to start from scratch.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-06 12:57:32 +01:00
Robert Lubos 4625820354 net: lwm2m: Send Registration Update on lifetime change
According to LwM2M specfication v1.0.2, par. 5.3.2, the LwM2M client
MUST send an “Update” operation to the LwM2M Server whenever the
lifetime parameter of the Server object changes the server). The same
applies for the object instances created/deleted. The changes in objects
seem to already be handled, but the lifetime was not.

Additionally, the "Update" message shall only contain these parameters
which changed since the last update (including objects). As it's
straightforward to determine if the liftime  changed but it's not easy
to tell if there were updates in the object instances, add an
additional parameter to the engine_trigger_update() function, indicating
that new object information shall be sent in the "Update" message.

Eventually add a proper error checking in `sm_send_registration` as the
function is reworked anyway.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-03 16:25:13 +01:00
Robert Lubos f747022d9e net: lwm2m: Fix PULL FW update in case of URI parse errors
The memset on firmware_ctx during PULL FW update initialization will
set the socket descriptor to a valid value of 0. This leads to an error
if parsing of the URI provided by the server fails, and the firware_ctx
is closed - the socket with a descriptor 0 will be accidently closed.
Fix this by invalidating the socket FD after the memset on
initialization.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-03 16:24:34 +01:00
Robert Lubos d8912fe895 net: lwm2m: Remove handle_separate_response flag
It shouldn't be optional to handle separate response, as it's a
mandatory requirement according to the RFC7252:

"The protocol leaves the decision whether to
 piggyback a response or not (i.e., send a separate response) to
 the server.  The client MUST be prepared to receive either."

Therefore, remove the flag as separate responses are handled now
properly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-03 16:23:59 +01:00
Robert Lubos 37681a7bef net: lwm2m: Fix separate response handling
Separate response handling implemented in the engine was faulty. The
separate response was not acknowledged by the client, resulting in
spurious retransmissions from the server side.

Also, the pending CON message was retransmitted by the client even after
it was acknowledged by an empty ACK, but the respnse haven't arrived
yet. Fix this by adding a new `acknowledged` flag to the `lwm2m_message`
structure. Once acknowledged, the flag is set and the confirmable
message is no longer retransmitted. We keep the message on the pending
list in order to timeout properly in case separate response does not
arrive in time.

Finally, prevent the reply callback from being called twice in case
the response is transmitted separately from ACk. The callback should
only be called on the actual reply, not the empty ACK.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-03 16:23:59 +01:00
Robert Lubos 94d62ca151 net: lwm2m: Add lwm2m_send_empty_ack() function to internal API
So far this function existed as a static function in LwM2M PULL FOTA
module. Since such functionality will be needed in other places, make it
an internal API function.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-11-03 16:23:59 +01:00
Viktor Sjölind 1b3abc096c net: lwm2m: Start notify sequence numbers on 0
Some LWM2M backends/servers, such as emxq, expect the sequence numbers
to begin on 0.

This change is in line with how other lwm2m clients, such as Anjay and
Wakama, starts the notification sequence.

Signed-off-by: Viktor Sjölind <viktor.sjolind@endian.se>
2020-10-27 11:25:22 +02:00
Benjamin Lindqvist 660ad9791b net: lwm2m: Pack TLV integers more efficiently
Prior to this commit, the LwM2M stack would TLV-encode integers
depending on their internal storage size. An integer with value 5 stored
in an int8_t would be encoded with length 1, but an integer stored in an
int32_t would be encoded as "00 00 00 05" with length 4.

This commit checks if the value is castable to a smaller int and encodes
it as such if so. This is cascading, so even a 64 bit integer with value
5 will be encoded with length 1.

Note that this does not seem to be required by the specification, but
this is how Anjay and the other LwM2M stack seem to do it.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-26 11:31:28 +02:00
Robert Lubos 2497958298 net: lwm2m: Improve token generation
Improve token handling by removing special meaning of tokenlen == 0,
which allows to handle server requests w/o a token (so far such
requests would cause the lwm2m engine to autogenerate token in the
response).

In order to autogenerate token during message initialization, use
special symbol `LWM2M_MSG_TOKEN_GENERATE_NEW`. If no token is wished to
be used, simply set the tokenlen to 0.

Additionally, fix an issue with token autogeneration, where invalid
token len was used (0 instead of 8).

Fixes #28299

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-09 10:46:53 +03:00
Robert Lubos b932edc772 net: lwm2m: Fix bootstrap finish response code
LwM2M engine did not set response code for the Bootstrap-finish message,
hence it replied with the code copied from the request which is not
correct. Fix this by setting correct code for the Bootstrap-finish
reply.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-08 16:31:56 +03:00
Robert Lubos 5fc7d86d7c net: lwm2m: Report boostrap complete after final response is sent
So far, `LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE` event was
reported before the final ACK for the Bootstrap Finish was sent from the
client side. This could cause delays in the ACK sending, in case the
application wanted for instance to store the received data in flash.

Fix this, by reporting the
`LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE` event on the next
state tansition (before the actual registration starts).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-06 12:01:13 +03:00
Robert Lubos f35d88503a net: lwm2m: Use the actual data size when provisioning PSK ID
"Public Key or Identity" resource is of opaque data type, therefore it's
not correct to assume it will be a NULL terminated string (the existing
servers, for instance Leshan, does not include NULL terminator). Use the
actual size associated with the resource instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-06 12:01:13 +03:00
Robert Lubos f223d0a86f net: lwm2m: Store the actual resource size in the resource instance
So far, the resource instance structure kept only the information about
the buffer length provided to the resource (in the `data_len` field).
While this approach might be enough for integer resources, where the
actual data size is fixed, it did not work for opaque resources. It is
impossible to determine the actual opaque resource length after it's
been written into.

Fix this, by replacing the current `data_len` field of the
`lwm2m_engine_res_inst` with `max_data_len`, indicating the buffer
size, and making the `data_len` field to hold the actual data size of
the resource.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-06 12:01:13 +03:00
Robert Lubos f7a5638871 net: lwm2m: Make bootstrap optional
Currently, after `CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP` is enabled,
the LwM2M engine will initiate bootstrap procedure on each run. This
approach limits the flexibility of the application, as it's not always
necessary to go over the bootstrap procedure (for instance, the
application may decide to store the security object obtained during the
bootstrap in flash, and restore it on boot).

Fix this by introducing an additional `flags` parameter to the
`lwm2m_rd_client_start()` function, which provides information whether
to run bootstrap in the current session or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-06 12:01:13 +03:00
Robert Lubos 40d25b8efa net: lwm2m: Introduce ENGINE_IDLE state
So far, the LwM2M state machine started in the `ENGINE_INIT` state,
which made it exectue the registration/bootstrap registration even when
`lwm2m_rd_client_start()` was not called. With a new `ENGINE_IDLE`
state, the state machine can wait for the application to actually start
the client before proceeding. It also makes sense to stay in the
ENGINE_IDLE state after successfull deregistration, until the
application restarts the client.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-06 12:01:13 +03:00
Robert Lubos 12e1fd653d net: lwm2m: Fix FOTA block transfer with opaque content-format
This commit fixes PUSH FOTA when opaque content-format is used.

This consists of the following fixes:
 * Moved `struct block_context` to a private header, so that it can be a
   part of `struct lwm2m_input_context`. This allows content decoders to
   make use of the block context data.
 * Removed faulty `get_length_left` function from the plain text
   decoder, and replace it with coap_packet_get_payload() to obtain the
   actual payload size.
 * Introduce `struct lwm2m_opaque_context` as a part of block context,
   which allows to keep track of opaque data download progress.
 * Simplify `lwm2m_write_handler_opaque()` function. It will now only
   make calls to `engine_get_opaque` - it's the decoder responsibility
   to update the opaque context according to it's content format (for
   instance TLV decoder should only update it with the actual opaque
   data size, not the whole TLV).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-10-05 12:16:57 +02:00
Pascal Brogle e3e465a29c net: lwm2m: make max client endpoint name configurable
support longer name like urn:dev:ops:{OUI}-{ProductClass}-{SerialNumber}
or urn:imei-msisdn:###############-###############

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2020-09-28 14:24:14 +03:00
Pascal Brogle 32f053403f net: lwm2m: remove special handling for message id 0
Change so that the caller of lwm2m_init_message is
responsible for generating a message id and remove message id generation
from lwm2m_init_message. Prevents generating a new id when the caller's
intent is to init a message with id 0.

Fixes #28283

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2020-09-17 13:34:19 -05:00
Pascal Brogle 18a51a0bf6 net: lwm2m: use defines for message id and token generation
message id 0 and token 0 have special semantics in the lwm2m engine,
they are used to request generation of new id, mark them as such.

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
2020-09-17 13:34:19 -05:00
Robert Lubos bff0f954a9 net: lwm2m: Make sure Sensor Type string isn't too long
The default string representing Sensor Type resource in Generic IPSO
object would not fit into the predefined buffer. Increase the buffer
size and add extra BUILD_ASSERT to detect this situation.

Coverity ID: 214225

Fixes #28164

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-09-09 14:10:29 +03:00
Marin Jurjevic 1753fac49a net: lwm2m: Fix FOTA Pull firmware transfer when Package URI is empty
Fix for a problem in current lwm2m firmware object implementation.
Transfer should not begin when an empty string is received.

Signed-off-by: Marin Jurjevic <marin.jurjevic@hotmail.com>
2020-09-04 12:18:58 +03:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Ryan Erickson 2ce87da252 net: lib: lwm2m: add new sensor objects
Add generic, humidity and pressure sensor objects.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2020-08-27 11:01:09 +03:00
Flavio Ceolin 0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Robert Lubos ab9f8bac28 net: lwm2m: Update lifetime on Register Update event
The LwM2M server might modify the lifetime value while the device is
registered, hence it's needed to obtain the value directly from the
Server object instance, before each Register Update.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-08-04 16:29:40 +02:00
Robert Lubos b9caaf217e net: lwm2m: Fix Security and Server object instance matching
A proper way to match a Security object instance with a Server object
instance is via Short Server ID resource. Both coupled object instances
should carry the same value of this resource in order to me considered
matched.

This was not implemented in the LwM2M library and it was incorrectly
assumed that the Security object instance index corresponds to the
Server object instance index. While such apporach works is simple
scenario, it might yield incorrect results when bootstrap is used.

Fix this, by verifyng the Short Server ID resource in the Secuirty
instance used, and finding a matching Server instance. The server object
instance is stored for future use in the engine.

Additionally, remove an extra Server object instance that was created
when the bootstrap procedure was used. Since the boostrap Security
object instance does not have the corresponding Server object, it's
enough to have a single Server instance.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-08-04 16:29:40 +02:00
Andrew Boie c0d3ed0d1c net: use kernel stacks
These threads don't run in user mode, save some memory if
userspace is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-01 08:13:15 -04:00
Robert Lubos d20b1aebf9 net: lwm2m: Fix poll fds handling
Currently, functions for poll sock_fds array management are buggy, in
case there is another socket open (for instance the socket for firmware
update download), it could get overwritten, if the LwM2M socket was
closed and re-opened in a meantime (e. g. on registration timeout).

Fix this, by appending new entries to the sock_fds in continuous manner.
In case of removal, the deleted entry is overwritten by the last one,
and the last one is cleared.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 15:08:14 +02:00
Robert Lubos b080dfbd12 net: lwm2m: Fix block transfer retransmissions
During FW update, the application expects a consecutive data stream.
Therefore retransmitted blocks shall not be forwarded to the
application, but ignored. In case blocks are received out of order,
return an error and do not handle this block.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 15:08:02 +02:00
Robert Lubos 69ca589256 net: lwm2m: Fix opaque data transfer in block mode
When FW update in PUSH mode is used, the firmware is encapsulated in the
TLV as an opaque data, according to the LMWM2M satandard, and then
sliced into blocks and transferred block by block in several
transactions. Therefore, the TLV header is only present in the initial
message.

Current implementation did not handle this case well, reporting errors
on consecutive blocks, therefore making the FW update in PUSH mode
broken.

This commit fixes this issue with following changes:
 * The TLV is only assumed to be present in the initial block, while
   consecutive blocks will be processed directly into the appropriate
   handler,
 * 32-bit variables shall be used whenever dealing with the opaque data
   length, since the firmware size can easily exceed the 16-bit range,
 * Additional information, required for the FW block transfer to work
   properly were added to the block context structure,
 * The application shall only be notified of the actual data length, and
   not the total block size (the total TLV size including header).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 15:08:02 +02:00
Robert Lubos daf303e660 net: lwm2m: Fix unused return value from sys_mutex calls
Fixes coverity issues 211473 and 211477.

Fixes #26988
Fixes #26989

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 12:40:40 +02:00
Robert Lubos ac305149bb net: lwm2m: Remove duplicated logs during bootstrap
Remove the `sm_bootstrap_reg_done` function, which produced duplicated
logs. The bootstrap registration done event is already logged on state
transition. Additionally, in case bootstrap procedure took longer time,
the duplicated log message was printed on each `lwm2m_rd_client_service`
call (500 miliseconds by default).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-20 12:50:25 -04:00
Robert Lubos c59271d9f0 net: lwm2m: Clear security object instance on engine restart
The security object instance used should be cleared on engine reset,
otherwise we might end up using invalid object instance for the
registration (i. e. if the engine was restarted during the bootstrap
procedure due to socket errors, the registration attempt will use
bootstrap security object instead of finding a proper one).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-20 12:50:25 -04:00
Robert Lubos 00d12041f6 net: lwm2m: Initialize CoAP response on bootstrap finish
During the bootstrap procedure, when Boostrap Finish was received, the
response message was not initialized properly, resulting in a socket
error (NULL pointer porovided) and the response not being sent.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-20 12:50:25 -04:00
Robert Lubos 38adddac00 net: lwm2m: Reinitialize address length before recvfrom is called
`addrlen` parameter is updated on each `recvfrom` call, indicating the
actual address length returned. In case both, IPv4 and IPv6 are used on
different sockets (i. e. on regular LWM2M socket and FOTA socket), the
returned address length will differ.

In case `from_addr_len` is not reinitialized on each iteration, the
value stored in the `from_addr_len` variable will eventually indicate
the smaller IPv4 address size, therefore resulting in a failure in a
consecutive call on an IPv6 socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-14 13:04:37 +02:00
Robert Lubos fddeb59911 net: lwm2m: Protect send() calls with a mutex
Although LwM2M engine uses cooperative threads, the internal `send()`
implementation might trigger context switch when it calls a kernel
function, therefore resulting in `send()` call being entered from both
the LwM2M thread and the retransmit work.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-14 13:04:37 +02:00
Robert Lubos c5132aac18 net: lwm2m: Fix invalid logical and operator usage
Binary and should be used instead.

Fixes #26356.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-07 15:06:22 +02:00
Robert Lubos 2eb633d12e net: lwm2m: Reset only messages owned by lwm2m context
The context should only clear messages it owns, not all of them. Since
both context (LwM2M and FOTA) share common message pool, they might
interrupt their operation otherwise (i. e. cancel retransmissions).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-06 18:01:31 -04:00
Robert Lubos 8b22521b6b net: lwm2m: Close FOTA socket when finished
The FOTA socket was not closed when download finished or an error
occured.

Additionally, fix the socket fd verification (it was assumed 0 is not a
valid fd which is not correct).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-06 18:01:31 -04:00
Robert Lubos 3ea5c2180a net: lwm2m: Prevent infinite loop in do_write_op_tlv function
In case unsopported TLV type or malformed packet is received, the
`do_write_op_tlv` function will end up in an infinite loop. Prevent that
by returning an error code in case it does not recognize TLV type.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-06 17:57:40 -04:00
Robert Lubos 44c1101e93 net: lwm2m: Make Registration Update ahead time configurable
Allow to configure, how long before registration timeout should the
Registration Update be sent. The fixed 6 seconds used so far, might
not be enough in slower networks (like NB-IoT), resulting in frequent
re-registrations at LWM2M level.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-18 19:38:19 +02:00
Robert Lubos 0cf55c4174 net: lwm2m: Fix "Server Store Notify" resource type in Server object
This should be boolean according to specification. It makes difference
when JSON encoding is used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-15 22:13:34 +03:00
Robert Lubos 4c868c9abf net: lwm2m: Fix ExtDevInfo field in Device object
The field used incorrect type (s32 instead of ObjLnk) and was not
initialized properly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-15 22:13:34 +03:00
Robert Lubos bd7d6926c4 net: lwm2m: Add ObjLnk resource type support
Implement LWM2M ObjLnk resource type and plaintext, TLV and JSON
readers/writers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-15 22:13:34 +03:00
Kumar Gala 59708769ea net: lwm2m: Remove deprecated functions
Remove deprecated functions that have been marked deprecated since
Zephyr 2.0.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-11 15:50:48 +03:00
Gerson Fernando Budke ebe5345e87 net: lwm2m: Refactor to use coap_get_option_int
Small clean-up to use coap_get_option_int.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-06-09 21:25:11 +03:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Xavier Chapron e5aaf21a73 subsys: Replace printf by printk when applicable
Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-05-09 21:25:33 +02:00
Robert Lubos 358dcc1bde net: lwm2m: Handle socket errors
So far socket errors reported by poll/recvfrom were ignored, which could
lead to an unexpected behavior when socket was left in an undefined
state.

Fix this, by requesting a re-registration in the LWM2M state machine,
which will close the faulty socket and open a new one. Note, that simply
closing and re-opening a socket in the lwm2m engine would not work,
since this would silently invalidate any open observations on the
lwm2m server side (due to port number change). Triggering a fresh
registration will notify the server to update its observations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-30 08:57:18 +03:00
Kiril Petrov ea072341d5 net: lwm2m: init pendings and replies on lwm2m_engine_start
On OT network with poor coverage, very often request/observe packets
doesn't get it's ACK and consumes from pendings/replies/message stacks.
In such cases when LWM2M engine tries to recover by resetting its state,
it fails because of lack of free messages.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2020-04-28 20:46:35 +03:00
Robert Lubos ae4ddc77cc net: lwm2m: Lower log level for duplicate response
In networks with high latencies (like NB-IoT), it's quite common to
recieve duplicated response. It's not an error condition, a correct way
to handle it is to simply ignore the duplicate. Lower the log level for
this event, not to disturb users.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-28 09:50:45 +03:00
Robert Lubos afb73d1d09 net: lwm2m: Fix retransmission logic
The retaransmission logic was not correct in the lwm2m_engine, and could
lead to faulty behavior in case multiple messages were pending for
retransmission in the queue.

1. Since there is a singe delayed work item for entire retransmission
   queue, `coap_pending_next_to_expire` should be called before
   scheduling next timeout, to identify which message is going to expire
   next (and when). Currently, the engine always set next timeout, based
   on timeout from the message being currently re-transmitted.
2. In case the message was re-transmitted several times, and is removed
   from the retansmission queue due to a timeout, next retransmission
   should be scheduled, in case there are other messages on the queue.
3. Verify the timeout of the earliest message to expire in the
   retransmission handler. In case messages from the beginning of the
   queue were removed, we might need to schedule the retransmission
   again, instead of sending message rightaway.
4. `lwm2m_send_message` is not handling retransmissions anyway, so
   there's no need to check send attempts. Instead, verify
   retransmission work item is already pending, and update its timeout
   if needed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-28 09:50:45 +03:00
Robert Lubos 40ac0a7a7d net: lwm2m: Convert to new timeout API
Align LWM2M stack implementation with the new timeout API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-28 09:50:45 +03:00
Göran Weinholt 32864ecbcc net: lwm2m: support for reading OPAQUE resources with OMA TLV
The LwM2M stack would previously ignore all OPAQUE resources when
reading them. This meant that it was impossible to read them, even if
there was a custom read callback.

Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
2020-04-23 10:16:52 +03:00
Robert Lubos 8d984b336e net: lwm2m: Initialize socket FD to an invalid value
During registration, first thing LWM2M does is trying to close a socket
indicated by sock_fd stored in its context. In case it is not
initialized to some invalid value (-1 in this case), LWM2M may close an
ambigous socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-21 20:58:56 +02:00
Robert Lubos 16d8a8359c net: lwm2m: Fix Cell ID resource initialization
Cell ID resource was not initialized properly in the Connectivity
Monitoring object, making it unusable from the application.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-18 16:27:56 +03:00
Kyle Sun a9b926414c net: lwm2m: Publicize firmware block context
This change is to allow access to the firmware block context in order to
give the firmware update callback implementation an indication of when
to reset the flash context. Additionally, it allows for a validity check
between the total expected size downloaded and the actual size
downloaded. A simple implementation can check if the block context's
current downloaded blocks is equal to the expected block size in order
to determine if the flash context needs to be reset. This approach
seemed the simplest, and knowing the firmware block context can have
other purposes. This has been tested by accessing the block context
during the update in the block received callback and confirming that the
callback had information regarding the current downloaded bytes.

Fixes #16122

Signed-off-by: Kyle Sun <yaomon18@yahoo.com>
2020-04-09 16:48:45 +02:00
Peter Bigot abbd53ce1f net: lwm2m: correct return value in tlv put
The function calculates the number of octets put, but does not return
it.  Call sites check for non-zero values suggesting this is a bug.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 12.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot 687826e83e net: lwm2m: json: fix potential buffer overflow
Use the size of the target buffer as the maximum length when
formatting with snprintf.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 3.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Robert Lubos d2e7a7d0c7 net: lwm2m: Notify when it's safe to turn RX off
According to LWM2M specification, when Queue Mode is used, the LWM2M
client should keep the reciever on for specified time after sending A
CoAP message. This commit adds a new LWM2M event,
`LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF`, to facilitate the process by
notifying the application when it's safe to turn the receiver off.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:57:29 +02:00
Robert Lubos 842d4b220f net: lwm2m: Add option to register in UDP queue mode
Add Kconfig option to enable Queue Mode binding. With this option
enabled, the LWM2M client will register with `UQ` binding, instead of
`U`.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:57:29 +02:00
Ulf Magnusson eddd98f811 kconfig: Replace some single-symbol 'if's with 'depends on'
I think people might be reading differences into 'if' and 'depends on'
that aren't there, like maybe 'if' being needed to "hide" a symbol,
while 'depends on' just adds a dependency.

There are no differences between 'if' and 'depends on'. 'if' is just a
shorthand for 'depends on'. They work the same when it comes to creating
implicit menus too.

The way symbols get "hidden" is through their dependencies not being
satisfied ('if'/'depends on' get copied up as a dependency on the
prompt).

Since 'if' and 'depends on' are the same, an 'if' with just a single
symbol in it can be replaced with a 'depends on'. IMO, it's best to
avoid 'if' there as a style choice too, because it confuses people into
thinking there's deep Kconfig magic going on that requires 'if'.

Going for 'depends on' can also remove some nested 'if's, which
generates nicer symbol information and docs, because nested 'if's really
are so simple/dumb that they just add the dependencies from both 'if's
to all symbols within.

Replace a bunch of single-symbol 'if's with 'depends on' to despam the
Kconfig files a bit and make it clearer how things work. Also do some
other minor related dependency refactoring.

The replacement isn't complete. Will fix up the rest later. Splitting it
a bit to make it more manageable.

(Everything above is true for choices, menus, and comments as well.)

Detected by tweaking the Kconfiglib parsing code. It's impossible to
detect after parsing, because 'if' turns into 'depends on'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-02-08 08:32:42 -05:00
Martin Lesund e12757e9e9 net: lwm2m: implement utc_offset and timezone
Implemented UTC_OFFSET and TIMEZONE to device.

Signed-off-by: Martin Lesund <martin.lesund@nordicsemi.no>
2020-02-06 10:19:47 +02:00
Martí Bolívar caa06c9c48 net: lwm2m: add optional timestamp resources to some IPSO objects
Based on work by Michael Scott.

Add a new Kconfig knob, CONFIG_LWM2M_IPSO_TIMESTAMP_EXTENSIONS. This
defaults to n. When enabled, various IPSO objects will by default have
the timestamp resource (5518) added to their representations. This can
be turned off on a per-object basis.

The idea of adding timestamp resources was originally suggested by
Hannes Tschofenig on this OMA page:

https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/429

Signed-off-by: Michael Scott <mike@foundries.io>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2019-12-18 10:43:59 +02:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
Ulf Magnusson e9c460b3cc net: lwm2m: kconfig: Remove unused firmware pull port symbol
LWM2M_FIRMWARE_UPDATE_PULL_LOCAL_PORT is unused since commit 54c10c04e5
("net: lwm2m: use security data for connections").

Found with a script.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-18 15:31:02 +03:00
Ulf Magnusson a3db0e98c9 net: lwm2m: kconfig: Remove unused LWM2M_LOCAL_PORT symbol
Unused since commit d1cb39e7ce ("net: lwm2m: migrate LwM2M library to
BSD-sockets API").

Found with a script.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-18 10:36:00 +02:00
Robert Lubos 399f213227 net: lwm2m: Cleanup special handling of DNS for offloading
With `CONFIG_NET_NATIVE`, offloaded drivers can specify capabilites with
`NET_IPV4/6` configs, so there is no longer need to handle socket
offloading separately.

Also, initialize hints structure with zeros, as according to man pages
unused fields should be set to 0:
`All the other fields in the structure pointed to by hints must contain
either 0 or a NULL pointer, as appropriate.`

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-10-15 23:31:08 +03:00
Robert Lubos 000226ff54 net: lwm2m: Add config to enable DNS support
Add new config option `LWM2M_DNS_SUPPORT` to the LWM2M library, instead
of relying on `DNS_RESOLVER` which is only compatible with native
network stack. This allows to use DNS with offloaded interfaces
seamlessly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-10-15 23:31:08 +03:00
Marti Bolivar c311aa4675 net: lwm2m: fix printf warning
Cast a %lld argument to long long int. This is causing warnings on
recent GNU Arm Embedded toolchains, which fail the build with
-Werror=format=.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-09-23 22:29:12 +03:00
Jun Qing Zou ca783d72a6 net: lwm2m: support client-initiated De-register
Add new RD Client API of lwm2m_rd_client_stop() for this
Fix issues of de-register and event reporting in RD Client

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2019-09-08 12:36:33 +02:00
Jun Qing Zou 9103403308 net: lwm2m: support NET_SOCKETS_OFFLOAD in peer parsing
The LwM2M implementation for DNS resolving has checks which
configure hints based on whether IPv4 or IPv6 are enabled.
Neither of them need enabled if using NET_SOCKETS_OFFLOAD,
which then causes an error to be returned to due to
"hints.ai_family" not being set.

Also the offload API need to know when to free the allocated
"struct addrinfo" instead of calling free() generically,
thus let's use the freeaddrinfo() API for sockets which will
call into the offload API if needed.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18765

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2019-08-30 11:58:00 +02:00
Michael Scott 7841ebf312 net: lwm2m: firmware_pull: fix multiple last_block notifications
When the firmware_pull mechansim sends the callback to notify the
sample of a new firmware block, the user supplied buffer can be
smaller than the CoAP BLOCK_SIZE setting.  To handle this case,
we loop through the payload and fill the user supplied buffer with
smaller chunks.

Unfortunately, the last_block calculation is done outside this loop
which causes several callbacks (while in this loop) to have
last_block true.   Let's fix this by adding a small check to make
sure we're at the end of the current payload block before notifying
the user of a last_block.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16158

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-29 19:49:29 +02:00
Michael Scott 098f1c9bfa net: lwm2m: tlv: fix float32/64 sign handling
When val1 is 0, we need to handle a negative val2 value so that we
generate correct TLV value.

Example: val1 = 0, val2 = -500000 is equivalent to -0.5 decimal.
Currently we generate: 0.5 (losing the sign).

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott d52b5843c7 net: lwm2m: json: use plain text formatter for float32/64
Current JSON formatting for float32/64 is broken in a similar way as
plain text.  Let's use the newly fixed logic for plain text to
generate the float32/64 values in the JSON string.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott 404a4b8556 net: lwm2m: plain text: expose put_float32/64 functions
We can use the plain text float32/64 formatter for JSON as well, so
let's expose the put_float32/64 functions.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott cdcb33b75f net: lwm2m: plain text: fix float formatting
Formatting a float32/64 value for plain text is broken.
Example for 32bit: val1=0 and val2=500000 is equivalent to 0.5

Current formatter was using %d.%d (%lld.%lld for 64bit) so
exported value was 0.500000 (or 0.5)

To fix this, for val2 use a zero-padded formatter for the maximum
length of each bit length (6 for 32bit and 9 for 64bit), and then
remove the zero characters at the end of the string.

Notes re: handling of val1/val2 signs:
- eliminate potential negative sign when converting val2 to avoid:
  a value like: 0.-5
- use negative val2 when val1 is 0 to fix small negative handling
  such as -0.5

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott e743d89cdc net: lwm2m: add missing bootstrap-finish handling
When the bootstrap support was added, it looks like I somehow missed
the handling block in the engine.

Let's add it now to fix boostrap support.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18080

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-24 11:04:25 +02:00
Michael Scott 523123857c net: lwm2m: Kconfig: fixup default instance counts for bootstrap
- LWM2M_SECURITY_INSTANCE_COUNT wasn't following the standard of
  having the unconditional default in the last position
- LWM2M_SERVER_INSTANCE_COUNT needs another instance when
  bootstrap is enabled.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-24 11:04:25 +02:00
Michael Scott 1bc586da6f net: lwm2m: Kconfig: move RD_CLIENT settings above dependencies
LwM2M boostrap support is enabled via the config option:
LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP.  If enabled, this config sets
the default # of server and security instances.  However, this is
not working correctly because LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
is defined below it's uses in the Kconfig file.

Let's move the RD_CLIENT configs higher in the Kconfig to fix this
behavior.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-24 11:04:25 +02:00
Michael Scott 07f9e8beea net: lwm2m: fix IP address max calc in conn mon obj
When checking for total IP address counts, don't check
CONFIG_NET_IF_MAX_IPV6_COUNT twice.  This was a typo for
CONFIG_NET_IF_MAX_IPV4_COUNT.

This was reported by IRC user: retfie

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-09 23:22:13 +03:00
Michael Scott e81332d4bd net: lwm2m: cleanup memset usage during init
Several problems with memset usage in the LwM2M subsystem were
identified:
- Every single object that can have multiple instances is using
  memset to initialize static resource data during init.  This data
  will already be set to 0 because it is static, so the memset
  statements are unneeded.
- Instead of using memset during object init which is only called
  one time during kernel startup, let's add a memset to the
  object create function to ensure the resource data is cleared out.
  It could have been used prior and then released via a DELETE op.
- the IPSO Timer object was setting a lot of data structure members
  to 0 in the create function.  Let's do 1 memset on the entire
  structure and then only the non-zero values afterward.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 6af8fa692b net: lwm2m: add LwM2M path to engine_set errors
When presenting errors in lwm2m_engine_set() let's include the related
LwM2M path for easier debugging.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 3d3af7114e net: lwm2m: add IPSO Accelerometer object support
This IPSO object can be used to represent a 1-3 axis accelerometer.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 3e7d374cd2 net: lwm2m: add Location object support
This core LwM2M object provides a range of location telemetry related
information.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 9dc5e293f0 net: lwm2m: add Connection Monitoring object support
This core LwM2M Object enables monitoring of parameters related to
network connectivity.

This is only the basic object structure.  More work will be needed
to set the various resources based on connectivity.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ca61a238af net: lwm2m: add IPSO Push Button object support
This Object is used to report the state of a momentary action push
button control and to count the number of times the control has
been operated since the last observation.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 2019d49bf0 net: lwm2m: add IPSO On/Off Switch object support
This object is used with an On/Off switch to report it's state.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 4bf343d5d1 net: lwm2m: add IPSO Buzzer object support
The IPSO Buzzer object is used to represent a buzzer, beeper or
vibrating alarm.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 8817d930a8 net: lwm2m: rework resource instance storage / access methods
LwM2M allows for multiple instance resources such the power source
resources in the device object.  These types of resources have
always been very hard to work with, and frankly were poorly
implemented.

This led to other issues where it was very hard to have
non-sequential resource instances, and each resource of this type
needed special getter / setter methods such as:
lwm2m_device_add_pwrsrc()
lwm2m_device_set_pwrsrc_voltage_mv()

Going forward, as more LwM2M objects are implemented this just
doesn't scale well.

To fix this:
- split the resource instance data out from the resource data.
  This includes the data pointer information and resource
  instance id.
- add resource id and resource instance id to the event callback
  functions so user's can see in more detail what resources and
  resource instances are being handled.
- allow generic functions like lwm2m_engine_get_*() and
  lwm2m_engine_set_*() to access resource instance data.
- adjust object resource initialization  macros to map resource
  instances to resources at the time of object instance
  creation.
- fix up the lwm2m_client as a reflection of all of these changes.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 6a2f362357 net: lwm2m: remove lwm2m_engine_obj from most handlers/formatter OPs
Due to work combining data into the lwm2m_message structure, we no
longer need to pass the lwm2m_engine_obj parameter between
formatters and most of the operation handlers.

So, let's remove it.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ca308ec479 net: lwm2m: remove unique lwm2m_engine_obj_delete_cb_t definition
Instead, let's use lwm2m_engine_user_cb_t which is used elsewhere and
matches the same signature.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 30f31fb4e1 net: lwm2m: remove unused multi_max_count field from obj_field
The multi_max_count is no longer used and can be removed from the
obj_field structure if we change all of the OBJ_FIELD() macros to
use OBJ_FIELD_DATA() instead.

Technically, OBJ_FIELD() and OBJ_FIELD_DATA() are now the same, but
we're keeping them both for the time being.  In the future, more
fields may be added to the obj_field structure and we can use the
OBJ_FIELD() macro again if that's the case.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ad01c035b8 net: lwm2m: update function prototypes and descriptions
- Several of the functions use "path" as the parameter name for the
  string-based LwM2M path.  Let's clarify by using "pathstr".
- Recent updates to the LwM2M engine now support resource instances
  when parsing the LwM2M path.  Let's update descriptions accordingly.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 9534bbd991 net: lwm2m: add missing application type to IPSO Light Control
Per IPSO Light Control definition from the OMA LwM2M registry:
http://www.openmobilealliance.org/tech/profiles/lwm2m/3311.xml

There is an optional "Application Type" string resource (5750) in the
Light Control object.  This was missed in the initial implementation.

NOTE: sample will assign reference if needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott a33a6f7754 net: lwm2m: remove data storage for IPSO Timer application type
We are pre-allocating a storage variable for the application type
resource in the IPSO Timer object.  This is an optional resource
which won't always be set by samples.

Let's leave out the pre-allocated variable and let the sample set
this reference if needed (it's optional).

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott c0e313aae1 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>
2019-08-02 12:00:35 +03:00
Pieterjan Camerlynck d0dd1fbf5c net: lwm2m: cancel pending retransmit work when closing context
Currently the retransmit_work is not cancelled when closing a context,
making it operate on an invalid context.

LwM2M RD client also closes the context and initializes it again when
registration with the server fails, overwriting the active timeout and
breaking the timeout dlist.

Signed-off-by: Pieterjan Camerlynck <pieterjan.camerlynck@gmail.com>
2019-07-30 10:19:39 +03:00
Michael Scott e7155622a2 net: lwm2m: add custom TLS credential load function pointer
Current implementation of LwM2M engine doesn't allow users a way
of overriding TLS credential load with custom function.  This
would be needed by an offloaded TLS stack where we don't want
to use standard Zephyr functions.

Let's add a load_credential function pointer to the LwM2M client
context which will be called when it's available.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17408

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-11 11:08:05 +03:00
Michael Scott b5231d0b93 net: lwm2m: firmware: add log_strdup to remove logging errors
When performing OTA using the LwM2M subsys, several logging errors
regarding log_strdup were noted.  Let's fix these.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:09:22 +03:00
Michael Scott 13086ccda8 net: lwm2m: dont select MBEDTLS or set MBEDTLS options in subsys
If a sample wants to use the Zephyr implementation of mbedtls, it
enables CONFIG_MBEDTLS and sets any needed Zephyr-specific mbedtls
options.

Currently, the LwM2M subsystem selects MBEDTLS automatically when
LWM2M_DTLS_SUPPORT is enabled.  Let's remove this and let the
LwM2M client sample enable mbedtls and it's options.

This mimics the behavior of several other network-related samples
and removes conflicts when selecting alternate implementations of
MBEDTLS.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17399

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:08:47 +03:00
Michael Scott 82e889a2e2 net: lwm2m: fix error message in load_tls_credential()
Copy/paste issue was showing the wrong error message when a TLS
credential failed to be added.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:08:30 +03:00
Michael Scott 88642ef2eb net: lwm2m: remove IP CONFIG checks in lwm2m_parse_peerinfo()
CONFIG_NET_IPV* checks are not needed in lwm2m_parse_peerinfo().
The functions used are always available.  Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17401

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:07:58 +03:00
Michael Scott 05cc5ae92c net: lwm2m: remove IP CONFIG checks in lwm2m_sprint_ip_addr()
CONFIG_NET_IPV* checks are not needed in lwm2m_sprint_ip_addr().  The
functions used are always available.  Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).

NOTE: Also fixes an issue where a NULL is returned when the IP address
is unknown.  This usually ends up with a crash/abort in the logging
code.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17401

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:07:58 +03:00
Robert Lubos c37faaa56d net: lwm2m: Ignore close return value
Explicitly ignore return value from `close` call.

Coverity-CID: 198870

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-07-08 21:40:15 +03:00
Pieterjan Camerlynck b7d4b0057e net: lwm2m: fix automatic notification frequency
This fixes the issue where observations are automatically reported using
the minimum period instead of the maximum. This causes notifications to
be sent more frequently than configured when the resource does not
change.

Signed-off-by: Pieterjan Camerlynck <pieterjan.camerlynck@gmail.com>
2019-07-01 10:36:33 +03:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Michael Scott a46db55d0a net: lwm2m: fix log_strdup missing errors
Due to commit a211afb0 ("logging: Add option to detect missed
transient string duplication"), the logs for LwM2M subsystem
is now spamming missing log_strdup() calls.

Let's add log_strdup() where needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-05-30 11:26:43 +08:00
Louis Dupont a8fffca40f net: lwm2m: Remove IPSO objects maximum number of instances limitation.
Fixes #16156 by removing kconfig maximum number of instances.

Signed-off-by: Louis Dupont <dupont.louis@ireq.ca>
2019-05-25 17:57:56 -04:00
Sebastian Bøe c2c8c849b6 cmake: Don't have users call zephyr_link_interface on mbedTLS
Libraries that use mbedTLS have been invoking
zephyr_link_interface(mbedTLS). It is not clear what the intent of
this code has been, but it is redundant with the mbedTLS build
scripts, so it can be safely removed.

In addition to being redundant, it causes problems as it introduces an
ordering dependency, with this code mbedTLS must be declared before
users of mbedTLS are declared. Since this code is redundant, this
ordering dependency is also unnecessary.

This code is believed to have been added early on by accident and
copied through cargo-cult programming since.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-05-11 08:35:26 -04:00
Michael Scott cb2bfcb9c0 net: lwm2m: fix periodic services handling
This fixes an issue where if timestamp == service_due_timestamp,
we don't call the periodic service.  Then the following call to
engine_next_service_timeout_ms() returns 0 because the service
is still due and lwm2m_engine_service() is called again.
This process repeats several times until the value of
k_uptime_get() changes and then the work is finally handled.

Previously, the resolution of k_uptime_get() was in ms.  A recent
change to this API defaults Zephyr so that the resolution is
set via CONFIG_SYS_CLOCK_TICKS_PER_SEC (default 100).

This means the value of k_uptime_get() only changes every 10ms.

Reported-by: Github User pieterjanc
Signed-off-by: Michael Scott <mike@foundries.io>
2019-04-10 13:54:23 -04:00
Michael Scott 42abfc6532 net: lwm2m: dont use system workqueue for services
"It's a Trap!" -- Admiral Ackbar

When moving to the BSD-socket APIs, the original thread running LwM2M
periodic services such as observes and lifetime updates, was replaced
with a re-occuring workqueue job.  To save the overhead of creating a
new thread, I used the system workqueue for these jobs.

This was a mistake.  If these jobs hit a semaphore or wait for some
reason, it cannot be prempted due to the priority of the system work
queue.

Let's instead add this service handling to the thread that we already
use for polling sockets.  This also removes a configuration issue where
the system workqueue stack size needed to be increased.  This can now
be adjusted via the LWM2M_ENGINE_STACK_SIZE knob.

Directly fixes semaphore usage in the socket-based DNS code.
This was introduced as a bugfix for non-responsive DNS server hanging
the Zephyr device forever.  However, this probably fixes randomly
seeming hangs on the device.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-04-10 13:54:23 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Michael Scott 8c615e7ce3 net: lwm2m: handle delay_work error in lwm2m_engine_init()
Let's handle errors during periodic service work submit.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 579e586fa1 net: lwm2m: fix write_handler sizes for float32/64
Normally, this bug wasn't apparent as the value is type-casted
to a float32/64 type.  However, once we start persisting these
values they need the correct length.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 910506cfc1 net: lwm2m: guard obj_field parameter of LWM2M_HAS_PERM
Let's avoid future compile issues with this macro when passing
in a type-casted value that isn't surrounded by parenthesis.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott fcde4c42cc net: lwm2m: raise stack sizes
Occasionally we see a stack crash in LwM2M.  This may have been
due to the swap from net_app APIs to socket-based APIs.

Let's raise the default stack by 1k.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott d615ab0dc3 net: lwm2m: change resend packet to an INF message
To avoid missing important messages, let's change the resend
packet message from a DBG to an INF.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 144ff91670 net: lwm2m: cleanup observes when closing context
When a context is closed to a server, we should clean up any
existing observes along with it.  Otherwise these will try to fire
afterward.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 35eb7818a7 net: lwm2m: remove unnecessary check in sm_do_registration()
We are already in sm_do_registration(), there's no need to check
!sm_is_registered().  Either we are performing a full registration
or a registration update.  In both cases, sm_send_registration()
is called.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott a5a83675d4 net: lwm2m: correct status change on send_reg error
If an error is received during registration update, we need to reset
the status so that a full registration is performed.  This was
incorrectly being set to ENGINE_REGISTRATION_SENT.

The correct status should be: ENGINE_DO_REGISTRATION

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 2ab50cb676 net: lwm2m: Follow POSIX send() API
send() returns -1 upon error and sets errno appropriately.  Let's
not bother saving the return code and instead share errno back
to the user.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Kumar Gala 0033448f10 net: lwm2m: Fix minor bug with setting flags
Looks like we are setting some bit flags so we should use '|' not '||'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 16:28:58 -05:00
Ulf Magnusson 214ef00db3 kconfig: subsys: net: Remove redundant dependencies
subsys/net/lib/lwm2m/Kconfig.ipso is 'source'd within an 'if LWM2M', in
subsys/net/lib/lwm2m/Kconfig, so the 'depends on LWM2M' is redundant.

The 'depends on NET_IPV4' and 'depends on NET_L2_OPENTHREAD' are within
corresponding 'if's in the same file.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 09:49:59 -05:00
Michael Scott 0482b66f0b net: lwm2m: fix json NULL deref / code flow in read_number()
Per Coverity report, we are assigning the value1 and value2
s64_t pointers a value of 0.  Later when we go to use value1
and value2, they are of course ... NULL.

Fix the typos in the initial assignment of 0 to the
references of value1 and value2.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/13867
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/13882

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-01 09:44:46 +01:00
Michael Scott cc1b6b024b net: lwm2m: fix json formatter putchar check
Found via Coverity CID 191001: Control flow issues  (NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true:
"put_char(out, '}') < 0U".

Let's fix this check to be less than 1 instead as it should have
been originally.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-27 08:36:12 -06:00
Michael Scott f68d62bbdb net: lwm2m: fix float exponent after fraction assign
Once the fraction value has been assigned a value, we can't move
the exponent any more.

Fixes erroneous values the binary32/64 formats.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-26 01:45:51 +01:00
Robert Lubos f8502a9993 net: lwm2m: Remove misused errno check
Errno value is only significant when `recvfrom` function indicated an
error (by returning -1). We should not depend on it's value if no error
is notified.

As the return value of `recvfrom` is already checked, misused errno
verification can simply be removed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Michael Scott 844c2ad716 net: lwm2m: fix NULL deref in plain_text_read_number()
Per Coverity report, we are assigning the value1 and value2
s64_t pointers a value of 0.  Later when we go to use value1
and value2, they are of course ... NULL.

Fix the typos in the initial assignment of 0 to the
references of value1 and value2.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12300
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12296

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott f6b221699c net: lwm2m: fix out-of-bounds access in put_s8()
Per Coverity report, oma_tlv_put() does pointer arithmetic accessing
the data as an array of u8_t.  In put_bool() we get a singleton
pointer from the evaluation of: "value != 0 ? 1 : 0" which is
passed to put_s8() which in turn passes it to oma_tlv_put().

To avoid misinterpretation, let's create a temporary s8_t variable
to pass into oma_tlv_put instead.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12312

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott 95f21d59b7 net: lwm2m: remove checks for long int > MAX_INT
Per Coverity report, the evaluation of long int v > MAX_INT is
always false and considered a CONSTANT_EXPRESS_RESULT issue.

Removed these checks from:
atof32()
lwm2m_write_attr_handler()

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12317
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12320

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott 91ef79539a net: lwm2m: fix rendering of zero value float32/64
Zero is a special value in the binary32/64 format.  It has all zero
bits (sign=0, exponent=0 and fraction=0).

Handle this special case explicitly instead of trying to encode
in binary format which results in an incorrect value of 0.5.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 07:00:33 -06:00
Michael Scott cf47c89971 net: lwm2m: add support for IPSO Timer object
Initial implementation of IPSO Timer object #3340
Based on: http://www.openmobilealliance.org/tech/profiles/lwm2m/3340.xml

"This IPSO object is used to time events and actions, using patterns
common to industrial timers. A POST to the trigger resource or On/Off
input state change starts the timing operation, and the timer
remaining time shows zero when the operation is complete. The
patterns supported are One-Shot (mode 1), On-Time or Interval
(mode 2), Time delay on pick-up or TDPU (tmode 3), and Time Delay
on Drop-Out or TDDO (mode 4). Mode 0 disables the timer, so the output
follows the input with no delay. A counter is provided to count
occurrences of the timer output changing from 0 to 1. Writing a value
of zero resets the counter. The Digital Input State resource reports
the state of the timer output."

NOTE: Only One-Shot Mode (mode 1) is implemented in this patch.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-12 21:19:49 -05:00
Michael Scott d53a0855a1 net: lwm2m: fix float32/64 handling
During the initial work on LwM2M, the float32/64 code was
basically stubbed out.  Float32 sent only whole values and
float64 was completely broken.

Let's clean up the OMA TLV formatting code by moving the float
processing code into a separate file: lwm2m_util.c.

Then using public definitions for binary32 and binary64, let's
fix the processing code to correctly fill the float32_value_t
and float64_value_t types.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-12 21:19:49 -05:00
Michael Scott 6cb768cb24 net: lwm2m: fix connection handling in RD client
A few cases were missed where we weren't cleaning up the existing
connection correctly.  This was easily missed because we try and
clean up the connection everywhere.

Instead, let's clean up any existing connection prior to starting
a new one in the do_bootstrap_reg() and do_registration()
functions.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-06 18:52:31 -05:00
Michael Scott 6b990ba9bf net: lwm2m: boostrap support cleanup
- Fix enum naming throughout
- Correct next_instance logic
- Move to registration server if no bootstrap server is found
- Fixes to logging

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-06 18:52:31 -05:00
Ravi kumar Veeramally 1e47f26d1c net: coap: Remove legacy CoAP implementation
As we are removing net_app and net_pkt based libraries and
applications, CoAP legacy based libraries and apps are moved
to socket based implementations. So removing legacy CoAP.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-04 16:49:59 -05:00
Michael Scott a79087cad1 net: lwm2m: add socket-based DNS support
Previously, the net_app layer handled DNS support as a part of
network initialization.  With the move to BSD-socket APIs,
we need to add support for DNS to the LwM2M library.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d1cb39e7ce net: lwm2m: migrate LwM2M library to BSD-sockets API
This commit removes the net_app layer from the LwM2M library and
replaces it with BSD-sockets APIs.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d7f20f63d8 net: lwm2m: fix firmware status after bad download attempts
This commit resets the firmware status to IDLE after a bad
download attempt.  Previously, the firmware object would stay
in an odd state and any further attempts to download firmware
would return an error.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 0abe96e4cf net: lwm2m: replace periodic service thread with work queue
We can save some resources by removing the periodic service thread
and replacing it by queuing the services to the work queue.

Before (reel_board using BT + DTLS)
Memory region         Used Size  Region Size  %age Used
           FLASH:      289464 B         1 MB     27.61%
            SRAM:       75620 B       256 KB     28.85%
        IDT_LIST:         136 B         2 KB      6.64%

After
Memory region         Used Size  Region Size  %age Used
           FLASH:      289576 B         1 MB     27.62%
            SRAM:       74596 B       256 KB     28.46%
        IDT_LIST:         136 B         2 KB      6.64%

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 180a365d2f net: lwm2m: support for LwM2M bootstrap
Now that the security data can be loaded into and used from the
security / server objects, we can add support for LwM2M bootstrap.

This is a mode where initially a connection can be made to a server
which can update several LwM2M (including security and server
data) and then trigger a "bootstrap complete".  Once this happens
the client will start it's connection process over but now with
the new information.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 54c10c04e5 net: lwm2m: use security data for connections
In order to support bootstrap mode, we need to store server data
in the security / server objects.  Once the connection to the
bootstrap server is made, it will clear these objects and add
new server connection data.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 3ef993c88e net: lwm2m: update security obj with DTLS data
For bootstrap support, we need to store connection credentials
in the security object.  This way the client can start a connection
at index 0 and after bootstrapping, move to the next connection.

Let's add the needed fields and a config item to set the key length.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 181544beec net: lwm2m: add JSON formatter for WRITE operations
Update the parsing functions for JSON used by the JSON data
formatter and enable it in the LwM2M engine.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 26599e30d4 net: lwm2m: introduce input formatter private data
The JSON formatter is currently not enabled for incoming WRITE
operations.  To update the code in the formatter and not litter
the input context with extra data, let's allow formatters to
store their own user data.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott a433af6e05 net: lwm2m: save remote address during setup
net_app contexts save the remote address and we use this during
observe notifications and pending handling.  If we move to another
network layer such as sockets, then the remote address becomes
harder to reference.  Let's save it as a part of the client
context.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 3bfb7debb3 net: lwm2m: move to flat buffers
As part of the migration from net_app APIs to socket APIs, let's
stop referencing the net_pkt fragments throughout the LwM2M library.

Establish a msg_data flat buffer inside lwm2m_message and use that
instead.

NOTE: As a part of this change we remove the COAP_NET_PKT setting.
The COAP library reverts to COAP_SOCK behavior.

This doesn't mean we use sockets in LwM2M (yet), it only means we
use the socket-compatible COAP library which parses flat buffers
instead of net_pkt fragments.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d003910460 net: lwm2m: create DTLS config layer for LwM2M
Currently, this will select the needed configs for LwM2M and net_pkt.
During the migration to socket APIs, the net_pkt selections will change
to socket-based selects.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 8a115ca556 net: lwm2m: remove some unnecessary includes
net/lwm2m.h is included by object.h

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 44e9b5ed44 net: lwm2m: refactor lwm2m_engine_context into lwm2m_message
The relationship between lwm2m_engine_context and lwm2m_message
has always been a tenuous one.  Let's merge the 2 structures
into lwm2m_message and remove all of the extra stack variables.

This change increases SRAM usage slightly due to the
addition of the context structures to the multiple lwm2m_messages.
However, the way lwm2m_engine_context was being used off the stack
was probably creating hard to debug issues in the longterm.

Also, having all of the structures in 1 place makes sharing them
much easier later.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 86728d849b net: lwm2m: fix unsigned check for <0 in LwM2M device obj
Reported by Github user himanshujha199640 using coccinelle:
subsys/net/lib/lwm2m/lwm2m_obj_device.c:172:5-16:
WARNING: Unsigned expression compared with zero.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/11135

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 0ee0773abd net: lwm2m: remove unused CONFIG_NET_CONTEXT_NET_PKT_POOL config
CONFIG_NET_CONTEXT_NET_PKT_POOL is used by Zephyr's TCP stack as
a way of keeping the original packet data when compression and
other l2 specific actions make the data unusable for retries.

LwM2M uses UDP and this option was never used.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Himanshu Jha 36279b69a8 net: lwm2m: ipso_temp_sensor: remove unnecessary variable
Remove an unnecessary local variable to store the
return value, instead return directly thereby saving
few bits of memory.

Found using Coccinelle.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 11:54:01 -08:00
Himanshu Jha a273cfaf32 net: lwm2m: ipso_light_control: remove unnecessary variable
Remove an unnecessary local variable to store the
return value, instead return directly thereby saving
few bits of memory.

Found using Coccinelle.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 11:54:01 -08:00
Anas Nashif 3d906dc4c1 net: coap: Move both CoAP implementations into one Kconfig
Two separate folders and Kconfig options causing confusion on
CoAP and CoAP_SOCK implementations. This patch simplifies it.
Current CoAP Kconfig option moved to COAP_NET_PKT.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-22 09:08:46 -05:00
Michael Scott 70b9e7bab6 net: lwm2m: handle pending before send in retransmit
When resending data, we need to always check pending status first.
If the pending check returns an "expired" status, avoid sending the
data to L2 network driver entirely.

This change fixes a use after free issue, where the L2 network driver
was still handling a packet that was expired out from under it when
the pending status was checked.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 144cfce42a net: lwm2m: firmware_pull: don't use pending pkt for token
During firmware transmit timeout, we rely on the pending packet data to
reconstitute the token and token length.  At this point the pending
structure may be cleared out due to multiple retries.  To avoid getting
a zero token, let's use the token data from the original msg structure
instead.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 64c03819ec net: lwm2m: don't use pending pkt on retransmit error
We are using msg->cpkt.pkt as the net_pkt pointer in the call to
net_app_send_pkt().  Let's keep the code clean and not expose
ourselves to "out of order" issues, by also using msg->cpkt.pkt
in the error handling unref call.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 547e449f98 net: lwm2m: remove extra ref/unref in retransmit
During the retransmit cycle we take ref on the outgoing packet,
only to immediately unref it.  Originally, this was to make sure
the net_context handling didn't get rid of the packet when
sendto() is called.  But after checking, the ref counter is never
in danger of going to 0 at this point in the code, so the
added ref handling is useless.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Marti Bolivar 1cd137c393 net: lwm2m: increase IPSO light object color size
Add some extra space to the color resource buffer, to allow more
exotic and application-specific color spaces.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 263dab3eda net: lwm2m: fix compile warning related to Logger changes
When DBG level for CONFIG_LWM2M_LOG_LEVEL is disabled, a compiler
warning is generated:
In file included from include/logging/log.h:11:0,
                 from subsys/net/lib/lwm2m/lwm2m_engine.c:28:
subsys/net/lib/lwm2m/lwm2m_engine.c: In function ‘engine_add_observer’:
subsys/net/lib/lwm2m/lwm2m_engine.c:558:3: warning: implicit
declaration of function ‘sprint_token’
[-Wimplicit-function-declaration]
   sprint_token(token, tkl), lwm2m_sprint_ip_addr(addr));
   ^

Let's remove the #if guards around sprint_token() and let
the Linker remove it when not needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-19 17:32:36 -04:00
Paul Sokolovsky cdeddee7c6 net: Set names for threads used by the network subsys/libs
Previously, these either used generic names like "workqueue" (so,
it wasn't possible to distiguish tx and rx workqueues) or didn't
set for net management thread. Here's an example of thread dump
in a typical system (using stack_analyze() call):

rx_workq (real size 4092):	unused 3696	usage 396 / 4092 (9 %)
tx_workq (real size 4092):	unused 3692	usage 400 / 4092 (9 %)
net_mgmt (real size 4092):	unused 3772	usage 320 / 4092 (7 %)
sysworkq (real size 4092):	unused 3512	usage 580 / 4092 (14 %)
idle (real size 252):	unused 64	usage 188 / 252 (74 %)
main (real size 4732):	unused 3672	usage 1060 / 4732 (22 %)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-19 07:58:45 -04:00
Jukka Rissanen 009e4dafa7 net: Make Kconfig template variables prettier
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 09:01:37 -04:00
Jukka Rissanen 5705573c46 net: lwm2m: Convert to new logging system
Use new logging system instead of SYS_LOG.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Michael Scott d30f2abbe4 net: lwm2m: fix formatter reader/writer initialization syntax
For ease of maintenance, let's swap the reader/writer initialization
syntax to:
.put_begin = put_begin,
.put_end = put_end,
...

This way we only assign used fields and adding new ones later is
less error prone.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott e42611615c net: lwm2m: in oma_tlv_put don't re-add value when insert is true
We set "insert" to true when the value is already in the buffer, but
we need to insert a TLV to denote things like RESOURCE_INSTANCE or
OBJECT_INSTANCE.  In this case, let's not re-add the value.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 7345023dc8 net: lwm2m: TLV: mark object instance boundry when needed
Let's implement put_begin/end_oi functions in the TLV formatter
so to mark the boundry of an object instance when more than 1
object instance is returned.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/9470

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4ba194942a net: lwm2m: refactor put_begin_ri/put_end_ri into generic functions
In order to re-use the put_begin_ri / put_end_ri logic, let's create
generic functions for them: put_begin_tlv and put_end_tlv

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 24e63f1295 net: lwm2m: implement begin/end processing for obj inst and resources
Implement put_begin/end calls for object instance and resource
processing in lwm2m_perform_read_op()

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 90b0986be8 net: lwm2m: store a backup of the entire path in perform_read_op
Currently, we only save the resource id of the incoming path setting.
In the future, we will need to change other values in order to process
multi-instance READ operations.

Let's save and restore the entire path only at the beginning and end
of processing.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 3d2c1b7d72 net: lwm2m: introduce put_begin/end for object instance and resources
Data formatters may need to process data at the beginning and end of
each object instance and/or resource.  Currently, they can only add
processing at the beginning and end of resource instances.

Let's establish put_begin/end_oi (object instance) and put_begin/end_r
(resource) API functions that data formatters can use for this purpose.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 019b24f16a net: lwm2m: optimize lwm2m_perform_read_op()
Optimize the resource processing loop to avoid extra
assignments before checking if we need to process the
actual resource.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 0561887bcb net: lwm2m: fix JSON format for multi-instance reads
When reading multiple instances, the base name value should not
include an object instance id.  The object instance id is added
to the individual resource name values.

Accomplish this by saving the original path level and adjusting
the (base) name where needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 658cb19339 net: lwm2m: correct placement of put_begin/put_end in READ op
The put_begin / put_end calls are to be used at the very beginning
and end of processing a READ op.  Let's correct that logic.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 1821c27462 net: lwm2m: optimize variable order in lwm2m_perform_read_op()
Let's sort by largest to smallest so that we don't leave odd gaps
in memory.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott f21b20550c net: lwm2m: remove unused members from lwm2m_output_context
Now that formatters use their own private data to hold state,
let's remove the old member variables from lwm2m_output_context
which are now unused.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4a344e7d0f net: lwm2m: tlv formatter use private data
Use newly introduced private data pointer in output context to
store TLV formatter information.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4fb29949af net: lwm2m: json formatter use private data
Use newly introduced private data pointer in output context to
store JSON formatter information.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott fff8422f60 net: lwm2m: introduce output context user_data
Data formatters have various private state variables which are
currently located in the output context structure.  Let's add
a place where data formatters can store a pointer to their
private data so that as we add more formatters the output
context doesn't get cluttered up.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott a4001f02b0 net: lwm2m: plain-text: process only reads for a specific resource
The plain-text format only supports READ op for a specific resource.
In all other cases return NOT_ALLOWED.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00