For ease of maintenance, let's swap the reader/writer initialization
syntax to:
.put_begin = put_begin,
.put_end = put_end,
...
This way we only assign used fields and adding new ones later is
less error prone.
Signed-off-by: Michael Scott <mike@foundries.io>
Data formatters may need to process data at the beginning and end of
each object instance and/or resource. Currently, they can only add
processing at the beginning and end of resource instances.
Let's establish put_begin/end_oi (object instance) and put_begin/end_r
(resource) API functions that data formatters can use for this purpose.
Signed-off-by: Michael Scott <mike@foundries.io>
The plain-text format only supports READ op for a specific resource.
In all other cases return NOT_ALLOWED.
Signed-off-by: Michael Scott <mike@foundries.io>
Data formatters are becoming too complex for a simple do_read_op()
function to handle all in one place. Also, more data formatters are
going to be added for LwM2M v1.1 support in the future.
In order for data formatters to perform internal setup or deny
invalid requests (specific to the formatter's logic), let's
establish do_read_op_* functions in each formatter.
Once the internal processing is done, they can call back into the
more generic lwm2m_perform_read_op function.
Signed-off-by: Michael Scott <mike@foundries.io>
Each content formatter should have a way of handling opaque data.
For instance TLV data will individually be able to specify a length
but plain text will take up the rest of the packet.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
The existing LwM2M framework expected contiguous buffers and this
was the reason for the 384 byte buffer sizes. This was previously
a limitation of the ZoAP API. The new CoAP API doesn't have this
limitation and the LwM2M library has already been migrated to use
it.
Let's finish the process by replacing any contiguous buffer handling
with the correct net_pkt APIs to parse across multiple fragments.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Let's use snprintk for simple formatting to allow for possible disabling
of printf and protect calls to sprintf from string overruns.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Don't use names like "strlen" for parameters. Try and name buffer
parameters consistently.
NOTE: For several functions I removed "const" flag. This is
intentional and will be needed in upcoming patches.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
We are returning EINVAL from content format write ops when an object
field definition is not found (an optional field which is not
implemented). Instead, return ENOENT which lets the LwM2M engine
know to send ZOAP_RESPONSE_CODE_NOT_FOUND to the LwM2M server at the
end of handle_request().
NOTE: This behavior is not correct when we call the writer right after
a CREATE operation where the data is assigned to resources for the
first time. This case will be handled in a follow-up patch once we're
able to distinguish between a WRITE and a CREATE in the write op
handler.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Origin: SICS-IoT / Contiki OS
URL: https://github.com/sics-iot/lwm2m-contiki/tree/lwm2m-standalone-dtls
commit: d07b0bcd77ec7e8b93787669507f3d86cfbea64a
Purpose: Introduction of LwM2M client library.
Maintained-by: Zephyr
Lightweight Machine-to-Machine (LwM2M) is a protocol stack extension
of the Constrained Application Protocol (CoAP) which uses UDP
transmission packets.
This library was based on source worked on by Joakim Eriksson,
Niclas Finne and Joel Hoglund which was adopted by Contiki and then
later revamped to work as a stand-alone library.
A VERY high level summary of the changes made:
- [ALL] sources were re-formatted to Zephyr coding standards
- [engine] The engine portion was re-written due to the heavy reliance
on ER-CoAP APIs which are not compatible to the Zephyr CoAP APIs as
well as other Zephyr specific needs.
- [engine] All LWM2M/IPSO object data is now abstracted into resource
data which stores information like the data type, length, callbacks
to help with read/write. The engine modifies this data directly (or
makes callbacks) instead of all of the logic for this living in each
object's code. (This wasn't scaling well as I was implementing
changes).
- [engine] Related to the above change, I also added a generic set of
getter/setter functions that user applications can call to change
the object data instead of having to add getter/setting methods in
each object.
- [engine] The original sources shared the engine's context structure
quite extensively causing a problem with portability. I broke up the
context into it's individual parts: LWM2M path data, input data and
output data and pass only the needed data into each set of APIs.
- [content format read/writer] sources were re-organized into single
.c/h files per content formatter.
- [content format read/writer] sources were re-written where necessary
to remove the sharing of the lwm2m engine's context and instead only
requires the path and input or output data specific to it's
function.
- [LwM2M objects] re-written using the new engine's abstractions
Signed-off-by: Michael Scott <michael.scott@linaro.org>