Commit graph

1061 commits

Author SHA1 Message Date
Michael Scott b5231d0b93 net: lwm2m: firmware: add log_strdup to remove logging errors
When performing OTA using the LwM2M subsys, several logging errors
regarding log_strdup were noted.  Let's fix these.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:09:22 +03:00
Michael Scott 13086ccda8 net: lwm2m: dont select MBEDTLS or set MBEDTLS options in subsys
If a sample wants to use the Zephyr implementation of mbedtls, it
enables CONFIG_MBEDTLS and sets any needed Zephyr-specific mbedtls
options.

Currently, the LwM2M subsystem selects MBEDTLS automatically when
LWM2M_DTLS_SUPPORT is enabled.  Let's remove this and let the
LwM2M client sample enable mbedtls and it's options.

This mimics the behavior of several other network-related samples
and removes conflicts when selecting alternate implementations of
MBEDTLS.

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

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:08:47 +03:00
Michael Scott 82e889a2e2 net: lwm2m: fix error message in load_tls_credential()
Copy/paste issue was showing the wrong error message when a TLS
credential failed to be added.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:08:30 +03:00
Michael Scott 88642ef2eb net: lwm2m: remove IP CONFIG checks in lwm2m_parse_peerinfo()
CONFIG_NET_IPV* checks are not needed in lwm2m_parse_peerinfo().
The functions used are always available.  Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).

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

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:07:58 +03:00
Michael Scott 05cc5ae92c net: lwm2m: remove IP CONFIG checks in lwm2m_sprint_ip_addr()
CONFIG_NET_IPV* checks are not needed in lwm2m_sprint_ip_addr().  The
functions used are always available.  Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).

NOTE: Also fixes an issue where a NULL is returned when the IP address
is unknown.  This usually ends up with a crash/abort in the logging
code.

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

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:07:58 +03:00
Jukka Rissanen 8f92dc4634 net: dns: Send net-mgmt event for DNS server add and del
If DNS server(s) are added or removed e.g., as part of DHCP
processing, send newly defined net-mgmt events so that
a user application may get this information.

Fixes #16924

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-09 17:04:55 +03:00
Robert Lubos c37faaa56d net: lwm2m: Ignore close return value
Explicitly ignore return value from `close` call.

Coverity-CID: 198870

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-07-08 21:40:15 +03:00
Jukka Rissanen 57101e56f4 net: llmnr_responder: Fix debug prints after receiving query
The hostname needs to have log_strdup() when printing it.
Also it is useful to print information if the sending fails.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-08 16:02:38 +03:00
Tomasz Bursztyka 11a8b42d8b net/llmnr: Fix LLMNR answer creation
- answer offset was 1 byte off.
- request offset, when copied into the answer, was off as well.

Fixes #16142

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-08 16:02:38 +03:00
Nicolas Pitre d19a5f9119 net: socket: mgmt: use uintptr_t for the nm_pid field
This may contain a pointer so make sure it is sufficiently wide
on 64-bit targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-05 10:06:23 -04:00
Nicolas Pitre 66045b5db0 net/socket: use the iterable section object constructor/iterator
The handcrafted allocation falls victim of misaligned structures due to
toolchain padding which crashes the socket test code on 64-bit targets.
Let's move it to the iterable section utility where those issues are
already taken care of.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-04 11:36:52 +03:00
Jukka Rissanen 2f95f4afe7 net: sockets: Initialize IP socket addresses in getsockname()
Make sure the IPv4 and IPv6 socket addresses are initialized before
copying them. This avoids uninitialized memory access.

Coverity-CID: 199436
Fixes #17202

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 15:26:59 +03:00
Jukka Rissanen eef7625660 net: socket: Add SO_TIMESTAMPING socket option
This can be used to activate the network packet statistics
collection. Note that we do not have resources to calculate
each network packet transit times but we collect average times
instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 09:42:45 +03:00
Jukka Rissanen 7c65db4e31 net: socket: mgmt: Add setsockopt() and getsockopt() support
Currently only setting and getting of Ethernet Qav options are
supported via this interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen 6f32f17cda net: socket: Add userspace support to getsockopt()
Allow userspace application to call getsockopt() without crashing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen ee849826e3 net: socket: Add userspace support to setsockopt()
Allow userspace application to call setsockopt() without crashing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen c0d6831bc0 net: sockets: mgmt: Add AF_NET_MGMT address family support
Allow application to listen network management events using
BSD socket API. Application needs to create the socket using
AF_NET_MGMT address family. At this point we only support
receiving network management events that the network subsystem
is sending.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Pieterjan Camerlynck b7d4b0057e net: lwm2m: fix automatic notification frequency
This fixes the issue where observations are automatically reported using
the minimum period instead of the maximum. This causes notifications to
be sent more frequently than configured when the resource does not
change.

