Commit graph

3020 commits

Author SHA1 Message Date
Kamil Kasperczyk 06bf2ca707 net: openthread: Added config options for NCP vendor hooks.
New config option that can be used to enable vendor hooks
for NCP component.

Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
2020-07-23 10:44:19 +02:00
Marek Porwisz 740e0ccc9e net: openthread: Allow use of custom mbedtls
To allow hardware crypto acceleration custom mbedtls library needs to be
prepared. However current implementation forces the default library to
be used.
This patch allows not using the default library and passing custom
mbedtls target to use with openthread.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-07-22 15:32:30 -05:00
Michael Hope b046ca5409 net: tcp2: fix unaligned access in the TCP2 stack
The TCP2 stack does operations directly on the packet data which may
or may not be aligned.  The unaligned access causes a fault on the
Cortex-M0+ so use the UNALIGNED_* macros instead.

Signed-off-by: Michael Hope <mlhx@google.com>
2020-07-22 15:08:31 +03:00
Kamil Kasperczyk f061400b37 net: openthread: platform: Removed double-buffering in UART send.
Putting data to local buffer before transmission was removed
to optimize operation. Local buffering was not needed, as passed
buffer cannot be modified until sending is finished.

Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
2020-07-22 11:08:21 +03:00
Kamil Kasperczyk cb41255e3f logging: added new logging backend - Spinel protocol
New logging backend that can be used by NCP architecture.

Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
2020-07-21 15:11:55 +02:00
Robert Lubos d20b1aebf9 net: lwm2m: Fix poll fds handling
Currently, functions for poll sock_fds array management are buggy, in
case there is another socket open (for instance the socket for firmware
update download), it could get overwritten, if the LwM2M socket was
closed and re-opened in a meantime (e. g. on registration timeout).

Fix this, by appending new entries to the sock_fds in continuous manner.
In case of removal, the deleted entry is overwritten by the last one,
and the last one is cleared.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 15:08:14 +02:00
Robert Lubos b080dfbd12 net: lwm2m: Fix block transfer retransmissions
During FW update, the application expects a consecutive data stream.
Therefore retransmitted blocks shall not be forwarded to the
application, but ignored. In case blocks are received out of order,
return an error and do not handle this block.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 15:08:02 +02:00
Robert Lubos 69ca589256 net: lwm2m: Fix opaque data transfer in block mode
When FW update in PUSH mode is used, the firmware is encapsulated in the
TLV as an opaque data, according to the LMWM2M satandard, and then
sliced into blocks and transferred block by block in several
transactions. Therefore, the TLV header is only present in the initial
message.

Current implementation did not handle this case well, reporting errors
on consecutive blocks, therefore making the FW update in PUSH mode
broken.

This commit fixes this issue with following changes:
 * The TLV is only assumed to be present in the initial block, while
   consecutive blocks will be processed directly into the appropriate
   handler,
 * 32-bit variables shall be used whenever dealing with the opaque data
   length, since the firmware size can easily exceed the 16-bit range,
 * Additional information, required for the FW block transfer to work
   properly were added to the block context structure,
 * The application shall only be notified of the actual data length, and
   not the total block size (the total TLV size including header).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 15:08:02 +02:00
Robert Lubos daf303e660 net: lwm2m: Fix unused return value from sys_mutex calls
Fixes coverity issues 211473 and 211477.

