Commit graph

1061 commits

Author SHA1 Message Date
Sebastian Bøe c2c8c849b6 cmake: Don't have users call zephyr_link_interface on mbedTLS
Libraries that use mbedTLS have been invoking
zephyr_link_interface(mbedTLS). It is not clear what the intent of
this code has been, but it is redundant with the mbedTLS build
scripts, so it can be safely removed.

In addition to being redundant, it causes problems as it introduces an
ordering dependency, with this code mbedTLS must be declared before
users of mbedTLS are declared. Since this code is redundant, this
ordering dependency is also unnecessary.

This code is believed to have been added early on by accident and
copied through cargo-cult programming since.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-05-11 08:35:26 -04:00
Jukka Rissanen e082d98911 net: sockets: can: Register handler for AF_CAN
Use the automatic registration of AF_CAN type sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen b3cd478a5f net: sockets: packet: Register handler for AF_PACKET
Use the automatic registration of AF_PACKET type sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen 61f4597d64 net: sockets: tls: Register handler for TLS sockets
Use the automatic registration of TLS socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen 89bf1578d9 net: sockets: Add a way to register a socket family handler
Allow automatic handling of registered socket families.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Paul Sokolovsky 22f1a29185 net: sntp: Add convenience API for one-shot SNTP query
sntp_simple() function queries the server (passed as "addr[:port]"
string). It wraps calls to a number of other functions, and may be
useful to write simple, concise apps needing the absolute time.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-10 13:44:32 +03:00
Paul Sokolovsky 426f3fa1ac net: socketutils: Add utils to manipulate network address strings
Two utils to manipulate addresses in format "addr[:port]". I.e.,
network address (domain name or numeric), optionally followed by
port number:

* net_addr_str_find_port(), to return pointer to port number
substring (or NULL if not present).
* net_getaddrinfo_addr_str(), which is effectively getaddrinfo()
wrapper taking a "addr[:port]" string as a parameter.

The header file is named socketutils.h to emphasize that these
utility functions are implemented on top of BSD Sockets API
(and other POSIX/ANSI C functions), and thus portable to other
POSIX systems (e.g., Linux), so can be used in apps testing
POSIX compatibility. More utility functions (beyond address
manipulation) can be added later.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-10 13:44:32 +03:00
Robert Lubos b8494d9a51 net: lib: mqtt: Enable blocking PUBLISH payload readout
It is convenient to have a blocking version of
`mqtt_read_publish_payload` function, for cases when it is called from
the event handler. Therefore, extend the 'mqtt_read_publish_payload'
argument list with information whether the call should block or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-07 22:08:30 -04:00
Jukka Rissanen 9a6bbbfb69 net: Check device driver API pointer
It is possible that the device driver API pointer is null.
For example if the device driver returns an error, the device
code will make the API pointer NULL so that the API would not
be used. This can cause errors in networking code where we
typically do not check the NULL value.

Fixes #15003

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-07 15:41:15 +03:00
Robert Lubos 7eb4a68876 net: openthread: Fix utilsFlashErasePage function
Zephyr implementation of OpenThreads utilsFlashErasePage platform
function did not disable flash protection before calling `flash_erase`
function. This resulted in an error instead of actual flash erase on
platforms that properly implement flash write protection.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-07 08:35:34 -04:00
Robert Lubos 57629724c2 net: openthread: Implement frame pending API
Implement OpenThreads frame pending bit management on top of the Zephyrs
radio driver API. This allows for proper Sleepy End Devices handling
from the parent side.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-06 10:58:04 -04:00
Luiz Augusto von Dentz c42707c2d3 Bluetooth: Use BT_GATT_SERVICE_DEFINE whenever possible
This makes use of BT_GATT_SERVICE_DEFINE to statically define services
for services that are not required to be dynamically registered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Håkon Øye Amundsen 66431d213d cmake: helper function for importing library
When importing a pre compiled imported library it is currently
required to perform three steps.
This commit introduces a helper function which allows the
user to import a library with a single function call.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2019-04-30 10:18:02 -04:00
Paul Sokolovsky f65727a193 net: sntp: Add sntp_query() function with fractional precision
Existing sntp_request() function has a coarse integer seconds
precision,  discarding fractional part as returned by SNTP.
Deprecate it, and instead introduce sntp_query() function which
returns both integer and fractional seconds as a newly introduced
structure sntp_tstamp.

Fixes: #15596

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-04-24 12:53:09 +03:00
Paul Sokolovsky e8e814c631 net: sntp: Handle case of request timeout
Previously, a case when poll() call timed out wasn't handled, and
recv() was called unconditionally. In the case of timeout, recv()
itself would hang indefinitely.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-04-24 12:50:12 +03:00
Jukka Rissanen 1897896e97 net: sockets: Make sure that getaddrinfo() cannot hang forever
If for some reason the DNS resolver callback is not called properly
then make sure that semaphore will not block forever.

Fixes #15197

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-11 18:01:08 -04:00
Michael Scott cb2bfcb9c0 net: lwm2m: fix periodic services handling
This fixes an issue where if timestamp == service_due_timestamp,
we don't call the periodic service.  Then the following call to
engine_next_service_timeout_ms() returns 0 because the service
is still due and lwm2m_engine_service() is called again.
This process repeats several times until the value of
k_uptime_get() changes and then the work is finally handled.

Previously, the resolution of k_uptime_get() was in ms.  A recent
change to this API defaults Zephyr so that the resolution is
set via CONFIG_SYS_CLOCK_TICKS_PER_SEC (default 100).

This means the value of k_uptime_get() only changes every 10ms.

Reported-by: Github User pieterjanc
Signed-off-by: Michael Scott <mike@foundries.io>
2019-04-10 13:54:23 -04:00
Michael Scott 42abfc6532 net: lwm2m: dont use system workqueue for services
"It's a Trap!" -- Admiral Ackbar

When moving to the BSD-socket APIs, the original thread running LwM2M
periodic services such as observes and lifetime updates, was replaced
with a re-occuring workqueue job.  To save the overhead of creating a
new thread, I used the system workqueue for these jobs.

This was a mistake.  If these jobs hit a semaphore or wait for some
reason, it cannot be prempted due to the priority of the system work
queue.

Let's instead add this service handling to the thread that we already
use for polling sockets.  This also removes a configuration issue where
the system workqueue stack size needed to be increased.  This can now
be adjusted via the LWM2M_ENGINE_STACK_SIZE knob.

Directly fixes semaphore usage in the socket-based DNS code.
This was introduced as a bugfix for non-responsive DNS server hanging
the Zephyr device forever.  However, this probably fixes randomly
seeming hangs on the device.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-04-10 13:54:23 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Andrew Boie ce6b80470d net: add missing syscall for gethostname()
We need all the socket APIs to work from user mode.
tests/net/socket/misc now runs in userspace.

Fixes: #15227

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-06 14:30:42 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Andrew Boie 7e3a34f84f mqtt: use sys_mutex instead of k_mutex
Allows the mqtt_client data structure to exist in user memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Tedd Ho-Jeong An f5c4e369ea net: sockets: Update setsockopt to handle IPV6_V6ONLY
This patch adds a routine that handles IPV6_V6ONLY option in setsockopt
function.

Fixes #14657

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-03-26 13:23:49 -04:00
Vincent Wan 3609e261bb net: sockets: move fcntl back to socket_offload.c
We are reverting the changes in commit
55b3f05932 given build errors are seen
when fcntl.h is included, as it declares fcntl() as a non-static
function. The same function cannot be declared as both static and
non-static.

Instead, we avoid redefining fcntl() in lib/os/fdtable.c specifically
for case of the SimpleLink family, til we have support for the new
socket_op_vtable.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-20 11:36:18 -05:00
Tomasz Bursztyka cf322c44db net: Switch usage of net_pkt_get_reserve to net_pkt_alloc
Some places were still using the old allocator. Using the new one does
not change any behavior. This will help to remove the useless data_len
attribute in net_pkt which legacy allocator was still setting.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 03bfc5dd0f net/context: Remove token parameter from net_context_send/sendto
And also to the relevant callbacks.

That parameter is not used anywhere so it is useless.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka a25f054cbd net/pkt: Remove _new suffix to net_pkt_read functions
Suffix is now useless, as these functions are now the only ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka f8a091104e net/pkt: Remove _new suffix to net_pkt_get_data_new function
Now that legacy - and unrelated - function named net_pkt_get_data has
been removed, we can rename net_pkt_get_data_new relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 172fe5a87b net/context: Remove _new suffix on net_context_send/sendto functions
Now that legacy functions are removew, let's rename the new functions by
removing the _new suffix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Paul Sokolovsky 4e097b4d54 net: sockets: recv_stream: Check that the underlying net_context active
It may be closed by the stack behind our back (something which needs
to be fixed).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-18 10:49:25 -05:00
Paul Sokolovsky 5499f38e7a net: socket: Increment TCP context refcount on socket(), accept()
TCP context is effectively owned by both application and the stack:
stack may detect that peer closed/aborted connection, but it must
not dispose of the context behind the application back. Likewise,
when application "closes" context, it's not disposed of immediately,
there's yet closing handshake for stack to perform.

This effectively means that TCP contexts have refcount of 2 when
they're created. Without this change, following situation is
possible: peer opens connection, an app get a context (or socket)
via accept, peer sends data, closes connection. An app still holds
a reference to connection, but stack may dispose of context, and
even reuse it for a new connection. Then application holds a reference
to either free, or completely different context.

This situation was very clearly and 100% reproducible when making
Zephyr port of open62541 library, which works in async manner using
select().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-18 10:49:25 -05:00
Paul Sokolovsky 193d6c60df net: sockets: Implement gai_strerror()
To save binary size, currently just returns textual name of error
code, e.g. EAI_FAIL -> "EAI_FAIL". Based on real usecases, can be
replaced with user-friendly message later. (Current usecase is to
allow/help to elaborate sockets API by proof-of-concept porting
existing socket apps).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-15 07:13:15 -05:00
Michael Scott 8c615e7ce3 net: lwm2m: handle delay_work error in lwm2m_engine_init()
Let's handle errors during periodic service work submit.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 579e586fa1 net: lwm2m: fix write_handler sizes for float32/64
Normally, this bug wasn't apparent as the value is type-casted
to a float32/64 type.  However, once we start persisting these
values they need the correct length.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 910506cfc1 net: lwm2m: guard obj_field parameter of LWM2M_HAS_PERM
Let's avoid future compile issues with this macro when passing
in a type-casted value that isn't surrounded by parenthesis.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott fcde4c42cc net: lwm2m: raise stack sizes
Occasionally we see a stack crash in LwM2M.  This may have been
due to the swap from net_app APIs to socket-based APIs.

Let's raise the default stack by 1k.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott d615ab0dc3 net: lwm2m: change resend packet to an INF message
To avoid missing important messages, let's change the resend
packet message from a DBG to an INF.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 144ff91670 net: lwm2m: cleanup observes when closing context
When a context is closed to a server, we should clean up any
existing observes along with it.  Otherwise these will try to fire
afterward.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 35eb7818a7 net: lwm2m: remove unnecessary check in sm_do_registration()
We are already in sm_do_registration(), there's no need to check
!sm_is_registered().  Either we are performing a full registration
or a registration update.  In both cases, sm_send_registration()
is called.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott a5a83675d4 net: lwm2m: correct status change on send_reg error
If an error is received during registration update, we need to reset
the status so that a full registration is performed.  This was
incorrectly being set to ENGINE_REGISTRATION_SENT.