Signed-off-by: Pieterjan Camerlynck <pieterjan.camerlynck@gmail.com>
2019-07-01 10:36:33 +03:00
Ravi kumar Veeramally 84b191edd2 net: sockets: Add timeout to socket connect call
Current socket connect call implementation always takes
K_FOREVER timeout value, which blocks TCP connections
in case failure. TCP connections waits until it receives
SYN ACK. If there is no SYC ACK means, connect call is
blocked forever.

Added a Kconfig option to define timeout value. Default
value is 3000 milliseconds. User can modify it.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-07-01 10:34:15 +03:00
Jukka Rissanen ef10937553 net: dns: Make dns_unpack_answer() to check non-compressed answers
Modify dns_unpack_answer() function to check if the answer is
compressed or not, and return correct values regardless.

Fixes #16594

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 09:44:29 +03:00
Justin Brzozoski ffe25df82a mqtt: Allow client to override keepalive
This change will allow an MQTT client to override the compile-time
keepalive if desired.  The change is structured such that the
compile-time default will still be setup by calling mqtt_client_init,
but can be changed by the application before calling mqtt_connect if
desired.

Signed-off-by: Justin Brzozoski <justin.brzozoski@signal-fire.com>
2019-06-28 09:54:16 -04:00
Anas Nashif 5b0aa794b2 cleanup: include/: move misc/reboot.h to power/reboot.h
move misc/reboot.h to power/reboot.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 0c9e280547 cleanup: include/: move misc/mutex.h to sys/mutex.h
move misc/mutex.h to sys/mutex.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6ecadb03ab cleanup: include/: move misc/math_extras.h to sys/math_extras.h
move misc/math_extras.h to sys/math_extras.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 8be9f5de03 cleanup: include/: move misc/fdtable.h to sys/fdtable.h
move misc/fdtable.h to sys/fdtable.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif fe051a9055 cleanup: include/: move flash.h to drivers/flash.h
move flash.h to drivers/flash.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 969f8f1c68 cleanup: include/: move entropy.h to drivers/entropy.h
move entropy.h to drivers/entropy.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Jukka Rissanen 70aa383018 net: sntp: Ignore return value from close
Return value from close() can be ignored in sntp_close()
as it is not returning value to caller anyway.

Coverity-CID: 198863
Fixes #16584

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-27 23:52:51 +03:00
Jukka Rissanen 19806a2c1b net: getaddrinfo: Query both IPv4 and IPv6 if family is AF_UNSPEC
We must query both IPv4 and IPv6 addresses if the hints parameter
is NULL i.e., user does not supply hints or if family is set to
AF_UNSPEC.

Fixes #16453

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-20 14:45:43 +03:00
Håkon Øye Amundsen 05cd3420ac net: mqtt: add mqtt_readall_publish_payload()
This function uses mqtt_read_publish_payload_blocking to perform a
blocking read of the specified number of bytes.

When reading out a payload, the normal use case is to read the
entire payload. This function facilitates that use case.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2019-06-20 13:06:08 +03:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Jukka Rissanen 06b500b6bd net: sockets: can: Close the socket cleanly
If the socket is closed, then do CAN detach if that is needed.
This way the CAN interrupts are not received if there are no
CAN sockets listening the data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen 6621491014 net: sockets: can: Add dispatcher
We need to dispatch the received CAN frame if there are multiple
sockets interested in the same CAN-IDs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Loic Poulain 3189da5cdc net: mdns_resolver: Fix malformed MDNS response
The query->len does not take 'Terminator' into account, shift over
one byte to prevent overwriting it with next field (Type).

This fixes mdns_resolver sample.