Fixes #26988
Fixes #26989

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-21 12:40:40 +02:00
Lukasz Maciejonczyk 6edf5bde11 net: config: Fix IPv6 setup when DAD is unused and IPv6 addr is not set
When the dupplicate address detection mechanism is not used, we should
not wait for IPv6 address configuration. Because of the bug we are
waiting for it, when CONFIG_NET_CONFIG_MY_IVP6_ADDR is not set.
This commit fixes it.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2020-07-21 10:11:32 +03:00
Robert Lubos ac305149bb net: lwm2m: Remove duplicated logs during bootstrap
Remove the `sm_bootstrap_reg_done` function, which produced duplicated
logs. The bootstrap registration done event is already logged on state
transition. Additionally, in case bootstrap procedure took longer time,
the duplicated log message was printed on each `lwm2m_rd_client_service`
call (500 miliseconds by default).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-20 12:50:25 -04:00
Robert Lubos c59271d9f0 net: lwm2m: Clear security object instance on engine restart
The security object instance used should be cleared on engine reset,
otherwise we might end up using invalid object instance for the
registration (i. e. if the engine was restarted during the bootstrap
procedure due to socket errors, the registration attempt will use
bootstrap security object instead of finding a proper one).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-20 12:50:25 -04:00
Robert Lubos 00d12041f6 net: lwm2m: Initialize CoAP response on bootstrap finish
During the bootstrap procedure, when Boostrap Finish was received, the
response message was not initialized properly, resulting in a socket
error (NULL pointer porovided) and the response not being sent.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-20 12:50:25 -04:00
Jukka Rissanen 4746a13324 net: Remove special alignment
The Z_STRUCT_SECTION_ITERABLE() provides an alignment so remove
the 32 byte alignment for net_if and ppp_protocol_handler structs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-07-20 08:32:46 -07:00
Jukka Rissanen 62580748e5 net: Use section foreach macros
Use system provided Z_STRUCT_SECTION_FOREACH() and
Z_STRUCT_SECTION_ITERABLE() macros instead of manually coding
everything for network sections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-07-20 08:32:46 -07:00
Marek Porwisz a6c6e7793f net: openthread: Use different kconfig switch for shim and src
Different switch was used for build to allow including all shim body
in zephyr without the need for building openthread from this repo. This
allows developer to include custom OpenThread sources as part of the
application.
This change is needed as Thread is a subject of certification and
sources provided by zephyr may not necesairly pass certification or be
precertified. User is allowed to use certified OpenThread version
this way.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-07-20 14:42:30 +03:00
Piotr Szkotak a6b0a3a263 net: openthread: make diag compile
Fix compilation error when the DIAG module is enabled.
All core functionalities are provided.

Signed-off-by: Piotr Szkotak <piotr.szkotak@nordicsemi.no>
2020-07-20 14:40:29 +03:00
Martí Bolívar dfbabb1201 openthread: avoid warning when CONFIG_NET_MGMT_EVENT=n
When this happens, ip6_addr_cb and ipv6_addr_event_handler() both look
unused, since they are passed to macros which discard them.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-07-20 14:28:30 +03:00
Oleg Zhurakivskyy 87577cb599 net: tcp2: Implement a blocking connect
In order to implement a blocking connect, add a semaphore
and block on it in net_tcp_connect().

The semaphore is released when ESTABLISHED state is reached.

In case tcp_conn_unref() is called while waiting on the semaphore,
defer the unreference, tcp_conn_unref() will be called from
net_tcp_connect().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-20 13:55:22 +03:00
Oleg Zhurakivskyy ff8e08e6c7 net: tcp2: Refactor net_tcp_connect()
In order to improve readability, refactor and simplify
the control flow in net_tcp_connect().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-20 13:55:22 +03:00
Oleg Zhurakivskyy f4c2772622 net: tcp2: Check for SYN and ACK in SYN_SENT
In order for events to be correctly interpreted in SYN_SENT,
check for SYN and ACK simultaneosly.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-20 13:55:22 +03:00
Oleg Zhurakivskyy dc01cae8a6 net: tcp2: Send FIN only in ESTABLISHED state
net_tcp_put() can be called before ESTABLISHED state
is reached, send FIN only in ESTABLISHED state.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-20 13:55:22 +03:00
Marcin Niestroj 071e8400ad net: l2: ppp: fsm: use packet work object instead of shared one
Single work object for whole fsm was not being able to handle more than
single packet at a time. Because of that we have overwritten already
scheduled packets, resulting in fsm timeout and net_pkt leak.

Use net_pkt work object instead, so we can safely schedule more than a
single packet.

This commit also drops workaround for qemu_x86 unit testing.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-20 13:19:28 +03:00
Eug Krashtan ad59e7fec5 net: ip: Fix IPv6 RS message doesn't comply RFC4291
Current implementation of net_ipv6_send_rs() uses
net_ipv6_addr_create_ll_allnodes_mcast() for creating RS packet.
As result we send RS packet to all-nodes destination [FF02::1],
but RFC4291 requires all-routers destination [FF02::2] for RS packets.

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2020-07-15 13:26:58 +02:00
Robert Lubos 38adddac00 net: lwm2m: Reinitialize address length before recvfrom is called
`addrlen` parameter is updated on each `recvfrom` call, indicating the
actual address length returned. In case both, IPv4 and IPv6 are used on
different sockets (i. e. on regular LWM2M socket and FOTA socket), the
returned address length will differ.