The correct status should be: ENGINE_DO_REGISTRATION

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 2ab50cb676 net: lwm2m: Follow POSIX send() API
send() returns -1 upon error and sets errno appropriately.  Let's
not bother saving the return code and instead share errno back
to the user.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Kumar Gala 0033448f10 net: lwm2m: Fix minor bug with setting flags
Looks like we are setting some bit flags so we should use '|' not '||'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 16:28:58 -05:00
Jukka Rissanen 5a9fa72ef2 net: socket: can: Convert between can_frame and zcan_frame
The socket-can code expects to have "struct can_frame" from
application when it calls send(). We then have to convert to
"struct zcan_frame" as that is what the driver expects.

Same thing when receiving data. We just convert to
"struct can_frame" and pass that to application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-13 05:58:30 -05:00
Jukka Rissanen fc36d56aca drivers: can: socket: Use proper filter when setsockopt is called
Check that the received filter is can_filter type when setsockopt()
is called.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-13 05:58:30 -05:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Ulf Magnusson 214ef00db3 kconfig: subsys: net: Remove redundant dependencies
subsys/net/lib/lwm2m/Kconfig.ipso is 'source'd within an 'if LWM2M', in
subsys/net/lib/lwm2m/Kconfig, so the 'depends on LWM2M' is redundant.

The 'depends on NET_IPV4' and 'depends on NET_L2_OPENTHREAD' are within
corresponding 'if's in the same file.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 09:49:59 -05:00
Anas Nashif 4fcbb6bdf2 Revert "net: sockets: recv_stream: Check that the underlying net_context active"
This reverts commit 8cb5d083cb53627964ed72fb9fa3fb7a5219739f.

This was breaking tests on master due to missing dependency that is
still being reviewed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-06 17:40:52 -05:00
Paul Sokolovsky 41864915c2 net: sockets: recv_stream: Check that the underlying net_context active
It may be closed by the stack behind our back (something which needs
to be fixed).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-06 15:56:57 -05:00
Vincent Wan 55b3f05932 include: net: Move fcntl implementation into socket_offload.h
This is done to conform with how the rest of the socket APIs are
implemented during socket offload. Otherwise link error would
result due to the symbol being redefined in lib/os/fdtable.c.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-05 11:37:10 -05:00
Paul Sokolovsky a3cffb8e63 net: sockets: Trace socket/accept/close operations for debug logging
This is required to debug almost any issue with sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-05 08:28:25 -05:00
Paul Sokolovsky 5a44011e3b net: sockets: Add dummy impl for SO_REUSEADDR and TCP_NODELAY sockopts
These options are oftentimes used when implementing servers, and
thus required to port existing socket apps. These options are also
safe to just ignore, e.g. SO_REUSEADDR has effect only for repeated
recreation of server socket (not an expected usecase for a Zephyr
app), while TCP_NODELAY is effectively the default for Zephyr, as we
don't implement TCP buffering (aka Nagle algorithm).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-01 09:52:15 +01:00
Michael Scott 0482b66f0b net: lwm2m: fix json NULL deref / code flow in read_number()
Per Coverity report, we are assigning the value1 and value2
s64_t pointers a value of 0.  Later when we go to use value1
and value2, they are of course ... NULL.

Fix the typos in the initial assignment of 0 to the
references of value1 and value2.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/13867
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/13882

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-01 09:44:46 +01:00
Jukka Rissanen a6614a32c1 net: sntp: Remove useless comparison
The LI bits checks is useless as the bitshifted value cannot be
larger than SNTP_LI_MAX (3).

Coverity-CID: 190924
Fixes #13888

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-28 08:47:10 -06:00
Michael Scott cc1b6b024b net: lwm2m: fix json formatter putchar check
Found via Coverity CID 191001: Control flow issues  (NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true:
"put_char(out, '}') < 0U".

Let's fix this check to be less than 1 instead as it should have
been originally.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-27 08:36:12 -06:00
Ravi kumar Veeramally f940cec0d0 net: coap: Fix coverity issue
To get u8_t value, just right shift the operands are enough.

Fixes #12298
Coverity-CID: 190635

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-27 10:36:39 +01:00
Robert Lubos 10e43e12ed net: sockets: tls: Add missing poll descriptor increment
Poll descriptor was not incremented in poll update function in case it
was reported as not ready. In result, poll could end up processing the
same poll descriptor for every fd requested to monitor.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-26 02:07:11 +01:00
Robert Lubos 6175d1bd8e net: sockets: tls: Detect EOF in poll prepare
Rework detection of EOF on a socket, so that it can be detected in a
poll prepare that socket is in in a EOF state and poll can return
immediately.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-26 02:07:11 +01:00
Tomasz Bursztyka 87eb552dd2 net/dns: Switch mdns responder to new net_pkt API
Unfortunately, most of the dns pack/unpack code is not factorized, and
mdns responder rewrites its own functions to write dns hdr, query,
answer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka 7bc61c1366 net/dns: Switch llmnr responder to new net_pkt API
Unfortunately, most of the dns pack/unpack code is not factorized, and
llmnr responder rewrites its own functions to write dns hdr, query,
answer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka 675a5056ed net/dns: Switch to new net_context API
So instead of building the net_pkt by itself, dns will pass its message
buffer to net_context_sendto_new(), which in turn will build the net_pkt
relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka f72b113876 net/dns: Move function declaration after macros and local variables
dns_write was in the middle of this, let's just move it to a more
relevant place so we logically have macros, then local variables then
functions.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka 46cefe9155 net/dns: Move common macros in the relevant header
Some of dns_pack.c macros are also used in resolve.c, so let's just put
the macros in dns_pack.h

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Michael Scott f68d62bbdb net: lwm2m: fix float exponent after fraction assign
Once the fraction value has been assigned a value, we can't move
the exponent any more.

Fixes erroneous values the binary32/64 formats.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-26 01:45:51 +01:00
Robert Lubos f1920fff46 net: sockets: tls: Block DTLS client in poll until handshake is complete
When DTLS client was added to `poll` before/during the handshake, it
could throw errors and in some circumstances (when polling thread was
cooperative and had higher or equal priority to the handshake thread)
could lead to a deadlock in the application.

Prevent that, by blocking on handshake semaphore instead of fifo. Poll
will start using fifo for data poll only after handshake is complete.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Robert Lubos 64ca76f327 net: sockets: tls: Use semaphore to notify that handshake is complete
Instead of simple bool value, use a semaphore to notify that TLS
handshake is complete. This way, we can monitor this value with k_poll.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Robert Lubos f8502a9993 net: lwm2m: Remove misused errno check
Errno value is only significant when `recvfrom` function indicated an
error (by returning -1). We should not depend on it's value if no error
is notified.

As the return value of `recvfrom` is already checked, misused errno
verification can simply be removed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Paul Sokolovsky 87b5eb9fce net: sockets: Implement getnameinfo()
This function is the opposite of getaddrinfo(), i.e. converts
struct sockaddr into a textual address. Normally (or more
specifically, based on the flags) it would perform reverse DNS
lookup, but current implementation implements only subset of
functionality, by converting to numeric textual address.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-19 17:34:57 -05:00
Paul Sokolovsky f7169ec216 net: sockets: Fix logging message
A debug message told "Set EOF flag on pkt %p", but actually printed
net_context instead of net_pkt.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-19 17:33:44 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Michael Scott 844c2ad716 net: lwm2m: fix NULL deref in plain_text_read_number()
Per Coverity report, we are assigning the value1 and value2
s64_t pointers a value of 0.  Later when we go to use value1
and value2, they are of course ... NULL.

Fix the typos in the initial assignment of 0 to the
references of value1 and value2.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12300
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12296

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott f6b221699c net: lwm2m: fix out-of-bounds access in put_s8()
Per Coverity report, oma_tlv_put() does pointer arithmetic accessing
the data as an array of u8_t.  In put_bool() we get a singleton
pointer from the evaluation of: "value != 0 ? 1 : 0" which is
passed to put_s8() which in turn passes it to oma_tlv_put().

To avoid misinterpretation, let's create a temporary s8_t variable
to pass into oma_tlv_put instead.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12312

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott 95f21d59b7 net: lwm2m: remove checks for long int > MAX_INT
Per Coverity report, the evaluation of long int v > MAX_INT is
always false and considered a CONSTANT_EXPRESS_RESULT issue.

Removed these checks from:
atof32()
lwm2m_write_attr_handler()

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12317
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12320

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Paul Sokolovsky 3b73511153 net: sockets: Add dummy shutdown() implementation.
shutdown() itself is described as just marking RX or TX path of a
socket as not available. For the first approximation, we implement
it just as a dummy function, to allow build existing POSIX
applications which use it.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-13 07:00:51 -06:00
Michael Scott 91ef79539a net: lwm2m: fix rendering of zero value float32/64
Zero is a special value in the binary32/64 format.  It has all zero
bits (sign=0, exponent=0 and fraction=0).

Handle this special case explicitly instead of trying to encode
in binary format which results in an incorrect value of 0.5.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 07:00:33 -06:00
Michael Scott cf47c89971 net: lwm2m: add support for IPSO Timer object
Initial implementation of IPSO Timer object #3340
Based on: http://www.openmobilealliance.org/tech/profiles/lwm2m/3340.xml

"This IPSO object is used to time events and actions, using patterns
common to industrial timers. A POST to the trigger resource or On/Off
input state change starts the timing operation, and the timer
remaining time shows zero when the operation is complete. The
patterns supported are One-Shot (mode 1), On-Time or Interval
(mode 2), Time delay on pick-up or TDPU (tmode 3), and Time Delay
on Drop-Out or TDDO (mode 4). Mode 0 disables the timer, so the output
follows the input with no delay. A counter is provided to count
occurrences of the timer output changing from 0 to 1. Writing a value
of zero resets the counter. The Digital Input State resource reports
the state of the timer output."

NOTE: Only One-Shot Mode (mode 1) is implemented in this patch.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-12 21:19:49 -05:00
Michael Scott d53a0855a1 net: lwm2m: fix float32/64 handling
During the initial work on LwM2M, the float32/64 code was
basically stubbed out.  Float32 sent only whole values and
float64 was completely broken.

Let's clean up the OMA TLV formatting code by moving the float
processing code into a separate file: lwm2m_util.c.

Then using public definitions for binary32 and binary64, let's
fix the processing code to correctly fill the float32_value_t
and float64_value_t types.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-12 21:19:49 -05:00
Tomasz Bursztyka 34fe5545c9 net/socket: Use the new net_pkt API to read TCP payload
There is no need for appdata pointer: net_pkt's cursor is already at the
right position, i.e. the beginning of the payload right after all IP/TCP
headers.

Also, when reading the actual data, let's use net_pkt_read_new()
relevantly instead of going through the buffer by ourselves.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 6331f052b7 net/socket: Use the new net_pkt API to read UDP payload
There is no need for appdata pointer: net_pkt's cursor is already at the
right position, i.e. the beginning of the payload right after all IP/UDP
headers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 024a7e0502 net/sockets: Adapt net_pkt_get_src_addr to new net_pkt API
This function is only used in sockets, thus making it a private function
of socket library and renaming it relevantly.

Note that sockets should be reviewed at some point to avoid using such
function: zsock_received_cb() already get the ip header and the protocol
header, so it could grab the src addr/port from there. It would be way
more optimized to do so, since net_pkt_get_src_addr is costly as it
parses all over again the ip/protocol headers.

utils unit test is updated and the test of the former
net_pkt_get_src_addr/net_pkt_get_dst_addr are removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Paul Sokolovsky a46aadeff2 net: sockets: Properly handle EOF condition for poll()
If a socket is in EOF, it's readable (so client can read() it, get 0
in return, figure it's in EOF, and close it). Without this change, we
had peer-closed sockets leaked (ignore) by poll() and select().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-12 09:45:04 -05:00
Kumar Gala abeed4ab74 net: lib: Remove CONFIG_HTTP reference
CONFIG_HTTP isn't a Kconfig symbol so remove reference to it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-11 22:29:58 -05:00
Kumar Gala 22253fcf6d openthread: Convert FLASH_ERASE_BLOCK_SIZE to DT_
Use DT_FLASH_ERASE_BLOCK_SIZE prefixed defined instead of
FLASH_ERASE_BLOCK_SIZE as the non-DT version is deprecated.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 22:39:07 -06:00
Jukka Rissanen 7f784153c1 net: socket: Dispatch all AF_CAN handling to sockets_can.c
The code was unnecessarily checking protocol for AF_CAN.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Jukka Rissanen c1d5cc26c1 net: sockets: Remove extra "default n" setting from config
No need to say "default n" as that is the implicit default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Tomasz Gorochowik df0d7652df net: mqtt: Add SOCKS5 proxy support
This commits adds a new MQTT transport. The purpose is to be able to
connect to a MQTT broker through a SOCKS5 proxy.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-02-08 14:20:44 +02:00
Tomasz Gorochowik ead249f2f9 net: Add initial SOCKS5 support
This adds some very basic SOCKS5 proxy client support.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-02-08 14:20:44 +02:00
Andrei Gansari fea80ca5c1 net: subsys: fixed comments CONFIG_NET*
Fixed stranded comments:
CONFIG_NET_TLS_DEBUG removed
CONFIG_NET_LLDP_MSG_TX_INTERVAL -> CONFIG_NET_LLDP_TX_INTERVAL

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2019-02-08 13:57:55 +02:00
Paul Sokolovsky 5bb2c7022e net: sockets: Add gethostname() call
Implemented via Zephyr's net_hostname_get(). As support for that call
is configurable and by default off, while many POSIX applications
assume that hostname is always available, we need a default value
in case CONFIG_NET_HOSTNAME_ENABLE is "n". Initial version of this
patch added that on the level of gethostname() call, but of was
suggested to move that down to net_hostname_get() instead.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-08 10:39:30 +02:00
Jukka Rissanen df7162331f net: socket: can: Add getsockopt() and setsockopt() support
It is possible to set the filter in user application and that
information is passed to the CANBUS device driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen f610db9453 net: l2: Add CANBUS L2 layer
This is basically a dummy layer that just passes data through.
It is needed so that we can create CANBUS type network interface
to the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen 49cea0a199 net: socket: can: Add socket CAN support
This allows user to create a CAN socket and to read/write data
from it. From the user point of view, the BSD socket CAN support
works same way as in Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Ravi kumar Veeramally a9a2b3ea91 net: sockets: Add socket api to support AF_PACKET
This commit adds packet socket support to socket api.
This version supports basic packet socket features.
Protocol family is AF_PACKET, type of socket is
SOCK_RAW and proto type is ETH_P_ALL. The user will
receive every packet (with L2 header) on the wire.
For TX, the subsystem expects that the user has set
all the protocol headers (L2 and L3) properly.

Networking subsystem doesn't verify or alter the headers while
sending or receiving the packets. This version supports packet
socket over Etherent only. Also combination of other family
and protocols doesn't work (i.e. Application can not open
packet-socket and non packet-socket together).

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Michael Scott 6cb768cb24 net: lwm2m: fix connection handling in RD client
A few cases were missed where we weren't cleaning up the existing
connection correctly.  This was easily missed because we try and
clean up the connection everywhere.

