Commit graph

64 commits

Author SHA1 Message Date
Michael Scott 77f18827d8 net: lwm2m: simplify oma_tlv get_bool()
Use existing get_number() function to reduce code size.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-02 10:01:05 +02:00
Michael Scott dd95dbcd9e net: lwm2m: introduce getter/setter for OPAQUE data
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>
2017-10-31 09:41:27 +02:00
Michael Scott b37a005d68 net: lwm2m: add multi fragment support to LwM2M library
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>
2017-10-31 09:41:27 +02:00
Michael Scott 1d05ba75d1 net: lwm2m: fix CREATED response code
Handle LwM2M CREATE op correctly and remove comments.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott fb734acc73 net: lwm2m: move to using the new multi-packet CoAP API
This patch moves from the ZoAP API in subsys/net/lib/zoap to
the CoAP API in subsys/net/lib/coap which handles multiple
fragments for sending / receiving data.

NOTE: This patch moves the LwM2M library over to the CoAP APIs
but there will be a follow-up patch which re-writes the content
formatter reader / writers to use net_pkt APIs for parsing
across multiple net buffers. The current implementation assumes
all of the data will land in 1 buffer.

Samples using the library still need a fairly large NET_BUF_DATA_SIZE
setting. (Example: CONFIG_NET_BUF_DATA_SIZE=384)

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott 545db8b482 net: lwm2m: remove unused last_value_len from lwm2m_input_context
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 078288b2be net: lwm2m: move non-public data out of shared TLV include
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 12072a378f net: lwm2m: cleanup function parameter naming
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>
2017-10-20 10:40:55 +03:00
Robert Chou c0a946ac3c net: lwm2m: propogate errors to the caller when using TLV writer
Errors has been ignored when using TLV writer to create/write object
instance/resources. Modify to propagate the error back to the caller.

To reproduce the issue, try to create IPSO light control object
instances twice. Since the default instance count is 1, the second one
should be rejected and responded w/ error. But the current
implementation will respond w/ 2.04.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou d42af5914e net: lwm2m: ignore optional resource when not implmeneted
Per LwM2M specification 7.3.2.4, "Optional Resources MAY be conveyed
in the "New Value" parameter as well; the LwM2M Client MAY ignore the
optional resources it doesn't support."

Update TLV/JSON writer to ignore error when object fields are not
found (treated as optional resource). This will allow the resources
supported being written.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: re-worked patch post addition of CREATE
operation.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-21 08:38:17 -04:00
Michael Scott 75016c7b97 net: lwm2m: fix resource not found error code in format writers
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>
2017-08-21 08:38:17 -04:00
Robert Chou 84106f3cb3 net: lwm2m: fix erroneous TLV write
Function do_write_op_tlv() uses in->inbuf and in->insize as a looping
condition to iterate through items in TLV payload and call
do_write_op_tlv_item() to update the value.

However, do_write_op_tlv_item() will override the value before calling
for fitting the usage of lwm2m_write_handler() function without restore
them. (lwm2m_write_handler() is also called by plain text/json writer
and is expecting in->inbuf is the start of buffer and in->insize as the
length of the buffer)

This will result in errors in do_write_op_tlv().

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-11 09:49:45 +03:00
Michael Scott ccd4f68da3 net: lwm2m: add SPX Apache-2.0 license tag w/ Linaro copyright
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-09 10:55:53 +03:00
Michael Scott c46c206f8c net: lwm2m: initial library support for LWM2M
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>
2017-08-09 10:55:53 +03:00