In case `from_addr_len` is not reinitialized on each iteration, the
value stored in the `from_addr_len` variable will eventually indicate
the smaller IPv4 address size, therefore resulting in a failure in a
consecutive call on an IPv6 socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-14 13:04:37 +02:00
Robert Lubos fddeb59911 net: lwm2m: Protect send() calls with a mutex
Although LwM2M engine uses cooperative threads, the internal `send()`
implementation might trigger context switch when it calls a kernel
function, therefore resulting in `send()` call being entered from both
the LwM2M thread and the retransmit work.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-14 13:04:37 +02:00
Oleg Zhurakivskyy fda94f7d06 net: tcp2: Fix dereference after null check in tcp_in()
Fix dereference after null check in tcp_in().

Coverity CID :210051

Fixes #25783

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-07-10 11:46:20 +02:00
Marcin Niestroj af0bb8835b net: l2: ppp: ipv6cp: remove wrong Configure-Rej handling
Currently there is a single function that handles both Configure-Ack and
Configure-Rej messages. This is obviously wrong for Configure-Rej,
because implementation applies options received in the message.

Remove Configure-Rej callback, so those frames are simply ignored for
the time no valid handling code exists.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-09 12:47:12 -04:00
Marcin Niestroj 7996f527d5 net: l2: ppp: ipcp: clear options after protocol goes down
Clear negotiated options in protocol down handler. That way all
addresses are properly requested (by sending 0.0.0.0 in Configure-Req)
in the subsequent option negotiation phases.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-09 13:45:18 +02:00
Flavio Ceolin c4f7faea10 random: Include header where it is used
Unit tests were failing to build because random header was included by
kernel_includes.h. The problem is that rand32.h includes a generated
file that is either not generated or not included when building unit
tests. Also, it is better to limit the scope of this file to where it is
used.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-07-08 21:05:36 -04:00
Robert Lubos c5132aac18 net: lwm2m: Fix invalid logical and operator usage
Binary and should be used instead.

Fixes #26356.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-07 15:06:22 +02:00
Robert Lubos 2eb633d12e net: lwm2m: Reset only messages owned by lwm2m context
The context should only clear messages it owns, not all of them. Since
both context (LwM2M and FOTA) share common message pool, they might
interrupt their operation otherwise (i. e. cancel retransmissions).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-06 18:01:31 -04:00
Robert Lubos 8b22521b6b net: lwm2m: Close FOTA socket when finished
The FOTA socket was not closed when download finished or an error
occured.

Additionally, fix the socket fd verification (it was assumed 0 is not a
valid fd which is not correct).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-06 18:01:31 -04:00
Alexandre Bourdiol 937482b4a7 net: ip: copy to wrong destination in z_vrfy_net_addr_pton()
In function z_vrfy_net_addr_pton(),
the final copy should be to 'dst' variable not to 'src'

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-07-06 18:00:07 -04:00
Robert Lubos 3ea5c2180a net: lwm2m: Prevent infinite loop in do_write_op_tlv function
In case unsopported TLV type or malformed packet is received, the
`do_write_op_tlv` function will end up in an infinite loop. Prevent that
by returning an error code in case it does not recognize TLV type.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-06 17:57:40 -04:00
Marcin Niestroj 03c774e58c net: l2: ppp: drop ppp_context's is_network_up
There is already a variable 'network_protos_up', which stores number of
network protocols being up. Additionally each network protocol has its
own state represented by is_ip{,v6}cp_up. Use the latter in FSM up() and
down() callbacks.

This fixes a case when both IPCP and IPv6CP protocols are going
down. When using ctx->is_network_up only one of them (the first) was
deinitialized correctly, second stayed always up (at least partially,
e.g. not calling ppp_network_down()).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-06 17:55:44 -04:00
Marcin Niestroj 16542e1642 net: l2: ppp: fix packet length for sending Term-Req and Term-Ack
Each PPP packet sent on wire needs to have at least 4 bytes length. Set
that length for outgoing Term-Req and Term-Ack packets. Also update
length validation to check for at least 4 bytes instead of at least 1
byte.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-06 16:50:54 +02:00
Lukasz Maciejonczyk ddb9f290e1 net: l2: openthread: Implement enable API function
It fixes #issues/26220.

