Commit graph

831 commits

Author SHA1 Message Date
Juha Heiskanen ad5492721a net: lwm2m: Fixed crash at LwM2M registration timeout
LwM2M context close moved to thread safe place when RD client
run state machine.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-07-05 14:19:24 +02:00
Ola Tangen Kulseng 9be4fd0bbb net: lwm2m: Refactor of engine, message handling
Created the file lwm2m_message_handling.c, to include all
code pertaining to CoAP and allocation and deletion of messages
in general.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-05 13:50:26 +02:00
Ola Tangen Kulseng 365efa0f6a net: lwm2m: Refactoring of engine, observation
Created the file lwm2m_observation.c, to include
all code maintaining observations and parameter handling.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-05 13:50:26 +02:00
Ola Tangen Kulseng 02fed0b22e net: lwm2m: Refactoring of lwm2m_engine.c
Created the file lwm2m_registry.c to include the
getters and setters of values and the creation
and deletion of all lwm2m objects, resources
and instances. Refactored the registry part
of lwm2m_engine.h into lwm2m_registry.h.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-07-05 13:50:26 +02:00
Veijo Pesonen 94b81664e4 net: lwm2m: default stack size with SenML CBOR
SenML CBOR data is stored statically in RAM and does not use process
stack.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-07-04 16:20:03 +02:00
Øyvind Rønningstad c1a9866c86 west.yml: Update zcbor to v. 0.5.1
lwm2m: Regenerate lwm2m_senml code from the CDDL description.
Reapply manual changes.
Create a sh script to perform the regeneration.

tests: zcbor_bulk: Adapt to zcbor 0.5.1
zcbor_new_decode_state() now has no return value.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2022-07-04 15:13:42 +02:00
Veijo Pesonen 9bf570eaba net: lwm2m: Fixes SenML CBOR composite read
Path list was replaced accidentally with free list during refactoring.
This change does fix the issue.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-29 10:29:27 +02:00
Andrei Emeltchenko ce76beecc3 net: lwm2m: Remove unused variable
Remove unused variable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-23 15:43:59 -05:00
Krzysztof Chruscinski 041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Ola Tangen Kulseng 38628f409e net: lwm2m: Add LwM2M shell commands for start&stop
Added start, stop and update to the shell.
Refactored the event_cb of the rd_client_info struct into the ctx,
as it was needed in the shell script.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-06-22 12:17:52 +02:00
Ola Tangen Kulseng 3e50624e39 net: lwm2m: Added commands to the lwm2m_client shell
Added read, write and execute commands to the shell.

Signed-off-by: Ola Tangen Kulseng <ola.kulseng@nordicsemi.no>
2022-06-22 12:17:52 +02:00
Juha Heiskanen 6d42ded565 net: lwm2m: LwM2M message allocation update
Allocated own message buffer for RD client interface.
This helps to cover if all messages are queued and need to do
registration or update.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
(cherry picked from commit 8dca91109d73a4a697e074c58ee9430d56c01a51)
2022-06-20 09:13:41 -04:00
Juha Heiskanen ad1960625a net: lwm2m: Fix Possible Notification send blocker
If Notification build fail there was possible that Notification
are blocked after failure.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
(cherry picked from commit 6dfa242c7d891b3458ab88df46b69b3a9621ee82)
2022-06-20 09:13:41 -04:00
Juha Heiskanen e4ce689de2 net: lwm2m: Coap Pending clear update
Fixed couple possible place for leak Coap pending entry.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
(cherry picked from commit 3c175951383be56fa9c1451845a15b66df41ff64)
2022-06-20 09:13:41 -04:00
Seppo Takalo 4a8efbb1bc net: lwm2m: Allow longer lifetimes than uint16_t
Lifetimes are really 32 bit values, so the limitation
did not make sense, and it did not allow 24 hour lifetime.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-06-20 10:25:41 +02:00
Veijo Pesonen fbef82c9c0 net: lwm2m: SenML JSON bootstrap exceptions
In bootstrap mode write to a non-exisisting optinal resource must not
cause an error.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen a5eae6f898 net: lwm2m: adds preferred content...
...format to bootstrap registration message with LwM2M v1.1.