Fixes: 87eb552dd2 (net/dns: Switch mdns responder to new net_pkt API)

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-06-12 13:59:27 +03:00
Loic Poulain 4f4adae271 net: lib: Fix missing dns subdir include
The dns directory was not included when building with
MDNS_RESONDER or LLMR_RESPONDER configs.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-06-12 13:59:27 +03:00
Jukka Rissanen c3bb0a6af9 net: socket: Add SO_PRIORITY support to setsockopt
Allow user to set the socket priority using setsockopt() call.
The priority value is used to order the networking queues so
that packets with a higher priority may be processed first.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-09 12:54:05 +03:00
Jukka Rissanen a348c8c61c net: llmnr: Check that UDP header can be accessed
It is possible that UDP header cannot be accessed so we need
to check that we do not do null pointer dereference.

Coverity-CID: 198866
Fixes #16581

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-09 01:42:13 +08:00
Paul Sokolovsky 0fb8a917e6 net: sockets: Make NET_SOCKETS_POSIX_NAMES depend on !POSIX_API
These options are mutually exclusive, or more specifically,
CONFIG_POSIX_API has wider scope and supersedes
CONFIG_NET_SOCKETS_POSIX_NAMES. Implementation-wise, the two
options should not be defined at the same time, as that may
lead to declaration conflicts.

Fixes: #16141

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-06-05 07:51:01 -04:00
Robert Lubos 87462df3ef net: sockets: Remove TI conditional from offloaded fcntl implementation
Offloaded `fcntl` implementation should be available for all offloaded
implementations, not specific for TI. `socket_offload.c` is already
conditionally compiled based on `CONFIG_NET_SOCKETS_OFFLOAD` option, so
there should not be conflicts for non-offloaded interfaces.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-30 18:41:31 -04:00
Michael Scott a46db55d0a net: lwm2m: fix log_strdup missing errors
Due to commit a211afb0 ("logging: Add option to detect missed
transient string duplication"), the logs for LwM2M subsystem
is now spamming missing log_strdup() calls.

Let's add log_strdup() where needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-05-30 11:26:43 +08:00
Paul Sokolovsky 8b3db460aa net: getaddrinfo: Parse numeric IPv4 addresses
If a valid numeric IP address is provided as argument, it should
be resolved without contacting DNS server.

Also, implement handling of AI_NUMERICHOST.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-29 17:46:56 +08:00
Louis Dupont a8fffca40f net: lwm2m: Remove IPSO objects maximum number of instances limitation.
Fixes #16156 by removing kconfig maximum number of instances.

Signed-off-by: Louis Dupont <dupont.louis@ireq.ca>
2019-05-25 17:57:56 -04:00
Michael Scott a923c2f1be net: openthread: fix off-by-one error in settings offset calculation
OpenThread uses CONFIG_OT_PLAT_FLASH_PAGES_COUNT to calculate the # of
pages at the end of flash to use for storing OpenThread settings.

This calculation has an off-by-one error which sets the offset for
the storage area as 1 page of flash too low.

For example, on nRF52840:
- default setting for CONFIG_OT_PLAT_FLASH_PAGES_COUNT is 4
- flash size is 1MB (0x100000)
- flash page size is 4096 (0x1000)
- expected offset is 0xfc000

Using the current logic we get an offset of: 0xfb000

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

Signed-off-by: Michael Scott <mike@foundries.io>
2019-05-23 10:47:20 +03:00
Tomasz Gorochowik c0b30355fb net: sockets: implement getsockname function
From POSIX.1-2017:

The getsockname() function shall retrieve the locally-bound name of the
specified socket, store this address in the sockaddr structure pointed
to by the address argument, and store the length of this address in the
object pointed to by the address_len argument.

The address_len argument points to a socklen_t object which on input
specifies the length of the supplied sockaddr structure, and on output
specifies the length of the stored address. If the actual length of the
address is greater than the length of the supplied sockaddr structure,
the stored address shall be truncated.

If the socket has not been bound to a local name, the value stored in
the object pointed to by address is unspecified.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-05-17 22:49:32 +03:00
Paul Sokolovsky a2fa8e9c1c net: getaddrinfo: Implement initial handling of host == NULL
If host is NULL and ai_flags are AI_PASSIVE in a call to
getaddrinfo(), need to return "any" address.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-16 16:11:10 +03:00
Jakob Olesen c8708d9bf3 misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>.
Use the new math_extras functions instead of calling builtins directly.

Change a few local variables to size_t after checking that all uses of
the variable actually expects a size_t.

Signed-off-by: Jakob Olesen <jolesen@fb.com>
2019-05-14 19:53:30 -05:00
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