Commit graph

831 commits

Author SHA1 Message Date
Michael Scott f8ba4585c5 net: lwm2m: register the RD client with the engine periodic service
Remove the RD client's stack in favor of using the engine's periodic
service to trigger RD client events.  This saves 5K RAM of stack based
memory.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott 1674a8c717 net: lwm2m: register device periodic service with engine
Remove the stack from the device object and instead make use of
the periodic engine service which will trigger the device service
when it's ready.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott a4ab36bcbd net: lwm2m: add periodic service registration to engine
Stacks cost a lot of RAM in Zephyr.  We have 3 total stacks in
the LwM2M lib.  We can remove 2 of these if add a service handler
into the main LwM2M engine.  Each service can register with this
handler so that they can be called based on their own periodic
timer.  The handler itself will search through these registered
services and call them when they become due otherwise sleep
until another is ready.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott 25ff4f0e6a net: lwm2m: reduce LwM2M footprint via lower defaults in Kconfig
Let's use conservative defaults for the LwM2M library to enable
hardware with constrained resources.  Users can increase where
necessary.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:25:56 +03:00
Michael Scott 022d805cc2 net: lwm2m: replace instances of s*printf with snprintk
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>
2017-10-26 09:23:19 +03:00
Michael Scott ebe3660308 net: lwm2m: fix Leshan discover OP
When using Leshan REST API to perform a discover OP on a client, only an
accept field is sent with "application/link-format".  Current logic uses
the content-type to determine when a discover OP is indicated.  Let's
handle this case as well.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:20:40 +03: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 eb5ba43644 net: lwm2m: fix error handling in handle_request()
Let's reset the payload and return correct response error codes.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott 1bca60d732 net: lwm2m: make release in lwm2m_release_message() optional
Let's rename lwm2m_release_message() to lwm2m_reset_message()
and add a parameter to let the function know whether or not to
release the lwm2m_message resource back to the pool.

By adding the optional release parameter, we can keep the
lwm2m_message but reset the underlying net_pkt / net_buf resources.
This allows us to regenerate the net_pkt after determining
an error has occured.  In this case, we don't want the previously
added net_pkt contents but we do want to maintain the message id,
token, etc.

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 fcd37eb79d net: lwm2m: use isdigit in JSON formatter
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 1fb61d21ac net: lwm2m: move non-public data out of shared JSON include
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 7f7e203334 net: lwm2m: remove unused JSON parser types
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
Michael Scott 9b643e2be7 net: lwm2m: cleanup TODOs in firmware obj.
Remove some left over TODOs and also fix a TODO where we need to return
the appropriate error code to generate a 4.05 response.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:39:00 +03:00
Robert Chou 19559ee41b net: lwm2m: increase rd client stack size when NET_LOG_GLOBAL=y
The stack of rd client is exhausted while running lwm2m client w/ IPv6
and network log global enabled. Increase the stack size to 1536 when
NET_LOG_GLOBAL is enabled.

Detail described at #4424

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:36:02 -04:00
Robert Chou 652cc727fe net: lwm2m: only method GET is allowed for .well-known/core
".well-known/core" is mainly used with method GET for performing the
resource discovery (RFC 6690). Since we are implementing a LwM2M client
and is not implement a resource directory which allow others to do the
resource registration (POST to .well-known/core). Only GET method is
allowed for the usage. Report 4.5 (Method Not Allowed) if other methods
are requested.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou cfa9990c41 net: lwm2m: return 4.04 when URI is not composed by digits
Modify zoap_options_to_path() to return error when URI contains
character other than digits and return 4.04 NOT FOUND to caller.