SenML CBOR takes precedence, followed by SenML JSON and OMA TLV.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen db602fd81d net: lwm2m: Missing optional resource does not ...
...trigger write to the error log

Uses debug-level instead.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen 7f54aea934 net: lwm2m: SenML CBOR opaque write fixed
Write to an opaque resource failed and it has been fixed. Support for
blockwise transfer is still missing.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Veijo Pesonen 4177aa21ec net: lwm2m: SenML CBOR bootstrap exceptions
In bootstrap mode write to a non-exisisting optinal resource must not
cause an error.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-06-14 09:31:23 +02:00
Andrei Emeltchenko 766358461c net: lwm2m: Fix NULL pointer dereference
It does make sense to goto to cleanup part.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-10 09:47:05 +02:00
Markus Rekdal 3d8f938929 net: lwm2m: Fix range of integers in SenML CBOR
This fixes a minor bug that caused an error if one attempted to encode
or decode INT64_MIN in SenML CBOR

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-09 11:32:01 +02:00
Markus Rekdal 0006f2c93e net: lwm2m: Fix decoding of objlnk in SenML CBOR
This fixes a bug in the decoding of objlinks. Without this the object
instance id is not retrieved correctly as it tries to read the second id
starting from the colon.

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-09 11:32:01 +02:00
Seppo Takalo e0296ca0b9 net: lwm2m: Allow initializing opaque and string data to zero length
By default, any string or opaque data that LwM2M engine initializes
sets data lenght to same value as given buffer length for that
resource.

However, on run time, engine keeps track how much data is written
to each resource, so when reading from any resource, should only
return data that has been written there. But uninitialized resources
return the content of the whole buffer.

Fixed the problem by introducing macros INIT_OBJ_RES_LEN(),
INIT_OBJ_RES_MULTI_DATA_LEN() and INIT_OBJ_RES_DATA_LEN() that
allows you to give the amount of data existing in buffer when
the resource is initialized. This sets the data_len and max_data_len
variables correctly.

Also introduced new functions lwm2m_engine_get_res_buf() and
lwm2m_engine_set_res_buf() that distinct between data size and
buffer size. Deprecated the previous functions
lwm2m_engine_get_res_data() and lwm2m_engine_set_res_data()

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2022-06-09 11:30:37 +02:00
Juha Heiskanen 7ffc95c430 net: lwm2m: Composite Observation refactor
Json library parser modify data so thats why we can't parse same
data again. Now Composite observation handler parse SenML Json or
CBOR resource path which is given to new API composite Read API
which not need any new data parser.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-06-06 12:06:43 +02:00
Juha Heiskanen 2da8df8b7e net: lwm2m: Integrate JSON lib to LwM2M 1.0 JSON
Integrated updated JSON library to LwM2M 1.0 JSON.
Removed Old Json format default choice.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-06-06 12:06:43 +02:00
Juha Heiskanen a9035ebe5e net: lwm2m: Integrate JSON lib to SenML-JSON
Integrated updated JSON library to SenML-JSON.
This integrate affect that Coap Block wise transfer is not
supported.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-06-06 12:06:43 +02:00
Markus Rekdal cf43c49b5f net: lwm2m: Fix decoding of objlnk
This fixes a bug in the decoding of objlinks. Without  this the object
instance id is not retrieved correctly as it tries to read the second id
starting from the colon.

Signed-off-by: Markus Rekdal <markus.rekdal@nordicsemi.no>
2022-06-05 14:27:39 +02:00
Ryan Erickson 67598965fb lwm2m: software management: Fix URI value not being written
Create the URI resource when creating the object if
PULL support is enabled.

