The code in the LwM2M "Device" object was checking for this max
power source config value, except that it was never added as a
Kconfig option. Let's go ahead and add it so apps can set the
value appropriately.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
When attempting to read an unused multi-value resource such as
"Available Power Sources", lwm2m client return a successful coap packet
w/o any values. This looks like a timeout to any lwm2m servers which
make sure a valid response is returned.
Let's fix this by returning the correct NOT_FOUND error code instead.
NOTE: To test this I commented out the portion of the lwm2m client
sample which initializes the LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT and
LWM2M_DEVICE_PWR_SRC_TYPE_USB values. By default, the sample will
setup dummy values to be returned by the client.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
As per review of PR #5893, this is a follow up patch to update
select_writer() API to match the behavior of select_reader() API.
Quote from OMA-TS-LightweightM2M-V1_0_1-20170704-A. 8.2.5
"An Object Instance or Resource is Read by sending a CoAP GET to the
corresponding path. The response includes the value in the
corresponding Plain Text, Opaque, TLV or JSON format according to
the specified Content-Format (see section 6.4).The request MAY
specify an Accept option containing the preferred Content-Format
to receive. When the specified Content-Format is not supported by
the LwM2M Client, the request MUST be rejected."
Therefore, we do not attempt to assign a content-format when the
requested one is not supported. Instead, we return an error code.
0 is returned when reader or writer has been successfully selected by
select_reader() or select_writer()
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
Currently, we always set the content-format as "plain/text" when
it is unrecognized. This is wrong for it's possible that payload
is actually something else.
For example, we don't support JSON as incoming format right now.
But if I send a PUT request to /1/0/1 (server objectinstance/lifetime
resource) with value 3200 in JSON format: {"e":[{"n":"","v":3200}]}.
The client will still handle the request and respond with changed (2.04)
except the lifetime resource is updated incorrectly due to parsing
error.
Correct the behavior by not setting a default format and respond with
content-format-not-support error code (4.15)
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
During the CoAP API change, slight changes were made the ref / unref
packet pending process. Let's re-align with the coap-client sample
in how we apply the packet refs in retransmit_request() and also
replace the lwm2m_send_message() call with a direct call of
net_app_send_pkt(). This avoids a second processing of the pending
packets and keeps the ref/unref flow cleaner.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
During the CoAP API change, the way packets were ref'd and then
unref'd in order to stop the packet sending functions from releasing
the net_pkts was changed and never updated in the LwM2M library.
Let's use coap_pending_cycle() and coap_pending_clear() to do the
ref/unref the same way as the coap-client samples in order to
match the pending process with the current CoAP APIs.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Fraction could be stored with negative value.
The implementation was only considering the positive value case.
Therefore, we have to modify the code to take care of the case.
To test it
======================================================================
1. launch eclipse/wakaama lwm2m server
2. launch zephyr lwm2m client and wait for registration completed
3. Issue commands from server
* attr 0 /1/0/1 -0.1 0.1
* disc 0 /1/0
Current output
----------------------------------------------------------------------
Client #0 /1/0 : 2.05 (COAP_205_CONTENT)
105 bytes received of type application/link-format:
</1/0>,</1/0/0>,</1/0/1>;gt=0.1;lt=0/00000,</1/0/2>,</1/0/3>,</1/0/4>,
</1/0/5>,</1/0/6>,</1/0/7>,</1/0/8>
Expected output
----------------------------------------------------------------------
Client #0 /1/0 : 2.05 (COAP_205_CONTENT)
102 bytes received of type application/link-format:
</1/0>,</1/0/0>,</1/0/1>;gt=0.1;lt=-0.1,</1/0/2>,</1/0/3>,</1/0/4>,
</1/0/5>,</1/0/6>,</1/0/7>,</1/0/8>
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
As title, we should update the existing observe_node when new attributes
are written from server side. Add the implementation to handle that.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
1. Read notification attributes set by server to setup the
minimum/maximum notification period of a observation request.
2. Reordering to check observe_node duplication first
(bailout earlier)
3. Simplify remove observe_node condition checking
NOTE: attributes are inheritable, priority: res > obj_inst > obj
Reference: LwM2M spec V1_0_1-20170704-A, section 5.1
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
Since we've added storing notification attributes written by server.
We can now append these attributes as part of link-format for discover
op.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
Implement write-attribute on obj/obj_inst/res according to LwM2M spec
20170704-A, sec 5.1.2. Support pmin/pmax/st/gt/lt parameters on WRITE
operation.
The basic idea is to add sys_slist_t to obj/obj_inst/res structure.
And attach struct lwm2m_attr to the list when attributes are written
from server side (implement lwm2m_write_attr_handler accordingly)
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
commit 2a7546fb5a ("net: lwm2m: add support for coap2coap proxy")
erroneously changed the COAP_OPTION_* used to specify the coap2coap
or coap2http proxy resource used from COAP_OPTION_URI_PATH to
COAP_OPTION_PROXY_SCHEME.
Changing it back to COAP_OPTION_URI_PATH requires us to re-order how
the coap options are appended to the packet as the coap options must
be added in the order specified by the numbers in:
https://tools.ietf.org/html/rfc7252#section-12.2
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
CoAP packet w/ confirmation flag set is required to be retransmitted
before it got the ACK message from the peer.
However, the packet is usally unreference once it's sent to the network.
Although we set the timeout as no wait when calling function
net_app_send_pkt(), it's still possible that the packet is unreferenced
before we got a chance to increase the packet reference by calling
coap_pending_cycle().
Usually, the IP stack will generate an ARP packet first and then send
out the packet. However, this is not the case when the remote is a
loopback address.
As issue #5101 described, when asking client to perform a firmware pull
on URL "coap://127.0.0.1:7783/large". The packet will be unreferenced
immediately after calling net_app_send_pkt(). Which then result in
client hang.
The solution to the issue is to increase the reference count on the
sending packet and decrease it after the process is finished.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
Consolidate and standardize error handling throughout
lwm2m_obj_firmware_pull.c. As well as handle previously
unhandled errors returned from transfer_request().
NOTE: in general, unhandled errors will now result in
RESULT_UPDATE_FAILED. Previously, unhandled errors in
transfer_request() would result in RESULT_CONNECTION_LOST
which might or might not be over-written with another
result later.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Currently, LwM2M firmware download only supports coap2http proxy.
Let's add support for coap2coap proxy as well.
This was tested running Californium demo app cf-proxy on the host
machine with the following setting changed in Californum.properties:
MAX_RESOURCE_BODY_SIZE=524288
Add the following to the samples/net/lwm2m_client/prj.conf:
CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_COAP_PROXY_SUPPORT=y
CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_COAP_PROXY_ADDR="coap://[2001:db8::2]:5682"
Build the sample for qemu_x86 as you would normally, but now
you can use a real world coap address to pull firmware using the 5/0/1
resource. The host machine running cf-proxy will pull the remote
resource and then deliver it to the running qemu sample.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
- Add needed settings for DTLS support to the lwm2m_ctx structure.
- Add initialization of MBEDTLS to the LwM2M lib based on the
user application settings in lwm2m_ctx.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The default net_context remote address is scrambled when using a
connection via DTLS. Instead let's use the dtls context remote.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
While looping through possible lwm2m_ctx matches, we're referencing
remote before checking that the context itself is valid.
Also, reduce indentation issues.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Instead of building under the "app" context, let's build the
LwM2M library as a separate static library. This will be helpful
later when adding support for DTLS as w/o this configuration,
the build breaks on MBEDTLS config includes.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Content-format is used to determine the type of the PUT/POST
request. Therefore, it's incorrect to assign default when the
caller does not include one in the request.
Define LWM2M_FORMAT_NONE=65535 to indicate the format is missing.
The 65000~65535 is reserved for experiments and should be safe for
the purpose. Check content-type at PUT method to setup
write/write-attrs operation accordingly.
Also, add reporting write-attrs as not implemented to the caller.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
According to LwM2M specification V1_0_1-20170704-A, table 25,
incoming request is a discover op if it is method GET with
accept format as application/link-format
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
According to LwM2M specification 20170208-A, there are two different
discover interfaces supported by the device.
(1) Bootstrap discover (sec 5.2.7.3) (To be implemented)
(2) Device management discover interface (Sec 5.4.2)
- object ID is required (i.e. root directory discover is not allowed)
- attributes should be responded accordingly when implemented
This patch correct the behavior according to the spec and summarized
as follow
(1) Still support CoAP ".well-known/core" but change to report only
first level of the URI.
(2) Respond to caller only when object ID is provided unless it's
bootstrap discover
Fixes#4941
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
Token is missing when we jump to the error and token is not yet setup.
To correct it, we grab the token from the input packet at the beginning
of the handle_request()
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
Copy/paste error was checking minimum measurements where it
should have been checking maximum measurements.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Initial values for the min/max measurements were 0 and this caused
issues with sensors maximums that weren't above 0 and minimums that
went below 0. Let's update those to MAX_INT so the first sensor
value update will set those to correct values.
When resetting the measured values, let's use the current sensor
value not 0.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.
Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.
This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.
For users that just want to continue their work with minimal
disruption the following should suffice:
Install CMake 3.8.2+
Port any out-of-tree Makefiles to CMake.
Learn the absolute minimum about the new command line interface:
$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..
$ cd build
$ make
PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
Update the firmware update_result accordingly by checking return
value of the firmware data write callback registered by application.
Also, set response code according.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
We should call coap_update_from_block() which will determine the minimum
size of the BLOCK1 SIZE between server/client and update the current
offset and total size(if available) accordingly.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
Now that objects and samples have their return values fixed, let's
propagate them back up to the user if there's an error.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Previously, post_write and execute callbacks returned 1 when handled
and 0 for error condition. However, this wasn't detailed enough and
the engine can't propagate any sort of error back to users -- so it
doesn't even check the return values in many cases!
Let's adjust the resource callback functions of all objects and the
lwm2m_client sample to return 0 for success or a valid error code.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Now that we can access resource data in the lwm2m subsys, let's use
the user provided firmware push buffer (5/0/0) to also store the
firmware pull data.
This way the size of the firmware pull buffer is completely up to the
application.
NOTE: This patch adds a 64 byte firmware buffer to the lwm2m_client
sample for this purpose.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
With the change to support multi-fragement buffers in the LwM2M subsys,
the OPAQUE data type was direct write methods were broken.
Let's fix OPAQUE handling by using the newly introduced getter methods
which can use multiple user callbacks (depending on the size of the
user provided buffer). Let's also add public methods for users to set
/ get OPAQUE data in resources for future use with DTLS key data.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
The lwm2m_engine_get_resource() function needs to be made available to
other portions of the lwm2m subsys in order for firmware resource data
to be used in the future.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
During conversion from the ZoAP to CoAP APIs the use for this variable
was removed, but the variable itself was left in place.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
No need for 2 different defines to specify URI lengths in the source
for firmware pull method. Let's combine them.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
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>
application/octet-stream is used to indicate opaque payload format.
Use plain text handler to handle the opaque format.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
When moving to the new CoAP API, I thought we would need to parse
incoming option values longer than 12 characters.
This hasn't proven to be true, so let's remove the auto-selection of
this config. If needed user can set this option later.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
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>