openthread_start function is called when L2 enable(iface, true) is
called. openthread_stop is called when L2 enable(iface, false) is
called. openthread_stop makes the device to leave the OpenThread
network.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2020-07-02 08:43:45 -04:00
Markus Becker 350bab6d8c net: openthread: handle non mesh-local IPv6 addresses as DHCPv6
OpenThread BR can assign addresses via DHCPv6 or when acting as an
NCP, addresses can be added manually. Currently, those addresses are
handled in the same way as auto-configured addresses.

This patch maps the newly introduced mAddressOrigin of otNetifAddress to
Zephyr's net_addr_type.

This way an application can register a handler and differentiate by type
of assignment:

```
static void handler(struct net_mgmt_event_callback *cb,
                    u32_t mgmt_event,
                    struct net_if *iface)
{
  if (iface->config.ip.ipv6->unicast[i].addr_type == NET_ADDR_DHCP) {
  }
}
```

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-07-02 08:36:27 -04:00
Marek Porwisz 83f7f81d8d net: openthread: New build options for OpenThread
Some options were available in the options.cmake but were not reflected
in Kconfig.
Added possibility to enable additional configuration options for OT.
Some of the options were left commented out as those options are not
yet supported e.g. require Thread 1.2 or require shim changes.
As openthread has gazillion configuration options that are passed as
define value, created generic option for passing any number of those
values separated with space.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-06-30 07:48:08 -04:00
Marek Porwisz 81e0a05285 net: openthread: Simplify openthread enabling
Currently user needs to specify quite much additional options to enable
OpenThread support. He also needs to set ip address count,
heap size, etc depending on features enabled.
Nade changes to automatically select/set some of the options on
enabling OpenThread

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-06-30 07:48:08 -04:00
Marcin Niestroj 79a8d0f616 net: l2: ppp: reject unsupported options
Both ASYNC_CTRL_CHAR_MAP and MAGIC_NUMBER are not supported right
now. Send Configure-Reject for them instead of Configure-Nak, as we
don't even propose new values in reply (which should be part of
Configure-Nak).

Send also Configure-Reject for MRU option, as we don't respect it
either.

Drop both count_rej and count_nack, as we can rely solely on nack_idx to
send Configure-Reject or not.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-06-29 08:26:53 -04:00
Jukka Rissanen 6ecea4b3dd net: conn: Handle multi interface AF_PACKET recv() properly
If we have multiple network interfaces and we are waiting incoming
network packets, make sure to honor the bind of the socket so that
correct socket will receive data in certain network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-24 23:34:27 +03:00
Jukka Rissanen c7058eba73 net: gptp: The sync receive timer had wrong timeout
The sync receive timeout was using invalid value (nanoseconds
instead of milliseconds). This caused unnecessary state switches
from SLAVE to MASTER and back.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-23 18:16:15 +03:00
Jukka Rissanen 0223169f14 net: gptp: Add more debug to PA info state machine
Add debug prints when the port announce information state
machine state changes. This is useful in debugging.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-23 18:16:15 +03:00
Jukka Rissanen f119cae365 net: shell: Print network interface for gptp info
This is useful to know so show what network interface is related
to a given gPTP port.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-23 18:16:15 +03:00
Jukka Rissanen 2675a11766 net: gptp: Return proper port number for given interface
The port number is stored starting from 0 in Ethernet context.
But in gPTP, it is an index which starts from 1. So increase
the value by 1 for a value returned from Ethernet context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-23 18:16:15 +03:00
Robert Lubos d780458bc6 net: openthread: Update OpenThread revision
Regular upmerge with some fixes needed after changes in the upstream
OpenThread.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-22 17:09:10 +02:00
Lukasz Maciejonczyk 74b1c617af net: openthread: Add possibility to register ot state changed app cb
It may be useful for the application to register its own callback for
ot state changed event which does not override the current one.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2020-06-22 11:34:18 +03:00
Lukasz Maciejonczyk 4ad78d9249 net: openthread: Make function openthread_start be public
It may be useful to start openthread manually but with default
network settings. For instance when the application wants to register
ot state changed callback which should be done before openthread
starts.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2020-06-22 11:34:18 +03:00