Instead, let's clean up any existing connection prior to starting
a new one in the do_bootstrap_reg() and do_registration()
functions.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-06 18:52:31 -05:00
Michael Scott 6b990ba9bf net: lwm2m: boostrap support cleanup
- Fix enum naming throughout
- Correct next_instance logic
- Move to registration server if no bootstrap server is found
- Fixes to logging

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-06 18:52:31 -05:00
Robert Lubos 418b9236fa net: lib: mqtt: Get rid of _sock suffix
As the legacy library has been removed, we no longer need to
differentiate betwen MQTT implementations. Therefore align the library
folder name with other libraries and remove the `_sock` suffix.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-05 11:05:26 -05:00
Ravi kumar Veeramally 1e47f26d1c net: coap: Remove legacy CoAP implementation
As we are removing net_app and net_pkt based libraries and
applications, CoAP legacy based libraries and apps are moved
to socket based implementations. So removing legacy CoAP.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-04 16:49:59 -05:00
Jukka Rissanen 6b3428c7e4 net: Remove net_app references from the code
Some net_app names were not removed by net_app API removal
commit so remove them here.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 19:05:56 -05:00
Tomasz Bursztyka 4b78a251d7 net/context: Make recv_cb providing the ip and protocol headers
If status is 0, both ip_hdr and proto_hdr will own a pointer to the
relevant IP and Protocol headers. In order to know which of ipv4/ipv6
and udp/tcp one will need to use respectively net_pkt_family(pkt) and
net_context_get_ip_proto(context).

Having access to those headers directly, many callbacks will not need
to parse the packet again no get the src/dst addresses or the src/dst
ports. This will be change after this commit.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 083470a14a net/sockets: Use the new send/sendto from net_context
It's now up to net_context to build the net_pkt and send it.
This will become the default.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Jukka Rissanen d1162600e9 net: app: Remove net-app API files
The net-app API is removed. Users should use the BSD socket API
for application development.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 12:29:21 +02:00
Michael Scott a79087cad1 net: lwm2m: add socket-based DNS support
Previously, the net_app layer handled DNS support as a part of
network initialization.  With the move to BSD-socket APIs,
we need to add support for DNS to the LwM2M library.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d1cb39e7ce net: lwm2m: migrate LwM2M library to BSD-sockets API
This commit removes the net_app layer from the LwM2M library and
replaces it with BSD-sockets APIs.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d7f20f63d8 net: lwm2m: fix firmware status after bad download attempts
This commit resets the firmware status to IDLE after a bad
download attempt.  Previously, the firmware object would stay
in an odd state and any further attempts to download firmware
would return an error.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 0abe96e4cf net: lwm2m: replace periodic service thread with work queue
We can save some resources by removing the periodic service thread
and replacing it by queuing the services to the work queue.

Before (reel_board using BT + DTLS)
Memory region         Used Size  Region Size  %age Used
           FLASH:      289464 B         1 MB     27.61%
            SRAM:       75620 B       256 KB     28.85%
        IDT_LIST:         136 B         2 KB      6.64%

After
Memory region         Used Size  Region Size  %age Used
           FLASH:      289576 B         1 MB     27.62%
            SRAM:       74596 B       256 KB     28.46%
        IDT_LIST:         136 B         2 KB      6.64%

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 180a365d2f net: lwm2m: support for LwM2M bootstrap
Now that the security data can be loaded into and used from the
security / server objects, we can add support for LwM2M bootstrap.

This is a mode where initially a connection can be made to a server
which can update several LwM2M (including security and server
data) and then trigger a "bootstrap complete".  Once this happens
the client will start it's connection process over but now with
the new information.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 54c10c04e5 net: lwm2m: use security data for connections
In order to support bootstrap mode, we need to store server data
in the security / server objects.  Once the connection to the
bootstrap server is made, it will clear these objects and add
new server connection data.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 3ef993c88e net: lwm2m: update security obj with DTLS data
For bootstrap support, we need to store connection credentials
in the security object.  This way the client can start a connection
at index 0 and after bootstrapping, move to the next connection.

Let's add the needed fields and a config item to set the key length.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 181544beec net: lwm2m: add JSON formatter for WRITE operations
Update the parsing functions for JSON used by the JSON data
formatter and enable it in the LwM2M engine.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 26599e30d4 net: lwm2m: introduce input formatter private data
The JSON formatter is currently not enabled for incoming WRITE
operations.  To update the code in the formatter and not litter
the input context with extra data, let's allow formatters to
store their own user data.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott a433af6e05 net: lwm2m: save remote address during setup
net_app contexts save the remote address and we use this during
observe notifications and pending handling.  If we move to another
network layer such as sockets, then the remote address becomes
harder to reference.  Let's save it as a part of the client
context.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 3bfb7debb3 net: lwm2m: move to flat buffers
As part of the migration from net_app APIs to socket APIs, let's
stop referencing the net_pkt fragments throughout the LwM2M library.

Establish a msg_data flat buffer inside lwm2m_message and use that
instead.

NOTE: As a part of this change we remove the COAP_NET_PKT setting.
The COAP library reverts to COAP_SOCK behavior.

This doesn't mean we use sockets in LwM2M (yet), it only means we
use the socket-compatible COAP library which parses flat buffers
instead of net_pkt fragments.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d003910460 net: lwm2m: create DTLS config layer for LwM2M
Currently, this will select the needed configs for LwM2M and net_pkt.
During the migration to socket APIs, the net_pkt selections will change
to socket-based selects.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Aurelien Jarno 4394601524 net: sntp: get rid of the callback function
The original SNTP client library was designed for the net-app API, for
which it makes sense to have a callback function, which is called
asynchronously when an answer is received.

For the socket based interface, the callback is called just before
sntp_request() returns. It gets the status and the epoch_time in
parameter, however the status is already returned by sntp_request(). It
therefore make sense to replace the callback function by a pointer to
epoch_time.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-31 10:14:12 +02:00
Robert Lubos e0a44c388c net: openthread: Bump OpenThread commit to f9d757a1
This version has cli_console backend fixed, hence no longer crashes on
`ot ping` command.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-30 21:01:53 -05:00
Michael Scott 8a115ca556 net: lwm2m: remove some unnecessary includes
net/lwm2m.h is included by object.h

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 44e9b5ed44 net: lwm2m: refactor lwm2m_engine_context into lwm2m_message
The relationship between lwm2m_engine_context and lwm2m_message
has always been a tenuous one.  Let's merge the 2 structures
into lwm2m_message and remove all of the extra stack variables.

This change increases SRAM usage slightly due to the
addition of the context structures to the multiple lwm2m_messages.
However, the way lwm2m_engine_context was being used off the stack
was probably creating hard to debug issues in the longterm.