PATH such as "/1a/2/3" was treated as "/1/2/3" after parsring
which is incorrect.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou d5ab14697f net: lwm2m: fix empty path being treated as 0/0/0 issue
Return 4.05 Method Not Allowed when path is empty ('/') to the
caller for it's only use by bootstrap delete. This change also avoid the
empty path being treated as request targeted at 0/0/0.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou ce5e0d7208 net: lwm2m: response nicely when obj not found or OP not handled
1) Respond NOT FOUND to caller when object doesn't exist
2) Report as internal server error when OP not handled

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Michael Scott 1965e5e9fc net: lwm2m: add RD client callbacks for app
Applications may want to be notified when various events
happen in the LwM2M rd client.  Let's implement an event
callback which sends: connect, disconnect and update events.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Ricardo Salveti 58d758bf90 net: lwm2m: firmware: add support for firmware pull over CoAP proxy
CoAP allows a proxy to be used when transferring data (CoAP-CoAP and/or
CoAP-HTTP) by creating request on a specific URI path and by using the
Proxy URI CoAP option. Create specific Kconfig options for the proxy
server address and port, until a parser gets implemented.

Code tested with Californium acting as CoAP proxy.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
[michael.scott@linaro.org: rebased on net_app + lwm2m_message
refactoring + firmware update changes.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 4a0986dc7a net: lwm2m: ignore duplicate/older block transfers
During firmware download via block-wise transfer, we can see
packets occaionally get re-transmitted (normal logic in the
pending / retry functions).  However, both of these packets
end up coming through the reply handler and we should ignore
any block-wise transfer that has a current value less than
where we expect to be.

NOTE: This fixes K64F ethernet transfers where we were getting
too many packets back in the handler.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott ed100e9c6a net: lwm2m: add full block-wise retries for firmware download
UDP packets can be lost in heavy traffic.  Normally we can handle this
with pending packet processing for packets which have not been responded
to with an ACK.  However, due to the time it takes for firmware to
download via CoAP, an extra level of retries should be added.

The process works like this:

Normal pending packets will try to send 3 times fairly quickly.
If that fails, then the timeout callback is called for the firmware
download process.  A retry counter is incremented and the timeout
callback perform a new packet send of the block-wise transfer
packet that is missing, until the retry counter hits a limit (3)
and then the transfer is aborted.

This allows for a longer "outage" to happen during firmware transfer
and the process can still succeed.

NOTE: This patch does not fix a current bug where the pending process
is not re-sending the packets correctly, it only makes the process
more stable with a better chance to work.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 0b0fd5515d net: lwm2m: fix packet leak in timeout work
When a packet expires after the pending retries we call
lwm2m_release_message() to free up resources.  This includes
cleanup of the pending structure which calls net_pkt_unref on
the pending packet.  This would normally free up the packet
memory.  However, earlier in the pending processing we add a ref
to the packet so that normal send processing doesn't free up
the memory.   This meant we were leaking packet memory every
time we had an expiration due to timeout.

Let's do an unref prior to calling lwm2m_release_message() to
make sure the packet memory is freed correctly.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott c9a80de76b net: lwm2m: setup lwm2m ctx for firmware download
Previously, firmware support wasn't initializing the retransmit work
or the extra network packet pools.  Let's fix that.

NOTE: While this fixes the setup of retransmit work, the actual
attempts to re-send packets which are pending is failing.  Needs
another follow-up fix.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 788c013d5b net: lwm2m: split out lwm2m context initialization
Create an internal function lwm2m_engine_context_init() which sets
the extra packet pools and initializes retransmit work internal to
the LwM2M engine.

This function will be used by firmware pull support which establishes
a new LwM2M context for downloading firmware.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott f630857e69 net: lwm2m: fix message release for separate reply
In the case of a proxy server translating HTTP -> COAP (known in
the code as "separate reply"), we were leaking lwm2m_message structures.
This was due to pending objects being cleared out during the first ACK,
and no other way of finding a matching message when the follow up packet
was received.  Let's add a second match for reply to make sure we can
find our matching message resources.

NOTE: This change renames find_msg_from_pending() to find_msg() and
makes it a static function as it's only used by the lwm2m_engine.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott edc32f4619 net: lwm2m: change registraion update messages to INFO
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 61fe1e17c3 net: lwm2m: RD client start message should be INFO not DEBUG
This is a useful message announcing that the RD client state machine
is starting for a particular connection.  If the log level is set
low so that DBG messages are hidden, then this message goes away.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 3f9c36301c net: lwm2m: fix compile w/o CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
Fix wrong check of DELIVERY_METHOD_PUSH to DELIVERY_METHOD_PUSH_ONLY

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Robert Chou b93eb8dee1 net: lwm2m: add firmware push support
1. Add handling block1 option in handle_request(). The basic idea is
   to declare structure block_context at compiled time and use "token"
   as a key to pick up the on-going block cotext. It should be able to
   support multiple blockwise transfer concurrently
2. Use write callback implemented in lwm2m_obj_firmware to deal w/ the
   update state transition and than call the callback registered by the
   application
3. move default_block_size to lwm2m_engine.c to share between
   lwm2m_engine and lwm2m_obj_firmware_pull

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: rebased on LwM2M net_app changes.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Robert Chou f6188fbce3 net: lwm2m: setup data_ptr/len for OPAQUE resource when none given
OPAQUE resource type might/might not have data_ptr/data_len setup
depending on the implementation. This introduce an issue that when
OPAQUE resource is written from the server side, the ones w/ none
setup will not be able to get the data at post_write_cb()

Modify to setup data_ptr/data_len as incoming buffer and buffer size

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-17 19:40:04 -04:00
Robert Chou d9f5fe7455 net: lwm2m: add state machine for firmware pull update
1. Parse firmware pull URI
2. Add lwm2m_firmware_get/set_update_cb() for application to register
   callback. This is because we want to check the update_state before
   we pass to the application
3. Add lwm2m_firmware_get/set_update_result() and
   lwm2m_firmware_get/set_update_stat() to manage the state transition
   as well as the sanity check

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: rebased on net_app framework and
lwm2m_message refactoring.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott ba20b3a884 net: lib: lwm2m: use stand-alone URL parser
With future patches we will need to parse URLs in the registration
client and firmware object.  Enable it by default when LWM2M is
enabled.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott b7060cf611 net: lwm2m: set range for client lifetime config
Due to timeout checking the minimum lifetime must be 15 seconds,
and we're storing the lifetime as an unsigned short so set the
maximum to 65535.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Michael Scott b3e58c7874 net: lwm2m: add timeout callbacks to registration client
Callbacks are setup for the following states:
- ENGINE_DO_BOOTSTRAP
- ENGINE_DO_REGISTRATION (first registration)
- ENGINE_REGISTRATION_DONE (subsequent client updates)
- ENGINE_DEREGISTER

In most cases, if a timeout occurs the registration engine goes back to
ENGINE_INIT.  The exception is a timeout during client update, which
forces the state machine back to ENGINE_DO_REGISTRATION (skipping a
boostrap).

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Michael Scott 897dbffe7c net: lwm2m: refactor engine to use lwm2m_message structure
Sending an lwm2m message is too difficult.  It requires pending / reply
and other structures to be configured and set by various portions of
the library.  There is also no way to know if a pending message ever
encounters a timeout.

Let's fix this by simplifying the internal LwM2M engine APIs for
handling lwm2m messages:

1. A user calls lwm2m_get_message(lwm2m_ctx) which returns the first
   available lwm2m message from an array of messages
   (total # of messages is set via CONFIG_LWM2M_ENGINE_MAX_MESSAGES).
2. Next the user sets all of the fields in the message that are
   required (type, code message id, token, etc)
3. Then the user calls lwm2m_init_message(msg).  This initializes the
   underlying zoap_packet, pending and reply structures.
4. Once initialized, the user creates their payload in msg->zpkt.
5. When the user is ready to send, the call lwm2m_send_message(msg).
6. And if for some reason an error occurs at any point, they can free
   up the entire set of structures with: lwm2m_release_message(msg).

Included in the refactoring is a timeout_cb field which can be set in
the LwM2M messages.  If a pending structure ever expires the engine
will call the timeout_cb passing in the msg structure before it's
automatically released.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Michael Scott 42f3eccb38 net: lwm2m: cleanup token / token length handling
Instead of using a magic reference to 8 for token length, let's
establish a define for MAX_TOKEN_LENGTH and then use it for both
variable definitions and to make sure tokens are valid.  Also,

Correct the handling of a special token length value (0xFF) which
lets lwm2m_init_message() know to skip token generation.  We were
using a -1 value here previously (on a u8_t variable).

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Michael Scott 70372f1201 net: lwm2m: save lwm2m_ctx instead of net_app_ctx in observer
This is the first part of a large refactoring of LwM2M library
message functions and will simplify observer handling later.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 10464e346c net: lwm2m: remove extra sockaddr values
All throughout the LwM2M library we use sockaddr values which are
basically the same as the net_app_ctx's remote addr.  There's no
reason to keep these extra sockaddr values around.  The net_app
framework client won't accept incoming requests on sockaddr other
than the one we're connected to.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 3840761265 net: lwm2m: remove registration client "registered" field
Replace with a check of the state machine's state instead.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 33c79033d0 net: lwm2m: move library internals to net_app APIs
This is the final stage of moving the LwM2M library internals to
the net_app APIs.  This means we can support DTLS and other
built-in features in the future.  All of the logic for
establishing the network connection is removed from the sample
app.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 53099eb501 net: lwm2m: add net_context parameters to functions
In preparation for the move to net_app APIs, we will need
to pass net_app_ctx structures around to the following
functions:
lwm2m_udp_sendto()
udp_request_handler()

Let's add the parameter as net_context for now so the
transition will be smoother later.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott aa3e52c261 net: lwm2m: remove net_context parameter from lwm2m_udp_receive()
This is part of lwm2m_ctx and is not needed.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 148b264255 net: lwm2m: add ZoAP pendings/replies to lwm2m_ctx
This allows use to associate easily the replies / pending operations
with a specific network connection.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott e6b2eeb6a6 net: lwm2m: move retransmit_work to lwm2m_ctx
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 82c2b70cb5 samples: lwm2m: initialize lwm2m_ctx prior to use
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 728ab4229a net: lwm2m: introduce lwm2m context structure
The LwM2M library does not use net_app APIs internally.  To help
this effort let's establish a user facing structure "lwm2m_ctx"
(similar to http_client_ctx and mqtt_ctx) and start it off by
wrappering the net_context structure.

Future patches will add user setup options to this structure and
eventually remove the net_context structure in favor of a net_app_ctx.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +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 70ee7e31af net: lwm2m: return 4.04 (not found) when obj/obj_inst/res not exist
We did not check the requested object/object instance/resource exists or
not before we adding an observer. Correct it by checking the existence
first.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou 627d199db3 net: lwm2m: clean up observer when object/object instance is removed
We should stop sending out notification to the peer when the
object/object instances requested to be observed is removed

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou b6a0cdfd64 net: lwm2m: fix obj/obj_inst/observer sys_slist_t corrupted when remove
We were using sys_slist_remove() to remove object, object instance and
observer w/o passing the previous sys_snode_t to it (NULL).
This will instruct the function to treat the node as the list head and
result in unexpected behavior after the removal.

Correct it by using sys_slist_find_and_remove() or passing the previous
node to the function.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou dc0b838641 net: lwm2m: reset obj_inst/res_inst data structure when delete
When a request demands to create a new object instance, it will search
whether the request object instance exists or not. However, current
implementation does not reset the lwm2m_engine_obj_inst at the time it
is deleted. It only removes the object instance from the sys list.

Correct the behavior by resetting both object instance and resource
instances at the time it's deleted. Also, consolidate function
lwm2m_delete_handler() and lwm2m_delete_obj_inst().

To reproduce the issue, try to create light control object instance
(/3301), delete the created instance and create it again. You shall find
following error message dumped.
> [ipso_light_control] [ERR] light_control_create: Can not create
  instance - already existing: 0
> [lib/lwm2m_engine] [ERR] lwm2m_create_obj_inst: unable to create obj -
  3311 instance 0

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Michael Scott cff468217b net: lwm2m: select NET_APP_CLIENT automatically
No need for samples to make sure they have this configured in their
.conf files.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-12 20:37:48 +03:00
David B. Kinder 97033049e1 doc: fix Kconfig misspellings
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-31 14:22:11 -04:00
Michael Scott 8662b69685 net: lwm2m: return BAD_REQUEST when object create fails
Per LwM2M spec (7.3.2.4 Operation on Object):
"If the payload (New Value) conveys an Object Instance ID in conflict
with one already present in the LwM2M Client, the complete request
MUST be rejected and a "Bad Request" error code MUST be sent back."

Let's do that.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-21 08:38:17 -04: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 22b11ba8fe net: lwm2m: define a CREATE operation
Prior to this patch, a CREATE operation was handled as a WRITE operation
after the object instance was created.  This becomes problematic when
handling of optional resources differs between these 2 operations.

Let's introduce an actual CREATE operation and use it later to create
these differences.

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
Paul Sokolovsky dcb80f7ab8 net: struct sockaddr should have field "sa_family"
POSIX requires struct sockaddr's field to be named "sa_family"
(not just "family"):
http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html

This change allows to port POSIX apps easier (including writing
portable apps using BSD Sockets compatible API).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-18 16:34:51 -04:00
Ricardo Salveti 2175f78385 net: lwm2m: add IPSO light control object
As defined by IPSO-Smart-Objects "Section: 16. IPSO Object: Light
Control".

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-18 10:53:25 +03:00
Robert Chou c1500fe9a4 net: lwm2m: report resource type / content type at registration
Per LwM2M specification 5.3.1 Register, report "ct=11543" when JSON is
supported. Also, report the resource type as rt="oma.lwm2m" when "ct="
presents.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-17 21:52:24 +03:00
Robert Chou a64dcbb7bf net: lwm2m: do not report object when object instances available
Per LwM2M specification 5.3.1 Register. When object instances are
available, object ID can be ignored in registration message

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-17 21:52:24 +03:00
Robert Chou c21372eeb8 net: lwm2m: do not expose security object
According to LwM2M specification 5.2.7.3 Bootstrap DISOCVER,
security object is only reported to the bootstrap server.

Correct the behavior to (1) report server object to the server
(2) do not report security object at registration time

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-17 21:52:24 +03:00
David B. Kinder 81f7c82625 doc: fix misspellings and missing EOF newlines
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-16 17:38:41 -05:00
Robert Chou 37e21a4152 net: lwm2m: fix registration content format and use plain/text
1. According to the specification 5.3.1, it's a MUST to specify
   (1) content format: app link format (2) supported lwm2m version.
   Also, we should use text/plain instead of LWM2M's (obsolete).
2. Use LWM2M_FORMAT_OMA_TLV as default accept format when accept option
   is not given from the caller for TLV is a MUST have in LwM2M spec and
   it can deals w/ multiple resources read

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-13 20:52:56 +03:00
Robert Chou 87ce5f1935 net: lwm2m: save accept format in observe_node_data
Save in observe_node_data so that later on we can select the correct
content format requested by the caller at the first time

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-11 09:53:47 +03: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
Ricardo Salveti cc3290afc8 net: lwm2m: build sprint_token only when debug is enabled
sprint_token is only used by SYS_LOG_DBG, so only build it when
CONFIG_SYS_LOG_LWM2M_LEVEL > 3.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 3896930be6 net: lwm2m: engine: add flag for separate response
Separate response can happen when handling block transfer for firmware
updates, and to avoid duplicating the lwm2m_udp_receive function, create
and additional flag to allow handling CoAP separate response messages.
This is required to avoid removing the reply callback, since a new
message (with a valid token) will be received later from the server.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 36fe07802a net: lwm2m: create common wrapper for net_context_sendto
Simplifly net_context_sendto calls and also allows to easily debug every
send/receive lwm2m call.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 2c759d180d net: lwm2m: engine: fix typo
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 17b33d3a58 net: lwm2m: rd_client: handle forbidden errors
Stop both bootstrap and registration process if they return forbidden.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 61961cf737 net: lwm2m: firmware: add Kconfig option for CoAP block size
CoAP block size might be adjusted for a faster firmware download
process.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Robert Chou cd56290dbe net: lwm2m: rename CONFIG_NET_L2_BLUETOOTH to CONFIG_NET_L2_BT
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-09 16:03:02 +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 aef5ee4582 net: lwm2m: add IPSO support w/ temperature sensor object
IPSO Smart Objects are a set of template objects based on the LwM2M
object framework which are designed to represent standard hardware
such as temperature and humidity sensors or light controls.

Let's add a place for these objects to live as well as an initial
temperature sensor object.

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