URI write callback should be post-write instead to ensure
the URI value is updated for the resource.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-05-27 15:45:14 -07:00
Marc Lasch fa84da588d net: lib: lwm2m: Cancel firmware DOWNLOADED state with NULL byte
Allow to cancel a firmware update in DOWNLOADED state by writing a
NULL byte as described in the Firmware Update object version 1.1
(urn:oma:lwm2m:oma:5:1.1). Keep object version 1.0 mechanism with
an `empty string`.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2022-05-23 10:17:52 +02:00
Veijo Pesonen b18f93dbc4 net: lwm2m: Fix SenML CBOR input basename length
Server might send the whole path in the basename when doing composite
write.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-05-13 10:15:27 -05:00
Veijo Pesonen 082fe9733c net: lwm2m: Adds missing SenML CBOR range check
Adds a check that number of records to be encoded does not exceed the
maximum limit configured through Kconfig.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-05-13 10:15:27 -05:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Juha Heiskanen 9b7a36099f net: lwm2m: LwM2M timeout recovery
LwM2M engine is blocking new notification send.
Notification or Send timeout trig Reconnect and registration state.
Send/Notification  message is blocked if client is not connected.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-05-04 09:50:28 -05:00
Jarno Lamsa ffa222725d net: lib: lwm2m: Don't create server object in bootstrap
When bootstrap is used, the server object shouldn't be autocreated.
Automatically creating object may cause problems after bootstrap
has been done and bootstrap server deletes and creates instances
for server object. In the next boot the auto-created server object
may have clashing server_id with the server object that the
bootstrap-server has created.
Also lifetime wasn't properly added to the registration message from
the server object.

Signed-off-by: Jarno Lamsa <jarno.lamsa@nordicsemi.no>
2022-05-04 09:46:10 -05:00
Juha Heiskanen 3bf30ef292 net: lwm2m: LwM2M RD client start and stop update
Added return code for for lwm2m_rd_client_start() & lwm2m_rd_client_stop().

lwm2m_rd_client_start() return -EINPROGRESS when start is in progress and
0 for success.

lwm2m_rd_client_stop() return -EPERM when context is unknown and
0 for success.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-05-04 09:44:29 -05:00
Veijo Pesonen d8b7449b52 net: lwm2m: SenML CBOR key ordering
Keys' order - bn, n - might differ from the default due to
Length-First Map Key Ordering rules.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen 975d170792 net: lwm2m: use stack for SenML CBOR data
Formatter data are is shared between different threads.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen a1bd90646e net: lwm2m: adds README
Includes instructions for generating the SenML CBOR encoder and
decoder.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen 98b22a1850 net: lwm2m: SenML CBOR optimisations
Regenerates the encoder and decoder. Treats integers and floating-point
values as separate entities instead of saying that those are numerical
values. Brings some memory savings.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen b78dd2498a net: lwm2m: Sets ct to registration msg
Tells the server which content format is preferred in a registration
message.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen 4f76b194a4 net: lwm2m: empty CBOR array support
Makes possible to write an empty CBOR array if there are no SenML CBOR
records that needs to be written. This came up when trying to delete a
portfolio object instance.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen 60eaafe293 net: lwm2m: SenML CBOR gencode adaption
Generated code needs some modifications for it to work correctly.

Adds license information.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Veijo Pesonen 0562de9fbe net: lwm2m: SenML CBOR RW support
* LwM2M v1.1 SenML CBOR content format support.
* Composite operations
* SEND functionality

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-29 16:10:43 +02:00
Juha Heiskanen 1b10f8345e net: lwm2m: LwM2M RD client registration update failure fix
Client jump to full registration state if registration update fail.
Update keep already opened DTLS session.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-29 08:57:30 +02:00
Juha Heiskanen f20eeebbd1 net: lwm2m: DTLS session cache enable and queue mode update
Enabled DTLS session cache for support session resume.
Fixed LwM2M queue mode for close connection and reconnect automatically.
Re-connect will do Registration update before it send queued data.
Session resume is helping a case when NAT change address and cause less
network traffic.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-29 08:57:30 +02:00
Veijo Pesonen cfcc891d3d net: lwm2m: makes CBOR as one of the default...
...content formats

In case that SenML CBOR or SenML JSON are both disabled there is need to
use plain CBOR as backup.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-22 09:44:36 +02:00
Veijo Pesonen 11b8b4e7ba net: lwm2m: enables CBOR content format
With LwM2M v1.1 the content format is enabled by default.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-22 09:44:36 +02:00
Veijo Pesonen 8fd283a788 net: lwm2m: Single instance read&write with CBOR
Raw CBOR content format support.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
2022-04-22 09:44:36 +02:00
Juha Heiskanen 53fbf40227 net: lwm2m: SenML Json fix RW Time
Added missing get_time and put_time for fixing crash.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2022-04-20 11:10:12 +02:00
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