Also, having all of the structures in 1 place makes sharing them
much easier later.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 86728d849b net: lwm2m: fix unsigned check for <0 in LwM2M device obj
Reported by Github user himanshujha199640 using coccinelle:
subsys/net/lib/lwm2m/lwm2m_obj_device.c:172:5-16:
WARNING: Unsigned expression compared with zero.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/11135

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 0ee0773abd net: lwm2m: remove unused CONFIG_NET_CONTEXT_NET_PKT_POOL config
CONFIG_NET_CONTEXT_NET_PKT_POOL is used by Zephyr's TCP stack as
a way of keeping the original packet data when compression and
other l2 specific actions make the data unusable for retries.

LwM2M uses UDP and this option was never used.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Ravi kumar Veeramally f51cebeea2 net: sntp: Rework SNTP client library to use sockets
As networking libraries and protocols are moving to socket
based implementation, reworked SNTP client library to use sockets.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-01-29 12:25:01 -05:00
Jukka Rissanen 581261334c net: mqtt: Remove legacy MQTT library
The old and deprecated net-app based MQTT library is removed.
See the BSD socket based MQTT library for a replacement.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-29 07:11:23 -05:00
Paul Sokolovsky 3e6d7d382a net: sockets_select: Fix build without CONFIG_NET_SOCKETS_POSIX_NAMES
The implementation code itself should not rely on plain POSIX names
and use zsock_ and ZSOCK_ prefixed versions of symbols.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-29 09:19:54 +02:00
Jukka Rissanen 4043909d69 net: http: Remove HTTP client and server APIs
The old legacy APIs use net-app library and as that is being
removed, then the dependencies need to be removed also.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-25 11:21:20 -05:00
Jukka Rissanen 1cba0161ed net: websocket: Remove the websocket as HTTP APIs are removed
Remove the experimental websocket code as it uses HTTP APIs
which are being removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-25 11:21:20 -05:00
Paul Sokolovsky 9c91094ff7 net: sockets: select: Get rid of timeval in favor of zsock_timeval
struct timeval is per POSIX defined in sys/time.h, but that also
allowed to pull sys/select.h (and indeed, it does with native_posix),
which then starts to conflict with out select implementation (if
NET_SOCKETS_POSIX_NAMES is defined, and many samples/tests have it).

So, for now follow the existing route of duplicating all definitions
needed by our code in namespaced manner. Things like struct timeval
usage will need to be revisited later, when we'll want socket
subsystem to work with POSIX subsystem, but that's a separate deep
matter.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Paul Sokolovsky 3a0a9944c0 net: sockets: Implement select() call.
It's implemented on top of poll() anyway, and the current
implementation of fd_set uses array of fd's underlyingly, which
leads to O(n) complexity for FD_SET() and friends.

The purpose of select() implementation is to allow to perform
proof-of-concept port of 3rd-party code to Zephyr quickly. For
efficiency, poll() should be used instead.

Fixes: #11333

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Robert Lubos 0b93c68f79 net: sockets: Add fcntl to socket offloading API
Offload fcntl calls through socket offloading API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 17:25:01 +02:00
Paul Sokolovsky c885cb533e net: buf: linearize: Get rid of useless memset()
net_buf_linearize() used to clear the contents of output buffer,
just to fill it with data as the next step. The only effect that
would have is if less data was written to the output buffer. But
it's not reliable for a caller to rely on net_buf_linearize() for
that, instead callers should take care to handle any conditions
like that themselves. For example, a caller which wants to process
the data as zero-terminated string, must reserve a byte for it
in the output buffer explicitly (and set it to zero).

The only in-tree user which relied on clearing output buffer was
wncm14a2a.c. But either had buffer sizes calculated very precisely
to always accommodate extra trailing zero byte (without providing
code comments about this), or arguably could suffer from buffer
overruns (at least if data received from a modem was invalid and
filled up all destination buffer, leaving no space for trailing
zero).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-12 15:24:29 -06:00
Martin Schwan c5de716af4 net: mqtt: Fix typo "seg_tag_list"
Fix a typo in the mqtt_sec_config struct where it was "seg_tag_list"
instead of "sec_tag_list".

Signed-off-by: Martin Schwan <m.schwan@phytec.de>
2019-01-10 11:30:33 +02:00
Paul Sokolovsky 3329eb2c4e net: pkt: net_frag_linearize: Make consistent with net_buf_linearize
net_frag_linearize() is just a wrapper for net_buf_linearize(). As
the latter was refactored to never return error, and instead just
return actual copied length, update the former and its usages too.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-08 11:06:56 +02:00
Aurelien Jarno e98e6a8a87 net: openthread: remove one subcommand level in shell
Currently OpenThread commands have to be prefixed in the shell by "ot
cmd", for example "ot cmd state". With the new shell, it is possible to
remove one subcommand level and change it to "ot state".

At the same time validate the number of arguments using
SHELL_CMD_ARG_REGISTER and improve the help message.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-07 11:19:24 +01:00
Aurelien Jarno ac3ff65a91 net: openthread: improve shell output
Following the introduction of the new shell, the OpenThread shell
wrapper is not well integrated. It outputs the answer to a command using
printk(), which is not necessarily using the same device than the shell
if "zephyr,console" does not match "zephyr,shell-uart".

OpenThread calls the otConsoleOutputCallback() function to output the
answer to the shell. It can provide a callback argument, but defined
when OpenThread is initialized, not when the command is submitted.
Workaround that by taking a copy of the shell argument in a static
variable and use it for the call to shell_fprintf(). It is not perfect
if two or more shells issue concurrent commands, but is already an
improvement compared to printk().

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-07 11:19:24 +01:00
Aurelien Jarno d3b6c5a755 net: coap: return -EPERM for a resource without requested method
When walking through the coap resources in coap_handle_request, return
-EPERM if a resource exists but does not have the request method. This
allows the caller to catch the error and return a 4.05 message.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-02 13:04:46 +01:00
David B. Kinder 06d78354ae doc: regular misspelling scan
Fix misspellings in documentation (.rst, Kconfig help text, and .h
doxygen API comments), missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-12-26 13:27:14 -05:00
Martin Turon 6410a16adb openthread: Update openthread version to latest upstream/master.
Update zephyr integration of openthread to latest api as of 2018-12-17:

2a75d30684

Both echo_server and echo_client compile and are operational.

Signed-off-by: Martin Turon <mturon@google.com>
2018-12-20 12:24:51 +01:00
Robert Lubos e8620e2cca ext: mbedtls: Unify mbedTLS Kconfig prefixes
Currently there is a mixed approach in prefixes from mbedTLS
configuration (MBEDTLS_ and TLS_). The latter was used in generic config
file and could bring up confusion that it can only be used with TLS
subsystem. Hence unify the approach to MBEDTLS_ prefix to avoid such
confusion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-17 11:27:02 +01:00
Tomasz Bursztyka e97a543e9b net/pkt: Remove parameters to "reserve" some headroom
Such parameter is not used anymore, it was defaulted to 0 previously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Paul Sokolovsky 8a65f68a48 net: sockets_tls: Typo fix in comment
s/DLTS/DTLS.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 13b38ed686 lib: fdtable: Change ioctl vmethod signature to take va_list
As extend fdtable usage to more cases, there regularly arises a need
to forward ioctl/fcntl arguments to another ioctl vmethod, which is
complicated because it defined as taking variadic arguments. The only
portable solution is to convert variadic arguments to va_list at the
first point of entry from client code, and then pass va_list around.

To facilitate calling ioctl with variadic arguments from system code,
z_fdtable_call_ioctl() helper function is added.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 94007da116 net: sockets: Rework fcntl() dispatching to the underlying fd object
fcntl operations are implemented using ioctl vmethod.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Robert Lubos ee0b61fff8 net: sockets: Rework poll to support ioctl helper commands
This commit reworks socket poll implementation to support multiple
socket implementations.

To achieve that, two ioctl poll helper requests were added:
ZFD_IOCTL_POLL_PREPARE and ZFD_IOCTL_POLL_UPDATE. The poll
implementation calls ioctl with these requests for each socket
requested in the fds table.

The first request is responsible for preparing k_poll_event objects
for specific socket. It can request to skip waiting in k_poll by
returning EALREADY through errno.

The latter request is responsible for processing outcome of k_poll for
each socket. It can request to retry the k_poll by returning EAGAIN
through errno.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos 31ab8d061d net: sockets: tls: Implement vtable for TLS sockets
Implement extended socket vtable for TLS sockets, therefore allowing to
integrate the implementation with socket subsystem.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos df8693af64 net: sockets: Extend socket vtable
This commit extends socket vtable, allowing to redirect socket calls to
alternate implementations (e.g. TLS sockets).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Jakub Rzeszutko e0be6a10b3 shell: printing command's help by shell engine
Removed printing command help from help handler. It is now
realized by the shell engine. This change saves a lot of flash
but still allows to print help in command handler with function
shell_help_print.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Jukka Rissanen 88d3a0a88f net: config: Enable syslog to network in init
Start to send syslog messages to net after we have a proper
IP address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-04 15:55:53 -05:00
Robert Lubos b5f9771252 net: mqtt: Fix NULL pointer dereference in logs
MQTT packet_length_encode function accepts NULL buf argument, therefore
it cannot be dereferenced without a check.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-28 13:09:46 -08:00
Robert Lubos a26db60b2f net: mqtt: Add missing mutex_unlock
mqtt_connect was not releasing mutex after successfull connection.
Reworked the code to have a single exit path with mutex unlock.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-28 13:09:46 -08:00
Himanshu Jha 36279b69a8 net: lwm2m: ipso_temp_sensor: remove unnecessary variable
Remove an unnecessary local variable to store the
return value, instead return directly thereby saving
few bits of memory.

Found using Coccinelle.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 11:54:01 -08:00
Himanshu Jha a273cfaf32 net: lwm2m: ipso_light_control: remove unnecessary variable
Remove an unnecessary local variable to store the
return value, instead return directly thereby saving
few bits of memory.

Found using Coccinelle.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 11:54:01 -08:00
Himanshu Jha 547e75723c net: llmnr_responder: Check return value of net_udp_get_hdr
net_udp_get_hdr() function returns NULL on failure. Therefore
handle its return value to avoid potential NULL dereference.

Fixes #11485
Coverity-CID: 189738

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 19:20:04 +02:00
Jukka Rissanen 4770528018 net: app: Remove extra log_strdup() calls
The _net_app_sprint_ipaddr() was calling log_strdup() when
creating the debug print string. This is not correct as
the log_strdup() can only be used when calling the logging macro
to print strings.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-28 14:25:25 +02:00
Gil Pitney c51cf1e463 drivers: wifi: simplelink: Implement setsockopt() for TLS offload
Implements setsockopt() for the socket offload driver
to process the TLS tags sent in via the Zephyr setsockopt() API,
when CONFIG_NET_SOCKETS_SOCKOPT_TLS is chosen.
For each tag, the credential filenames are retrieved and
set via SimpleLink's sl_SetSockOpt() API.

