Split out definition of net_app_init() and its parameter flags from
net_app.h header to new net_config.h header. As we do this, rename
the function to net_config_init() and flags to NET_CONFIG_NEED_*.
This is a second step in splitting out network configuration API
out of net_app API, started in the c60df1311 commit.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This allows zephyr to listen LLMNR DNS queries sent by Windows
and respond to them. See RFC 4795 for details.
The feature requires that hostname is set properly to the
zephyr device and LLMNR is configured properly.
Typically following config options are enough for this support:
CONFIG_NET_HOSTNAME_ENABLE=y
CONFIG_NET_HOSTNAME="zephyr-device"
CONFIG_DNS_RESOLVER=y
CONFIG_LLMNR_RESPONDER=y
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This implements LLMNR client from RFC 4795. This means that caller
is able to resolve DNS resource records using multicast DNS.
The LLMNR is used in Windows networks.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Due to the fact that cmake doesn't allow to build empty "library"
(which would be the case when neither CONFIG_NET_APP_SERVER nor
CONFIG_NET_APP_CLIENT is defined).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
net_app library consisted of 2 disjoint parts: a) library to
setup/configure networking on the application startup; b) library
to setup client and server connections.
As the configuration library is universally useful and is a generic
Zephyr networking component, split it out to a seperate top-level
networking library under net/lib/config/.
Fixes: #7658
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
When the priority of the LwM2M engine was lowered, it causes an
occasional registration update to fall outside of the registration
lifetime. This shows up as the following error:
Failed with code 4.4. Retrying registration
Let's try and retry a bit earlier to account for the priority
change.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The ARRAY_SIZE() utility macro will actually test the parameter types,
and ensure that it is only called with arrays, and not arrays decayed
to pointers.
Changes were performed with a simple Coccinelle script.
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
A typo in update_attrs() was setting every observer to a PMIN of 0.
This meant we could send observer data as often as the process was
called. This is out of spec as the default minimum is 10 seconds.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The LwM2M engine thread is used for various periodic triggers.
None of these are in a critical path that requires super sensitive
timing and the current K_PRIO_COOP(7) setting was causing the
Bluetooth RX thread to have to wait too long for certain actions
to complete.
Let's lower the priority to -1 (effectively) to eliminate these
conflicts.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Convert couple of MSEC() calls to K_MSEC() as the timeouts
when using MSEC() are just too long.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
During normal use, a CoAP packet can be resent due to network congestion
and other causes. During block transfer the LwM2M client checks to make
sure the block received is the one we expect and if not generates a
"duplicate" warning. When this happened, we were releasing the reply
handler and when the correct block was received the client would
generate a "No handler" error.
To avoid releasing the reply handler too early, let's set the coap_reply
"user_data" field to an error condition (1). Then, once the reply
processing is complete we can check the user_data field to be sure that
it's ok to release the reply handler.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The code was using MSEC() macro in few places instead of more
proper K_MSEC(). The MSEC() takes seconds as a parameter and
K_MSEC() takes milliseconds.
Fixes#7657
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
sin6_scope_id is not set anywhere and not used. Probably left over
from old ZOAP library. Just address, port and family type are enough
to find registered CoAP observer.
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
The next error check is much more suitable to handle the error due to
the error message which lets the user know that something went wrong.
Fixes#7661.
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
Current implementation hardcoded channel in received frame structure.
With this change channel can be retrieved from a OpenThread platform,
and put in the frame. In result procedures like Discovery can be
executed correctly. Change was tested with OpenThread Border Router.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit contains bugfix for Joiner eui-64 handling and setting radio
in correct mode after calling thread stop.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When designing the registration client for LwM2M, I understood
that the LwM2M Technical Specification allows for a multi-server
connection setup where the client makes several connections
to various LwM2M servers and allows each of them to manage
various aspects of the LwM2M client based on Access Controls.
However, the way I implemented it was not well thought out and
as we look forward to adding Bootstrap support, it needs a
do over.
Let's remove all of the code dedicated to handling multiple LwM2M
client connections. This will simplify and reduce the code size
of the registration client considerably.
Later, once Bootstrap support has been added, we can implement
multi-server connections in a cleaner manner.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
This allows a user to customize the port used for downloading
firmware via the pull method of the LwM2M client. It's default
value of 0 will select a random port during initialization.
NOTE: If set, this value should not be the same port as the
LWM2M_LOCAL_PORT setting.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Due to a bug where LWM2M_LOCAL_PORT was not being honored, all
outgoing traffic from the LwM2M client was coming from a random
port determined during initialization.
Now that this bug bas been fixed, let's default the client to the
behavior that most users are expecting, and let new users customize
the outgoing port if needed (which should be rarely).
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Currently, CONFIG_LWM2M_LOCAL_PORT is never used when setting up
the LwM2M client. Let's set the port of the local address using
CONFIG_LWM2M_LOCAL_PORT, so that the client can bind to it.
NOTE: A setting of 0 will use a random port.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Currently, the client_addr parameter is only used to check the
sa_family at various points during the init process. Both the
IP address and the port are ignored. Let's set the local client's
port based on the port value of the passed in client_addr if one
is supplied.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The port parameter passed to _net_app_set_local_addr() is converted
from host byte-order to network byte-order. Here we are passing
a port value which has already been translated to network byte-order.
Let's translate the local port to host byte-order when passing it
to _net_app_set_local_addr() to fix this issue.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
L2 could take advantage of such hardware capability, when supported by
the device. This is also required for OpenThread.
Fixes#5714
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
We only clear 3 of the 6 member variables of the coap_reply structure
in coap_reply_clear().
Let's make sure to reset all of them.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The base CoAP retry setting is quite fast for network technologies
such as LTE-M and LoRa. Let's add an option to delay retries
a bit longer depending on the need.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Using IPSO Smart Object Guideline: "Smart Objects Starter Pack 1.0"
dated May 27, 2017, let's mark the OPTIONAL resources for an
IPSO Temperature object (Section 10. "IPSO Object: Temperature").
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Using IPSO Smart Object Guideline: "Smart Objects Starter Pack 1.0"
dated May 27, 2017, let's mark the OPTIONAL resources for an
IPSO Light Control object (Section 16. "IPSO Object: Light Control")
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Firmware Update object (Section E.6 "LwM2M Object: Firmware
Update")
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Device object (Section E.4 "LwM2M Object: Device")
As a result, the Device object no longer configures the default
buffers for data storage of several optional resources.
The LwM2M client sample is also changed to to setup these read-only
buffers instead.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Server object (Section E.1 "LwM2M Object: Server")
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Security object (Section E.1 "LwM2M Object: Security")
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
This patch introduces several changes to support OPTIONAL resources.
The primary indicator for this behavior is to assign FLAG_OPTIONAL
to the object field's permission flags.
These resources are not setup by the LwM2M object code. They are
left up to the user-based code for initialization via the following
functions:
lwm2m_engine_set_res_data()
lwm2m_engine_get_res_data()
When assigning const-based data as a data buffer, user-based code can
also specify the following data flag: LWM2M_RES_DATA_FLAG_RO
The FLAG_OPTIONAL flag also affects the LwM2M engine in the following
ways:
- CREATE operations won't generate an error if optional resources are
not included.
- Object instance READ operations won't complain about missing
optional resources.
- In the future, BOOTSTRAP operations can have different handling
based on optional resources.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
In the future, we will have optional resources that may or may
not be assigned a buffer for data storage. When these resources
are queried we need to be able to return an error code if the
buffer isn't set.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Instead of selecting the first IPv4 address from the network
interface, use destination address to select the proper local IPv4
address.
Fixes#7500
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Fix a build warning when compiling a net_app sample with
CONFIG_NET_APP_DTLS enabled by changing the print formatter from %zu
to %d. It references the var hdr_len which is defined as an int:
In file included from include/net/net_core.h:78:0,
from subsys/net/lib/app/net_app.c:27:
subsys/net/lib/app/net_app.c: In function ‘_net_app_ssl_mainloop’:
include/logging/sys_log.h:96:20: warning: format ‘%zu’ expects
...
subsys/net/lib/app/net_app.c:2132:6: note: in expansion of macro
‘NET_ERR’
NET_ERR("could not skip %zu bytes",
^~~~~~~
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
- Changed define for SETTINGS_CONFIG_PAGE_SIZE from a hard coded value
to reference build system generated FLASH_ERASE_BLOCK_SIZE. This value
comes from 'erase-block-size' found in the dtsi file of devices.
- Modified nrf52840.dtsi to include definition for 'erase-block-size'
Fixes#7107
Signed-off-by: David Leach <david.leach@nxp.com>
This removes some tricky math to calculate lengths and offsets,
ensuring that, when appending the WebSocket UUID to the handshake
key, the key_accept buffer won't overflow.
Coverity-ID: 183057
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
Rewrite prepare_reply() to reduce unnecessary string copies and calls
to net_pkt_append_all(). Also reduces some of the tricky string length
calculations.
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
In an effort to reduce the footprint of the LwM2M client, let's
lower the default # of observes handled by the client from 20 to
10.
This saves ~640 bytes of SRAM.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Remove "used" member from observe_node structure and replace by
checking the ctx for non-NULL value.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The slist attr_list doesn't scale well when added to the LwM2M object,
object instance and resource instance structures. The goal of a
robust LwM2M client is to let the user create MANY object instances
and these will have many resource instances each. The amount of SRAM
taken up by the attr_lists will only increase over time, regardless
of the actual # of write attribute structures reserved via the
LWM2M_NUM_ATTR config setting.
Instead, let's remove the slist from these structures and add a
reference pointer to the lwm2m_attr structure. We can use this
reference to create the one to many relationship between the objects,
object instances and resource instances for a much smaller amount of
code and SRAM resources.
The sacrifice for these savings will be a larger # of iterations when
looking up assigned write attributes and matching them to their
references. However, due to the # of write attributes current being
handled, the # of iterations during this process is very manageable.
Example flash and SRAM savings when building for nrf52_blenano2:
Before patch:
Memory region Used Size Region Size %age Used
FLASH: 139532 B 512 KB 26.61%
SRAM: 36576 B 64 KB 55.81%
IDT_LIST: 148 B 2 KB 7.23%
After patch:
Memory region Used Size Region Size %age Used
FLASH: 139284 B 512 KB 26.57%
SRAM: 36000 B 64 KB 54.93%
IDT_LIST: 148 B 2 KB 7.23%
Summary: This patch saves ~248 bytes of flash and ~576 bytes of SRAM
for the typical configuration of LwM2M client in Zephyr.
NOTE: these values will vary by architecture.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
When any error is returned from update_attrs() in engine_add_observer()
an EINVAL is returned back to the caller. Let's return whatever error
code was generated in update_attrs() instead.
Also, add handling where previously errors were ignored.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
For code clarity, let's move notification_attrs structure to the top
of lwm2m_engine.c. While we're at it, we can re-order it's members
for memory alignment.
NOTE: This patch does not change the current flash or SRAM usage but
further additions to the notification_attrs structure could.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
The path member of the object instance and resource instance structures
can easily be removed to save several bytes per instance over the entire
LwM2M subsystem. So let's remove it.
Example savings when building for nrf52_blenano:
SRAM usage before patch: 37952 B
SRAM usage after patch: 36576 B
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
Let's optimize the order of the following structures to account for
memory alignment:
lwm2m_engine_obj
lwm2m_engine_res_inst
lwm2m_output_context
lwm2m_output_context
Tested building for nrf52_blenano hardware:
SRAM usage before patch: 38240 B
SRAM usage after patch: 37952 B
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
It's highly unlikely that snprintk() will return a negative value, but
that's a possibility that will make the `pos` variable be set to a
value outside the boundaries of the statically allocated `buf` array.
Also clamp writes to ensure that the statically allocated buffer won't
be overwritten with a large token length.
Fixes#7070.
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
In the future, when bootstrap support is added, this config won't
be used. Let's remove it.
Signed-off-by: Michael Scott <michael@opensourcefoundries.com>