Also, creates a new KConfig option for TLS_CREDENTIAL_FILENAMES.
This new option is used by apps/protocols to add TLS credentials
via filenames referring to the actual content stored on a secure
file system or flash.

Handles the IPPROTO_TLS_* socket protocol families in the
socket() offloaded API.

This was validated on the cc3220sf_launchxl with the http_get sockets
sample, with the globalsign_r2.der file loaded to secure flash via
the TI Uniflash tool, and using the TI Catalog of known good
root CA's.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-11-23 09:16:21 -05:00
Ravi kumar Veeramally 19c598f081 net: coap: Deprecate net_pkt based CoAP library
Deprecating net_pkt based CoAP library due to Socket based
CoAP library.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-22 09:08:46 -05:00
Anas Nashif 3d906dc4c1 net: coap: Move both CoAP implementations into one Kconfig
Two separate folders and Kconfig options causing confusion on
CoAP and CoAP_SOCK implementations. This patch simplifies it.
Current CoAP Kconfig option moved to COAP_NET_PKT.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-22 09:08:46 -05:00
Michael Scott 70b9e7bab6 net: lwm2m: handle pending before send in retransmit
When resending data, we need to always check pending status first.
If the pending check returns an "expired" status, avoid sending the
data to L2 network driver entirely.

This change fixes a use after free issue, where the L2 network driver
was still handling a packet that was expired out from under it when
the pending status was checked.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 144cfce42a net: lwm2m: firmware_pull: don't use pending pkt for token
During firmware transmit timeout, we rely on the pending packet data to
reconstitute the token and token length.  At this point the pending
structure may be cleared out due to multiple retries.  To avoid getting
a zero token, let's use the token data from the original msg structure
instead.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 64c03819ec net: lwm2m: don't use pending pkt on retransmit error
We are using msg->cpkt.pkt as the net_pkt pointer in the call to
net_app_send_pkt().  Let's keep the code clean and not expose
ourselves to "out of order" issues, by also using msg->cpkt.pkt
in the error handling unref call.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 547e449f98 net: lwm2m: remove extra ref/unref in retransmit
During the retransmit cycle we take ref on the outgoing packet,
only to immediately unref it.  Originally, this was to make sure
the net_context handling didn't get rid of the packet when
sendto() is called.  But after checking, the ref counter is never
in danger of going to 0 at this point in the code, so the
added ref handling is useless.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Marti Bolivar 1cd137c393 net: lwm2m: increase IPSO light object color size
Add some extra space to the color resource buffer, to allow more
exotic and application-specific color spaces.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-21 12:30:42 -05:00
Paul Sokolovsky 2e21a95fd4 net: sockets: zsock_close: Be sure to free file descriptor
File descriptor I freed automagically when using POSIX subsystem's
close() function, but any subsys-adhoc functions like zsock_close()
should do that explicitly.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-20 11:25:17 +01:00
Robert Lubos d2a397bcf8 net: mqtt: Add TLS socket transport
Add TLS transport to socket MQTT implementation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00
Robert Lubos 37563a92d5 net: mqtt: Add BSD socket implementation
Add new, socket based MQTT implementation, based on MQTT from Nordic
nRF5 SDK, introducing the following features:

* transport independent MQTT logic, with support for multiple transports
* support for multiple MQTT versions (3.1.0 and 3.1.1 supported)
* single event handler - no need to keep callback array in RAM
* automatic send of Ping Requests, for connection keep-alive
* message/event parameters wrapped into strucutres - easier extension
  for future MQTT versions
* no separate thread needed to run MQTT - application only needs to call
  mqtt_input and mqtt_live periodically

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00
Robert Lubos f50aa6d3fb net: mqtt: Mark existing implementation as legacy
Rename existing headers and sybols to mqtt_legacy, to allow new
implementation to keep old config and header names.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00
Robert Lubos 824d0bd854 sockets: tls: Use FD table to reach net_context
With FD table introduction, net_context can no longer be reached by
typecasting socket descriptor. Instead, file descriptor API have to be
used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-15 17:54:40 -05:00
Robert Lubos 72958f2e1c sockets: tls: Fix getsockopt/setsockop return value
ztls_setsockopt and ztls_getsockopt returned error codes instead of
setting errno in particular cases. This commit fixes it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-15 17:54:40 -05:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Krzysztof Chruscinski 97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Paul Sokolovsky 8f690e291b lib: fdtable: FD method tables should be const.
FD method tables contain function pointers, and thus should be
const and reside in ROM. This patch fixes all cases of FD vtable
definitions: for POSIX FS API and for sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-08 09:47:46 -08:00
Paul Sokolovsky f750ce56ce net: lib: sockets: Switch to use fdtable
Previously the "socket file descriptors" were just net_context
pointers cast to int. For full POSIX compatibility and support
of generic operations line read/write/close/fcntl/ioctl, the
real file descriptors should be supported, as implemented by
fdtable mini-subsys.

Socket implementation already has userspace vs flatspace dichotomy,
and adding to that ptr-fds vs real-fds dichotomy (4 possible cases)
is just too cumbersome. So, switch sockets to real fd's regardless
if full POSIX subsystem is enabled or not.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Jukka Rissanen cf063fe85b net: Rename net_is_xxx...() functions to net_xxx_is...()
Unify the function naming for various network checking functions.

For example:
     net_is_ipv6_addr_loopback() -> net_ipv6_is_addr_loopback()
     net_is_my_ipv6_maddr() -> net_ipv6_is_my_maddr()
etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 14:52:33 -04:00
Andrei Emeltchenko 62f3f8e92a net: llmnr_responder: Fix uninitialized use Warning
Fixes following warning:
...
subsys/net/lib/dns/llmnr_responder.c:24:0:
subsys/net/lib/dns/llmnr_responder.c: In function ‘recv_cb’:
include/net/net_pkt.h:1203:9: warning: ‘addr’ may be used uninitialized
in this function [-Wmaybe-uninitialized]
  return net_pkt_append(pkt, len, data, timeout) == len;
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsys/net/lib/dns/llmnr_responder.c:306:14: note: ‘addr’ was declared
here
  const u8_t *addr;
              ^~~~
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-02 10:03:04 +02:00
Andrei Emeltchenko 006231bbdc net: llmnr_responder: Fix unused Warning
Fixes warning:
warning: ‘ipv6’ defined but not used [-Wunused-variable]
 static struct net_context *ipv6;

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-02 10:03:04 +02:00
Ravi kumar Veeramally c8954d3544 net: coap: CoAP library support over sockets
CoAP library is migrated to support over socket based
applications or other higher layer protocols. Most of the
API's and functionality is kept as it is except few changes.

net_pkt/net_buf is removed from CoAP library. Now it expects
a pre-allocated flat buffer and length. If there is not enough
space to append any data, library simply returns an error.
It's user's responsibility to allocate and free memory.

One change in functionality is, earlier coap_pending_clear()
used to clear the memory, but now it's user's responsibility
to free the memory.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-10-31 19:44:25 -04:00
Jukka Rissanen 469ff39b11 net: lib: init: Remove remaining SYS_LOG usage
Remove the last SYS_LOG reference from init.c as SYS_LOG is
being deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Robert Lubos 683628ab73 net: tls: Do not assume PSK id is NULL terminated
Current TLS socket implementation assumed that PSK ID stored in
credential manager is NULL terminated. It's actually better to store
only the string content, as the string length is stored as well. This
approach is less confusing, when a user is not operating on C strings
but on a non-NULL terminated byte array.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-10-22 10:32:07 +03:00
Michael Scott 263dab3eda net: lwm2m: fix compile warning related to Logger changes
When DBG level for CONFIG_LWM2M_LOG_LEVEL is disabled, a compiler
warning is generated:
In file included from include/logging/log.h:11:0,
                 from subsys/net/lib/lwm2m/lwm2m_engine.c:28:
subsys/net/lib/lwm2m/lwm2m_engine.c: In function ‘engine_add_observer’:
subsys/net/lib/lwm2m/lwm2m_engine.c:558:3: warning: implicit
declaration of function ‘sprint_token’
[-Wimplicit-function-declaration]
   sprint_token(token, tkl), lwm2m_sprint_ip_addr(addr));
   ^

Let's remove the #if guards around sprint_token() and let
the Linker remove it when not needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-19 17:32:36 -04:00
Jukka Rissanen 7c34dcd315 net: app: Fix register and unregister functions
Make sure that we define and declare the _net_app_register() and
_net_app_unregister() functions properly if net_app logging level
is set to debug.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:13:48 -04:00
Paul Sokolovsky cdeddee7c6 net: Set names for threads used by the network subsys/libs
Previously, these either used generic names like "workqueue" (so,
it wasn't possible to distiguish tx and rx workqueues) or didn't
set for net management thread. Here's an example of thread dump
in a typical system (using stack_analyze() call):

rx_workq (real size 4092):	unused 3696	usage 396 / 4092 (9 %)
tx_workq (real size 4092):	unused 3692	usage 400 / 4092 (9 %)
net_mgmt (real size 4092):	unused 3772	usage 320 / 4092 (7 %)
sysworkq (real size 4092):	unused 3512	usage 580 / 4092 (14 %)
idle (real size 252):	unused 64	usage 188 / 252 (74 %)
main (real size 4732):	unused 3672	usage 1060 / 4732 (22 %)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-19 07:58:45 -04:00
Andy Ross b8ffd9acd6 sys_clock: Make clock_always_on true by default
This flag is an indication to the timer driver that the OS doesn't
care about rollover conditions of the tick count while idling, so the
system doesn't need to wake up once per counter flip[1].  Obviously in
that circumstance values returned from k_uptime_get_32() are going to
be wrong, so the implementation had an assert to check for misuse.

But no one understood that from the docs, so the only place these APIs
were used in practice were as "guards" around code that needed to call
k_uptime_get_32(), even though that's 100% wrong per docs!

Clarify the docs.  Remove the incorrect guards.  Change the flag to
initialize to true so that uptime isn't broken-by-default in tickless
mode.  Also move the implemenations of the functions out of the
header, as there's no good reason for these to need to be inlined.

[1] Which can be significant.  A 100MHz ARM using the 24 bit SysTick
    counter rolls over at about 6 Hz, and if it had to come out of
    idle at that rate it would be a significant power issue that would
    swamp the gains from tickless.  Obviously systems with slow
    counters like nRF or 64 bit ones like RISC-V or x86's TSC aren't
    as affected.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Jukka Rissanen 9ae7c394ab net: openthread: Convert to use new shell
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-15 11:14:02 +03:00
Gil Pitney c2cdbbafd7 net: sockets: Get socket offload to build after net logging overhaul.
Also, defines one LOG_MODULE_NAME for the simplelink WiFi driver, and
uses the same name for all files in this driver (module).

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-11 15:51:57 +03:00
Paul Sokolovsky 8e1d78c357 libc: minimal: Make fcntl.h be at top level, not sys/fcntl.h
Placing it at sys/fcntl.h was due to mimicking internal newlib's
layout, but what we need is this file at the standard location,
for reuse.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-09 15:44:59 -04:00
Léonard Bise 9975f7b854 net: sockets: Unblock threads waiting on recv on socket close
This commit fixes the issue that if a thread is waiting on recv for
data and the user closes the socket, the waiting thread is not
unblocked.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
2018-10-09 18:35:22 +02:00
Jukka Rissanen 009e4dafa7 net: Make Kconfig template variables prettier
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 09:01:37 -04:00
Jukka Rissanen 57a8db7789 net: Use log_strdup() when printing debug strings
As the debugging print calls are async, all the strings that might
be overwritten must use log_strdup() which will create a copy
of the printable string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen df13dcf911 net: app: No need to print anything if resolving is not possible
The code was trying to print peer IP address string but that
pointer could contain garbage. There is actually no need to print
anything in this case, the error code return is enough.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 5705573c46 net: lwm2m: Convert to new logging system
Use new logging system instead of SYS_LOG.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 502130d6ea net: lib: Convert mqtt library to use log level
Use network log level in mqtt library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 1165f0d400 net: lib: Convert websocket library to use log level
Use network log level in Websocket library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen dc29ed0bd9 net: lib: Convert socket library to use log level
Use network log level in BSD socket library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 51e9297c4d net: lib: Convert sntp library to use log level
Use network log level in SNTP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 1fbf7862f2 net: lib: Convert openthread library to use log level
Use network log level in OpenThread library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 8ffb0fc968 net: lib: Convert http library to use log level
Use network log level in HTTP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen d880d7c9c8 net: lib: Convert dns library to use log level
Use network log level in DNS library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen cb4fa371c5 net: lib: Convert config library to use log level
Use network log level in config library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen dc018376f2 net: lib: Convert coap API to use log level
Use network log level in CoAP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 3ab1f90822 net: lib: Convert net_app to use log level
Use network log level in net_app library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Taehwa Kang 2bdc5923ad net: coap: Fix Coap coap_option_value_to_int and coap_append_option_int
In coap_option_value_to_int function, when coap option length is 4,
option->value[3] should be shifted by 0 rather than option->value[2].
This doesn't affect the behavior of function but needs to be fixed.

In coap_append_option_int function, when the value is between 0xffff
and 0xffffff(when option length is 3), bit shift operation is wrong.
For example, if the value is 0xABCDEF, by sys_put_be16(val, data)
data[0]=0xCD, data[1]=0xEF, by val >> 16, data[2]=0xAB. So the result
becomes 0xCDEFAB not 0xABCDEF. So, to sys_put_be16 function hand
&data[1] over instead of handing data over and val >> 16 needs to be
set to data[0], not data[2].

Signed-off-by: Taehwa Kang <hegrecomm@gmail.com>
2018-09-28 11:11:17 +03:00
Krzysztof Chruscinski 527256501f shell: Rename shell to legacy_shell
New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Jukka Rissanen 0433e1a840 net: mdns: Wrong net_buf pool was used
Use mDNS specific net_buf pool for received mDNS data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-19 09:55:44 +03:00
Jukka Rissanen ab8ff324d3 net: mdns: Select source IPv4 address properly for sent msg
There is now a proper function to select the right source IPv4
address when sending a mDNS packet so use it instead of selecting
the address directly from network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-19 09:55:44 +03:00
Robert Lubos 349e14d63c net: tls: Fix mbedtls hostname erros when certificates are not used
When no certificate-based ciphersuites are used, mbedTLS compiles out
hostname field and associated functions from its SSL context. This
resulted in compilation error when only PSK-based ciphersuites were
configured.

This commit resolves the issue by compiling-out hostname-related code
from secure sockets implementation on the same basis as mbedTLS does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-17 09:48:11 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Flavio Ceolin a1135620ba misc: printk: Change function return
The result of both printk and vprintk are not used in any place.
MISRA-C says that the return of every non void function must be
checked.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Robert Lubos 5286524a5c net: tls: Add missing entropy header
sockets_tls subsystem uses entropy driver, yet it does not include
entropy header. This commit fixes this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-14 15:01:57 +03:00
Gil Pitney c21b0fb357 net: sockets: Add a socket offload module
This patch enables BSD socket offload to a dedicated
TCP/IP offload engine.

This provides a simpler, more direct mechanism than going
through NET_OFFLOAD (zsock -> net_context -> socket conversions)
for those devices which provide complete TCP/IP offload at the
BSD socket level, and whose use cases do not require
IP routing between multiple network interfaces.

To use, configure CONFIG_NET_SOCKETS_OFFLOAD=y, and register
socket_offload_ops with this module.

Fixes #3706

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-09-11 18:42:34 +03:00
Paul Sokolovsky 4d375eef23 net: config: Use sizeof() to get size of buffer for net_addr_ntop()
Using sizeof() is a common best practice in C, because it allows to
adjust size in one place instead of many.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-09-11 10:42:51 +03:00
Michael Scott d30f2abbe4 net: lwm2m: fix formatter reader/writer initialization syntax
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>
2018-08-30 14:06:18 -04:00
Michael Scott e42611615c net: lwm2m: in oma_tlv_put don't re-add value when insert is true
We set "insert" to true when the value is already in the buffer, but
we need to insert a TLV to denote things like RESOURCE_INSTANCE or
OBJECT_INSTANCE.  In this case, let's not re-add the value.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 7345023dc8 net: lwm2m: TLV: mark object instance boundry when needed
Let's implement put_begin/end_oi functions in the TLV formatter
so to mark the boundry of an object instance when more than 1
object instance is returned.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/9470

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4ba194942a net: lwm2m: refactor put_begin_ri/put_end_ri into generic functions
In order to re-use the put_begin_ri / put_end_ri logic, let's create
generic functions for them: put_begin_tlv and put_end_tlv

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 24e63f1295 net: lwm2m: implement begin/end processing for obj inst and resources
Implement put_begin/end calls for object instance and resource
processing in lwm2m_perform_read_op()

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 90b0986be8 net: lwm2m: store a backup of the entire path in perform_read_op
Currently, we only save the resource id of the incoming path setting.
In the future, we will need to change other values in order to process
multi-instance READ operations.

Let's save and restore the entire path only at the beginning and end
of processing.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 3d2c1b7d72 net: lwm2m: introduce put_begin/end for object instance and resources
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>
2018-08-30 14:06:18 -04:00
Michael Scott 019b24f16a net: lwm2m: optimize lwm2m_perform_read_op()
Optimize the resource processing loop to avoid extra
assignments before checking if we need to process the
actual resource.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 0561887bcb net: lwm2m: fix JSON format for multi-instance reads
When reading multiple instances, the base name value should not
include an object instance id.  The object instance id is added
to the individual resource name values.

Accomplish this by saving the original path level and adjusting
the (base) name where needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 658cb19339 net: lwm2m: correct placement of put_begin/put_end in READ op
The put_begin / put_end calls are to be used at the very beginning
and end of processing a READ op.  Let's correct that logic.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 1821c27462 net: lwm2m: optimize variable order in lwm2m_perform_read_op()
Let's sort by largest to smallest so that we don't leave odd gaps
in memory.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott f21b20550c net: lwm2m: remove unused members from lwm2m_output_context
Now that formatters use their own private data to hold state,
let's remove the old member variables from lwm2m_output_context
which are now unused.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4a344e7d0f net: lwm2m: tlv formatter use private data
Use newly introduced private data pointer in output context to
store TLV formatter information.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4fb29949af net: lwm2m: json formatter use private data
Use newly introduced private data pointer in output context to
store JSON formatter information.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott fff8422f60 net: lwm2m: introduce output context user_data
Data formatters have various private state variables which are
currently located in the output context structure.  Let's add
a place where data formatters can store a pointer to their
private data so that as we add more formatters the output
context doesn't get cluttered up.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott a4001f02b0 net: lwm2m: plain-text: process only reads for a specific resource
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>
2018-08-30 14:06:18 -04:00
Michael Scott 34a135b608 net: lwm2m: allow formatters to perform processing prior to read_op
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>
2018-08-30 14:06:18 -04:00
Michael Scott 485bf7a7eb net: lwm2m: fix reading multiple objects that don't start at 0
Let's correct the starting logic in do_read_op() to not assume
a default value of 0 will be present for the first object, when
reading multiple objects.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 280f159b67 net: lwm2m: fix logic for lwm2m_next_engine_obj_inst()
The object instance list isn't sorted by object instance id.  Let's
simplify this and fix the logic in lwm2m_next_engine_obj_inst() to make
sure that we always get the NEXT object instance by value of
obj_inst_id, not just the next object instance in the list.

NOTE: This change removes the "last" object instance pointer from the
parameters of lwm2m_next_engine_obj_inst().  Some of the logic to return
a NULL value for the end of the list has to be moved back into
do_read_op().

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 0f0455e0b6 net: lwm2m: simplify MATCH_ logic in do_read_op()
Remove over-complicated match_type logic in do_read_op().  Replace
MATCH_* checks with actual path->level values.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Paul Sokolovsky a2d12527f6 net: sockets: poll: Handle EINTR return from k_poll
This is similar to change which was done in 21f31e90ec, unfortunately
this case was missed.

Fixes: #9032

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-30 09:28:29 -04:00
Jukka Rissanen cfe27b3984 net: app: Notify peers properly when DTLS connection is closed
The peers were not informed about DTLS connection close because
we removed DTLS context. The fix is to notify peers before we
remove the DTLS connection.

Fixes #8605

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-30 09:27:38 -04:00
Michael Scott a166ba77c4 net: lwm2m: return observe errors immediately
Instead of continuing to do_read_op(), let's handle errors during
observe processing immediately.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-28 08:30:48 -04:00
Michael Scott 881fae33a9 net: lwm2m: fix typo in observe error message
obserer -> observe

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-28 08:30:48 -04:00
Michael Scott be2b361b35 net: lwm2m: check for read permission on observe
When processing an observe request we fail to check whether a
resource has the read permission set.  Let's check and if it
doesn't return -EPERM.

NOTE: Also do diligence and return -ENOENT when an object field
cannot be found while looking for the permission.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/8286

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-28 08:30:48 -04:00
Michael Scott 3b80998ff2 net: lwm2m: correct Copyright to Foundries.io
Due to a change in the company name, the LwM2M copyrights need
to be changed from "Open Source Foundries Limited" ->
"Foundries.io".

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-27 19:29:16 -04:00
Paul Sokolovsky 2af8dc9630 net: sockets: close: Call net_context_accept only for listening socket
The previous code "optimized" and called both net_context_accept()
and net_context_recv() blindly to reset the corresponding callbacks.
But this leads to "wrong state" logging if debugging is enabled, so
clean that up.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-25 07:18:31 -07:00
Robert Lubos d529aef9f2 net: tls: Apply DTLS review fixes
This commit contains several fixes for DTLS implementation, proposed in
a post-merge review of #9338.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-17 15:10:00 +03:00
Ulf Magnusson 8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Jukka Rissanen 355d58b0d0 net: http: One extra byte was sent in last chunk
There was one extra byte sent in last chunk which caused
this error to be printed by curl

  * Illegal or missing hexadecimal sequence in chunked-encoding
  * stopped the pause stream!
  * Closing connection 0
  curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-15 12:59:13 +03:00
Jukka Rissanen 4078e46e7d net: l2/lib: Always have a timeout when allocating a net_buf
Instead of waiting forever for a network buffer, have a timeout
when allocating net_buf. This way we cannot left hanging for a
long time waiting for a buffer and possibly deadlock the system.
This commit adds checks to L2 and network support libraries.

Fixes #7571

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 12:17:00 +03:00
Xuan Ze 96abe861a7 net/mqtt: Fix function mqtt_parser
There have a funtion mqtt_rx_unsuback defined but not used.
So add it into mqtt_parser and fix the missing case.

Fixes #8431

Signed-off-by: Xuan Ze <119524428@qq.com>
2018-08-13 19:37:36 -07:00
Paul Sokolovsky 028aae1ec9 net: config: Rename Kconfig options to correspond to library name
This finishes refactor of splitting off net_config library name from
net_app library, started in c60df1311, c89a06dbc. This commit makes
sure that Kconfig options are prefixed with CONFIG_NET_CONFIG_
instead of CONFIG_NET_APP_, and propagates these changes thru the
app configs in the tree.

Also, minor dependency, etc. tweaks are made.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-13 18:42:31 -07:00
Andrew Boie 18cec245ba net: introduce system calls for zsock socket APIs
Add system calls for the zsock implementations of socket,
close, bind, connect, listen, accept, sendto, recvfrom,
fcntl, poll, inet_pton, and getaddrinfo.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-08-13 07:19:39 -07:00
Robert Lubos 7c487ba04a net: tls: Use EINVAL for NULL pointer error in option setters
Originally EFAULT was used to indicate NULL pointer error in TLS option
set/get functions. EINVAL was suggested to be more apropriate error code
for this case, hence replace it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 800392e128 net: tls: Enable non-blocking DTLS handshake
Introduce non-blocking DTLS handshake, used during recv function call.
This prevents from blocking while waiting for initial handshake packet
on non-blocking sockets during receive.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos ae41ec1f35 net: tls: Make TLS poll implementation check mbedTLS data
Make TLS poll function verify if decrypted data is available after
socket has notified activity with POLLIN flag. This prevents from giving
false notifications in case data was received on socket but was consumed
by mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 8697cc946f net: tls: Add timeout for mbetTLS read
Specify timeout value for mbedtls_ssl_read function for DTLS servers.
Adding this can prevent TLS context lockup in case blocking recv is used
and peer has shut down DTLS connection without closing it gracefully.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b1d8271152 net: tls: Support DTLS recv and handshake
Add support for DTLS recv/recvfrom function.

For DTLS client, recv function requires to have an already established
DTLS connection.

For DTLS servers, this function will try to establish DTLS connection
before receiving data. In case that DTLS handshake fails, recv function
will silently retry.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos bdc56cfe89 net: tls: Support DTLS send and handshake
Add support for DTLS send/sendto function.

For DTLS clients, send function will try to establish DTLS connection
before sending data. If DTLS handshake fails, it will return an error.

For DTLS servers, send function requires to have DTLS connection already
established.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos d021b8c60f net: tls: Adapt connect for DTLS
Extend connect function with DTLS functionality.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 6c5aaa070c net: tls: Handle HELLO_VERIFY_REQUIRED during DTLS handshake
DTLS handshake can return MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED, which
indicate that TLS session context should be reset.

Also, store information whether TLS connection has beed established.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 4c235dea73 net: tls: Add DTLS bio functions
Add binary IO functions for DTLS connections.

dtls_rx function is more complex than it's TLS counterpart due to fact,
that DTLS does not allow blocking operation for this function. A simple
timeout mechanism was implmented basing on the zsock_poll function.

This function also verifies peer address. As currently only a single
DTLS connection is supported on a socket, if a DTLS connection is
established, and we receive datagram from different peer, it is silently
dropped.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 8719f9a802 net: socket: Extract flag related functions to internal header file
Functions for checking flags set on sockets are needed by TLS sockets as
well, therefore extract them to a separate header file to avoid code
duplication.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 4aaffaff8a net: tls: Add DTLS peer address helpers
Add helper functions to handle stored DTLS peer address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 3ad2bbceda net: tls: Add cookie for DTLS
Add DTLS cookie to TLS context, required by DTLS servers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 011b4f4265 net: tls: Add timer handling for DTLS
Add timer functions required by DTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b03a388d73 net: tls: Add socket option to set DTLS role
Add write-only socket option to set role for DTLS connection. This
option is irrelevant for TLS connections.

This options accepts and integer with a TLS role, compatible with
mbedTLS values:
0 - client,
1 - server.

By default, DTLS will assume client role.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 85db974ec3 net: tls: Add DTLS protocol types
Define DTLS protocol types and and Kconfig option to enable DTLS
support.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Michael Scott 9c26c3fa3b net: lwm2m: no need to cleanup net_app_ctx in RD client
The LwM2M engine will cleanup the net_app_ctx if there are
errors during initialization.  The clean up calls here in
RD client are duplicated.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-07 19:55:49 +03:00
Robert Lubos b7e686648b net: sockets: Fix setsockopt coverity issues
Minor refactoring to satisfy Coverity.

Fixes #9291 (CID 187324)
Fixes #9296 (CID 187319)

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-06 12:40:40 +03:00
Philémon Jaermann c3eea5f6ee net: net_app: Correctly notify server on TCP disconnection
If a disconnection callback was registered, it is not called
as the check done in net_app is reversed. The disconnection callback
is not called if there are any inactive contexts.
The check should be on any active context.

Signed-off-by: Philémon Jaermann <p.jaermann@gmail.com>
2018-08-02 10:28:20 +03:00
Ulf Magnusson d1684a83a4 Kconfig: Clean up some symbol definitions
- Remove redundant 'n' defaults. 'n' is the default value for bool
  symbols.

  This makes the auto-generated documentation clearer as well: You get
  "implicitly defaults to n" instead of
  "- n if <propagated dependencies>".

- Shorten

      <type>
      prompt "foo"

  to

      <type> "foo"

  This works for all types, not just bool.

- Various formatting nits.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-01 12:47:17 -04:00
Robert Lubos 7826228def net: tls: Add socket option to set peer verification level
Add write only TLS secure option to set peer verification level for
TLS connection.

This option accepts an integer with a peer verification
level, compatible with mbedtls values (0 - none, 1 - optional, 2 -
required.

By default, socket mimics mebdTLS behavior - (none for server, required
for client).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 3d560e14ac net: tls: Add socket option to read chosen ciphersuite
Add TLS secure socket option to read a ciphersuite chosen during TLS
handshake. Might be useful during development.

This is a read-only option that returns an integer containing an
IANA assigned ciphersuite identifier of chosen ciphersuite.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11c24c855d net: tls: Add socket option to select ciphersuites
Add TLS secure socket option that enables to narrow list of ciphersuites
available for TLS connection.

This option accepts an array of integers with IANA assigned ciphersuite
identifiers and returns such.

By default, every statically configured ciphersuite is available for a
socket and getsockopt returns an array of these.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 915317724c net: tls: Add socket option to set TLS hostname
Add write-only TLS secure socket option to set hostname.

This option accepts a string containing the hostname. May be NULL, to
disable hostname verification.

By default, an empty string is set as a hostname for TLS clients,
to enforce hostname verification in mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos a3edfc2563 net: tls: Set TLS credentials in mbedTLS
Configure selected credentials in mbedTLS before the handshake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 48e055577b net: tls: Add socket option to select TLS credentials
Add TLS secure socket option to select TLS credentials to use.

This option accepts and returns an array of sec_tag_t that indicate
which TLS credentials should be used with specific socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos f959b5c164 net: tls: Add TLS socket options placeholder
Add TLS secure sockets wrapper for getsockopt/setsockopt functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11f7abcefd net: socket: Define getsockopt() and setsockopt()
Define socket option functions and make them return ENOPROTOOPT.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos d09cbcaf6f net: tls: Add credential management subsystem
Add TLS credential management subsystem that enables to register TLS
credentials in the system. Once specific credentials are registered in
the system, they will be available for TLS secure sockets to use.

To use a TLS credential with a socket, the following steps have to be
taken:
1. TLS credential has to be registered in a system-wide pool, using the
API provided in "net/tls_credentials.h" header file.
2. TLS credential (and other TLS parameters) should be set on a socket
using setsockopt().

Note, that there is no need to repeat step 1 for different sockets using
the same credentials. Once TLS credential is registered in the system,
it can be used with mulitple sockets, as long as it's not deleted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Jukka Rissanen 9b8c83f44a net: Avoid holes in structs
Move struct members around in networking code so that we avoid
unnecessary holes inside structs. No functionality changes by
this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-25 15:20:34 +03:00
Paul Sokolovsky 58cc75327b net: getaddrinfo: Make availability depend on CONFIG_DNS_RESOLVER
CONFIG_DNS_RESOLVER is the master switch for DNS resolution support,
for both native and socket APIs. Avoid confusing link errors by
compiling out both dns_resolve_name() and getaddrinfo() if that
option is not enabled.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-23 10:04:39 -07:00
Ravi kumar Veeramally 3fafe4f9ad net: ipv6: Handle large IPv6 packets properly
Current implementation does not handle large extension headers
(e.g HBHO). Which resulted network stack crashes or due to
misinterpretation of lengths network packets are dropped. Also
caused issues while preparing IPv6 packet (e.g. large HBHO header
with IPv6 fragmentation support).

Issues fixed and provided more unit tests.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-07-23 15:01:09 +03:00
Andrew Boie a74137f665 net: getaddrinfo: use memory allocation for res
We no longer use a global array for what is supposed to be
a memory allocation.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 08:56:21 -07:00
Andrew Boie 1b37602859 net: getaddrinfo: ai_state no longer global
Move this onto the call stack of the getaddrinfo() function,
there's no need for it to be global.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 08:56:21 -07:00
Ramon Ribeiro a9c684c6e6 net: openThread: Fix MTD build
This patch fix the problem when the user select to use the MTD
in OpenThread configuration

Signed-off-by: Ramon Ribeiro <rhpr@cesar.org.br>
2018-07-17 16:40:53 +03:00
Michael Scott 3f53e6d1d8 net: lwm2m: read past not supported TLV resources
During transfer of object data via OMA TLV format, we can
encounter resources which are optional or not handled in base
LwM2M engine.  When these resources cannot be handled let's
read past them and continue on.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Michael Scott ce48f18d10 net: lwm2m: use ARRAY_SIZE to calculate # of options
Don't use hard-coded value of 4 for passing the # of options to
coap_find_options() in handle_request().  This can easily get
out of sync.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Michael Scott 538d3418fd net: lwm2m: introduce user-code callbacks for obj create/delete
LwM2M engine now supports optional resources that may need to be
setup or torn down in user-based code during object instance
creation / deletion.

Let's provide callbacks that can be used for this purpose.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Michael Scott 56e240e528 net: lwm2m: make lwm2m_engine_exec_cb_t more generic
Let's rename lwm2m_engine_exec_cb_t to lwm2m_engine_user_cb_t so that
future user-code callbacks can make use of the same definition.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Paul Sokolovsky eedb8a7bd8 net: sockets: Make poll() call threadsafe by avoiding global array
Initial implementation of poll() was more of a proof of concept, so
was coded with a single-thread application in mind. As we move to
sockets as the main networking API, make it possible to use poll()
from different threads.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-17 13:02:16 +03:00
Robert Lubos 47f908872d net: tls: Implement poll with support for mbedTLS pending data
Implement socket poll function for TLS socket. In addition to regular
poll checks, we have to check if there is some decrypted data pending on
mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 07f1a1fe2c net: tls: Handle TLS socket send and recv
Implement socket recv/recvfrom and send/sendto functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos d08fd07f60 net: tls: Handle TLS handshake
Implement TLS handshake handling in socket connect/accept functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 2d4815dd15 net: tls: Add mbedTLS logging
Add mbedTLS logging function to enable logs from mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos ccdc6a6bdf net: tls: Add mbedTLS entropy source
Add entropy source for mbedTLS. If no entropy driver is available, use
non-secure, software entropy source.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos a7c698d936 net: tls: Add TLS context allocation/deallocation
Add tls_context structure that stored data required by TLS socket
implementation. This structure is allocated from global pool during
socket creation and freed during socket closure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 00a69bf9bb net: socket: Add switch to enable TLS socket option support
Add switch to a socket layer that will enable switching socket API to
TLS secure sockets. At this point there is no secure sockets
implementation, so secure socket calls redirect to regular socket calls.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Kumar Gala 21d6e302f6 net: lwm2m: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:47:15 -05:00
Paul Sokolovsky c89a06dbc1 net: config: Introduce a dedicated header for the library
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>
2018-07-02 12:36:35 +03:00
Jukka Rissanen b833d010eb net: llmnr: Add LLMNR responder support
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>
2018-06-29 13:11:18 +03:00
Jukka Rissanen 837ed14a0d net: llmnr: Add link-local mcast name resolution client support
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>
2018-06-29 13:11:18 +03:00
Paul Sokolovsky 83b3f84d6f net: lib: app: Convert CMakeLists.txt to avoid library
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>
2018-06-20 17:10:39 +03:00
Paul Sokolovsky c60df13110 net: app: Split code for configuring network to a separate lib, "config"
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>
2018-06-20 17:10:39 +03:00
Michael Scott 7934e24983 net: lwm2m: retry registration update 6 seconds before expiration
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>
2018-06-18 10:51:15 +03:00
Leandro Pereira c16bce7a6a samples, subsys, tests: Use ARRAY_SIZE() whenever possible
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>
2018-06-14 19:12:51 -04:00
Michael Scott ed3ea06f88 net: lwm2m: fix observer attribute update logic
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>
2018-06-07 12:27:46 -05:00
Michael Scott a957107d50 net: lwm2m: lower priority of engine thread
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>
2018-06-07 11:51:51 -05:00
Jukka Rissanen 8f5929ddf0 net: Too long timeout for k_sleep
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>
2018-05-28 17:20:11 -04:00
Michael Scott 4c58ffb5ab net: lwm2m: dont release reply for duplicate block transfer
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>
2018-05-25 17:19:34 -04:00
Jukka Rissanen 6180b904af net: Too long timeout was passed to k_sleep
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>
2018-05-22 08:55:27 -04:00
Ravi kumar Veeramally 6586dba334 net: coap: Fix CoAP observer helper function
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>
2018-05-22 08:54:54 -04:00
Daniel Egger b1e06f2b3b net: lwm2m: remove silent fail for bad endpoint data in rd_client
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>
2018-05-21 22:50:12 -04:00
Robert Lubos 5f534dc6de net: openthread: Add function for getting current radio channel
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>
2018-05-18 15:09:53 +03:00
Robert Lubos c0af4de7b3 net: openthread: Bump OpenThread commit to db4759cc
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>
2018-05-18 15:09:53 +03:00
Jukka Rissanen 3c09bee921 net: app: server: Fix compile error if TCP is disabled
There was a compile error if TCP was disabled in net-app server.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-18 14:06:33 +03:00
Michael Scott 198b358638 net: lwm2m: simplify registration client
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>
2018-05-18 09:28:28 +03:00
Michael Scott a58781f504 net: lwm2m: add LWM2M_FIRMWARE_UPDATE_PULL_LOCAL_PORT setting
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>
2018-05-18 09:28:28 +03:00
Michael Scott 21fdf536ba net: lwm2m: default LWM2M_LOCAL_PORT to 0 (random)
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>
2018-05-18 09:28:28 +03:00
Michael Scott a021034327 net: lwm2m: honor CONFIG_LWM2M_LOCAL_PORT when starting client
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>
2018-05-18 09:28:28 +03:00
Michael Scott 9cbe86f832 net: app: client: handle client_addr port in net_app_init_client()
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>
2018-05-18 09:28:28 +03:00
Michael Scott cc8fab8ddb net: app: client: fix local port byte-order in bind_local()
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>
2018-05-18 09:28:28 +03:00
Tomasz Bursztyka 49bd1e9c6f ieee802154: Add support for filtering source short/ieee addresses
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>
2018-05-17 16:18:53 +03:00
Michael Scott d07391d386 net: coap: clear more fields in coap_reply_clear()
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>
2018-05-16 10:57:55 +03:00
Michael Scott bb98d8766a net: coap: add COAP_INIT_ACK_TIMEOUT_MS setting
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>
2018-05-16 10:57:55 +03:00
Michael Scott 07ec5567fc net: lwm2m: remove unused OBJ_FIELD_MULTI_DATA macro
The use-case for this macro was removed during optional resource
changes.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott b6774f0eea net: lwm2m: mark OPTIONAL resources for IPSO Temperature
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>
2018-05-16 10:56:07 +03:00
Michael Scott a5bdbc1751 net: lwm2m: mark OPTIONAL resources for IPSO Light Control
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>
2018-05-16 10:56:07 +03:00
Michael Scott 7a1024e5c8 net: lwm2m: mark OPTIONAL resources for LwM2M Firmware Update
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>
2018-05-16 10:56:07 +03:00
Michael Scott 1290139626 net: lwm2m: mark OPTIONAL resources for LwM2M Device
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>
2018-05-16 10:56:07 +03:00
Michael Scott 9506b427b7 net: lwm2m: mark OPTIONAL resources for LwM2M Server
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>
2018-05-16 10:56:07 +03:00
Michael Scott 4fb16db26d net: lwm2m: mark OPTIONAL resources for LwM2M Security
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>
2018-05-16 10:56:07 +03:00
Michael Scott 0d67f6a78d net: lwm2m: introduce FLAG_OPTIONAL to denote optional resources
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>
2018-05-16 10:56:07 +03:00
Michael Scott 0db9af5a28 net: lwm2m: return error from lwm2m_engine_get_* functions
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>
2018-05-16 10:56:07 +03:00
Jukka Rissanen e50cacb356 net: app: Select proper source IPv4 address in client
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>
2018-05-16 10:47:01 +03:00
Michael Scott 8a21d3862b net: app: fix build warning in _net_app_ssl_mainloop()
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>
2018-05-16 09:16:35 +03:00
David Leach 9e09e2a1b7 OpenThread: Change SETTINGS_CONFIG_PAGE_SIZE to target specific value
- 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>
2018-05-14 17:23:38 -04:00
Leandro Pereira 03f9f66496 net: websocket: Revise generation of Sec-WebSocket-Accept header
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>
2018-05-14 08:16:46 +03:00
Leandro Pereira e81b9043c5 net: websocket: Simplify building of responses
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>
2018-05-14 08:16:46 +03:00
Michael Scott fc8d093592 net: lwm2m: lower default maximum observes from 20 to 10
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>
2018-05-11 16:38:49 +03:00
Michael Scott ad13866ffd net: lwm2m: remove "used" from observe_node
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>
2018-05-11 16:38:49 +03:00
Michael Scott 6ef46e3f31 net: lwm2m: remove attr_list from obj, obj_inst and res_inst structs
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>
2018-05-11 16:38:49 +03:00
Michael Scott 573c1f777e net: lwm2m: improve return errors from update_attrs()
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>
2018-05-11 16:38:49 +03:00
Michael Scott bc7a5d3a6c net: lwm2m: relocate/memory align notification_attrs struct
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>
2018-05-11 16:38:49 +03:00
Michael Scott 2027c10a9f net: lwm2m: remove "path" from object and resource instances
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>
2018-05-11 16:38:49 +03:00
Michael Scott bba1fe8ca9 net: lwm2m: Re-order lwm2m object structs for memory alignment
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>
2018-05-11 16:38:49 +03:00
Leandro Pereira 7359c5b10b net: lwm2m: Do not use snprintk() to get debugging token
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>
2018-05-10 14:17:35 -07:00
Michael Scott f038d35a98 net: lwm2m: remove unused LWM2M_PEER_PORT define
Code references CONFIG_LWM2M_PEER_PORT directly.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott b6ca731bdc net: lwm2m: remove unused CONFIG_LWM2M_BOOTSTRAP_PORT config
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>
2018-05-04 09:45:35 +03:00
Michael Scott 42717a97f7 net: lwm2m: use BIT macro instead of LWM2M_OP_BIT
Now that the LWM2M_OP_* bits have been renumbered, we no longer need
a custom BIT() macro for the LwM2M code.  Let's remove it and use
BIT() instead.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott aa9a24aa25 net: lwm2m: remove LWM2M_OP_NONE flag and renumber the rest
Remove unused OP flag LWM2M_OP_NONE and renumber the existing flags
so that the operations used in object permissions land in the lowest
bits, and extended operations come later.

We may eventually add more permission / data flags, so let's try and
keep them inside a 1 byte boundary (flags with bits 0 to 7).

NOTE: LWM2M_OP_DELETE is currently not checked as a permission but
it may be in the future so it is in the lower bits.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott f80c52d668 net: lwm2m: introduce LWM2M_HAS_PERM macro
Standardize permission checks via the LWM2M_HAS_PERM macro.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott cf55b70b4c net: lwm2m: fix error code in read and write handlers
When a data pointer or data length is not set, the read and write
handlers should return ENOENT to generate the correct LwM2M error
code (COAP_RESPONSE_CODE_NOT_FOUND).

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott 44c9b79a49 net: lwm2m: clear lwm2m_obj_path obj in string_to_path
Before ever call of string_to_path(), the lwm2m_obj_path object
was being cleared via memset.  Let's move the memset into
string_to_path() to remove the duplicate code.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott 3e16be3c3c net: lwm2m: refactor engine_get_obj to be more useful
Eliminate several similar code-blocks by replacing
engine_get_resource() with a more useful function called:
path_to_objs()

By supplying an lwm2m_obj_path object, it will find and set
the related values for:
struct lwm2m_engine_obj_inst
struct lwm2m_engine_obj_field
struct lwm2m_engine_res_inst

NOTE: NULLs can be supplied where the returned value is not
important.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Jukka Rissanen a91c46ffde net: app: Select local IP address properly if multiple interfaces
If we have multiple network interface (like in VLAN), then we need
to select the proper local interface based on destination address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-13 08:29:44 -04:00