Commit graph

346 commits

Author SHA1 Message Date
Peter Bigot 4fb4d280d3 net: l2: ppp: validate pointer before dereferencing it
See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 9.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Robert Lubos 369109b4b2 net: ieee802154: Avoid ACK processing when not needed
In case hardware CSMA CA is used, ieee802154 L2 does not initialize ACK
processing structures, as it does not need to process ACK messages. As
it is not possible to conditionally disable ACK reporting to the upper
layer, ieee802154 could end up using uninitialized kernel primitive
(semaphore) in the ACK handler, which lead to a crash.

Avoid this, by explicitly checking in the ACK handler, if HW CSMA CA is
used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-03 14:07:41 +03:00
Robert Lubos 1fb418df4c net: ieee802154_radio: Allow to specify TX mode
Even though radio driver can report in its capabilities that it does
support CSMA CA, there's no way in the driver to select how the frame
should be transmitted (with CSMA or without). As layers above radio
driver (Thread, Zigbee) can expect that both TX modes are available, we
need to extend the API to allow either of these modes.

This commits extends the API `tx` function with an extra parameter,
`ieee802154_tx_mode`, which informs the driver how the packet should be
transmitted. Currently, the following modes are specified:
* direct (regular tx, no cca, just how it worked so far),
* CCA before transmission,
* CSMA CA before transmission,
* delayed TX,
* delayed TX with CCA

Assume that radios that reported CSMA CA capability transmit in CSMA CA
mode by default, all others will support direct mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-03 14:07:41 +03:00
Joakim Andersson f2d7b77e96 Bluetooth: host: Deprecate BT_LE_ADV defines in hci.h in favour of gap.h
Deprecate BT_LE_ADV defines in hci.h that are expected to be used by the
application in the scan received callback to identify the advertising
PDU type. These defines are mixing HCI input parameters and advertising
PDU types. Internally it is acceptable to mix these, but at the API we
should to mix in them.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 405ce842ab Bluetooth: host: Add new argument and return code to bt_create_conn_le
Deprecate bt_create_conn_le and rename it to in order to add return
code, new arguments and to follow the established naming convention.

Add API for the application to control the scan parameters of the
initiator role. This allows the application more scheduling control
of the initiator in multi-role scenarios. Also provides options to
configure the initiator for LE Coded PHY for long range support.
We deprecate the old way of creating connection to make the name more
consistent with the rest of the API.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Markus Becker 0651141d84 net: openthread: Add NCP start-up and required platform changes
When NCP starts-up some of the initialisation functions of a regular
OpenThread device do not need to be called, because they get triggered
by wpantund via UART. Instead NCP initialisation needs to be called.

A small typo has been fixed as well.

Also initialisation for raw link packet interface has been added. Can be
used for picking up 802.15.4 frames and interpreting them in the
application.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-03-25 08:37:16 +02:00
Markus Becker 71ce94e0ed net: openthread: Add UART platform backend for NCP
Currently based on CDC-ACM. Can possibly be used with plain UART as
well.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-03-25 08:37:16 +02:00
Christian Taedcke a401aefa0a net: ppp: Implement missing ppp mgmt functions
The functions ppp_mgmt_raise_carrier_on/off_event() were not
implemented, but already documeted in the header net/ppp.h

Fixes #23420

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2020-03-24 14:29:49 -05:00
Flavio Ceolin 6fec8ea84e net: ieee802154: Fix possible null pointer de-reference
ieee802154_scan() checks if ctx->scan_ctx (scan) is NULL what implies
that this can be true, but de-reference this variable before this
check what may cause a problem.

Fixes #23299 [3]

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-03-17 17:03:19 -05:00
Andrew Boie 760644041c net: purge NET_STACK and other stack APIs
The current design of the network-specific stack dumping APIs
is fundamentally unsafe. You cannot properly dump stack data
without information which is only available in the thread object.

In addition, this infrastructure is unnecessary. There is already
a core shell command which dumps stack information for all
active threads.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Marcin Niestroj f5edc6db8f net: wifi: shell: drop explicit length parameter
Calculate length based on provided SSID string, so user does not have to
provide length explicitly over shell.

This patch also removes requirement of minimum 3 characters SSID, as
the shortest SSID can be even 1 character.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-03-10 14:37:57 +02:00
Robert Lubos 24b6afaec2 net: openthread: Unify IS_ENABLED macro usage
Older OT code used preprocessor #if conditionals, while newer code
used IS_ENABLED macro. Unify the approach by switching to the latter
option.

Additinally, fix inclusion issue that came out after switching to
IS_ENABLED.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:36:24 +02:00
Göran Weinholt 091f630014 net: ppp: ipcp: negotiate DNS servers and optionally use them
We now negotiate DNS servers in the IPCP configuration. This has been
observed to speed up the connection setup. The received DNS servers
are used by the DNS resolver library, but we leave it optional since
the static server list might be preferable.

Increase MAX_IPCP_OPTIONS to 4 so that we can nack all RFC 1877
options.

Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
2020-03-10 14:09:10 +02:00
Göran Weinholt eef8e67ea7 net: ppp: ipcp: do not require a peer address
It is not unusual that the peer does not provide an IP address in the
ipcp negotiation. But because ppp is a peer-to-peer protocol, we do
not actually need to know the peer's address to use the network.

Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
2020-03-10 14:09:10 +02:00
Ravi kumar Veeramally 36b92fb7e6 net: ppp: Fix integer handling coverity issue
Store the time difference value in u32_t variable than
abs() value in signed variable.

Fixes #22912
Coverity CID: 208406

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-02-25 11:26:06 +01:00
Jukka Rissanen 856dd3dfdd net: ppp: ipcp: Remove dead code
If nack_idx > 0, then the count_rej must be > 0. This means that
the "code" variable will never be set to PPP_CONFIGURE_NACK.

Fixes #22436
Coverity-CID: 207975

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-02-12 17:41:03 +02:00
Ulf Magnusson eddd98f811 kconfig: Replace some single-symbol 'if's with 'depends on'
I think people might be reading differences into 'if' and 'depends on'
that aren't there, like maybe 'if' being needed to "hide" a symbol,
while 'depends on' just adds a dependency.

There are no differences between 'if' and 'depends on'. 'if' is just a
shorthand for 'depends on'. They work the same when it comes to creating
implicit menus too.

The way symbols get "hidden" is through their dependencies not being
satisfied ('if'/'depends on' get copied up as a dependency on the
prompt).

Since 'if' and 'depends on' are the same, an 'if' with just a single
symbol in it can be replaced with a 'depends on'. IMO, it's best to
avoid 'if' there as a style choice too, because it confuses people into
thinking there's deep Kconfig magic going on that requires 'if'.

Going for 'depends on' can also remove some nested 'if's, which
generates nicer symbol information and docs, because nested 'if's really
are so simple/dumb that they just add the dependencies from both 'if's
to all symbols within.

Replace a bunch of single-symbol 'if's with 'depends on' to despam the
Kconfig files a bit and make it clearer how things work. Also do some
other minor related dependency refactoring.

The replacement isn't complete. Will fix up the rest later. Splitting it
a bit to make it more manageable.

(Everything above is true for choices, menus, and comments as well.)

Detected by tweaking the Kconfiglib parsing code. It's impossible to
detect after parsing, because 'if' turns into 'depends on'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-02-08 08:32:42 -05:00
Jukka Rissanen f633c16cbd net: ethernet: Set link local address to VLAN interfaces
Each network interface needs to have IPv6 link local address.
The ll address was not set to VLAN interfaces which then caused
some of the IPv6 neighbors to be in wrong state (INCOMPLETE) in
neighbor cache.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-01-30 09:42:07 +02:00
Patrik Flykt ede043a84c net: l2: ppp: Assign IPv4 address received with IPCP
Store the IPv4 address into the local LCP options and set it
as the interface IP address once IPCP negotiation is complete.

Fix calling the correct function when an IPCP Configure Reject
is received carrying our local IP address.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2020-01-28 12:44:17 +02:00
Robert Lubos b3a1ede830 net: openthread: Use settings subsystem
OpenThread settings implementation built on top of Zepyhr settings
submodule.

With this solution, OpenThread settings are identified with keys of
the following format: `ot/id/instance`, where `id` is assigned by
OpenThread stack, and `instance` is a 32-bit random number, both in
hex. The implementation makes use of `settings_load_subtree_direct`
function to iterate over settings instances. This allows the
OpenThread settings layer to be a fully transparent shim layer between
OpenThread/Zephyr APIs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-16 17:12:47 -06:00
Marcin Niestroj 7ee5cf6a0b net: ppp: fsm: fix sending Protocol-Reject
No packet was previously sent, because net_pkt_set_ppp(pkt, true) was
not called on the outgoing packet. Also the received protocol instead of
LCP was used, which was incorrectly interpreted by remote peer.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-01-07 20:01:31 +02:00
Marcin Niestroj 0b8e5f1552 net: ppp: fsm: prevent double free in Discard-Req handler
Received net_pkt is always discarded in ppp_recv() if we return
NET_OK. Don't do this in ppp_fsm_recv_discard_req().

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-01-07 20:01:31 +02:00
Marcin Niestroj c182610466 net: ppp: fsm: use size of whole structure instead of each field
Just improve readability by converting to sizeof(ppp).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-01-07 20:01:31 +02:00
Marcin Niestroj 660dbcd56e net: ppp: lcp: reject all not recognized and not acceptable options
Just follow RFC 1661 [1] about Configure-Reject packets.

[1] https://tools.ietf.org/html/rfc1661#section-5.4

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-01-07 20:01:31 +02:00
Marcin Niestroj 0a3d0c8d89 net: ppp: ipcp: reject all not recognized and not acceptable options
Just follow RFC 1661 [1] about Configure-Reject packets.

[1] https://tools.ietf.org/html/rfc1661#section-5.4

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-01-07 20:01:31 +02:00
Marcin Niestroj b3a8e7dcd5 net: ppp: ip{,v6}cp: drop possible double free of nack_buf
When iterating though configuration options it is possible that we will
fail to add data to nack_buf and hence unref it in error handling
path. Just after that we will unref buf, which has nack_buf in its
buffer chain.

Drop code unrefing nack_buf and just go directly to unrefing buf.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-01-07 20:01:31 +02:00
Marcin Niestroj e0cf06fc72 net: ppp: lcp: drop dead code path checking nack_buf
There is no possibility right now that 'nack == NULL' and 'nack_buf !=
NULL', so drop code path for that case.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-01-07 20:01:31 +02:00
Johan Hedberg 0e91493ab4 Bluetooth: L2CAP: Make channel ops const
Make the channel ops struct const since there really isn't anything
there that needs to change at runtime. The only exception is the L2CAP
shell which was playing with the recv callback, however that can be
fixed by introducing a simple bool variable.

With tests/bluetooth/shell this reduces RAM consumption by 112 bytes
while adding only 16 bytes to flash consumption.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-19 11:28:24 +02:00
Robert Lubos 649ec80c9e net: openthread: Update OpenThread version and better CMake integration
OpenThread recently introduced CMake build system into its repostiory
so we no longer need autotools to build OpenThread libraries and can
integrate them natively.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-12-16 11:08:09 +02:00
Luiz Augusto von Dentz cbcbfee41d net: bt: Don't wait for buffer indefinatelly
This can actually block system critical threads like the syswq.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Luiz Augusto von Dentz f93de735d2 net: bt: Disconnect in case of errors sending a packet
Packets shall never fail to be sent now that they are queued, so if an
error occured there is no point in keep the channel connected.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-13 15:30:28 +02:00
Christian Taedcke cdb6332af6 net: ppp: Reset flag is_ipcp_up in ipcp_down
Without this fix is it not possible to terminate pppd and restart
pppd afterwards without restarting the firmware, too.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2019-12-12 09:41:13 +02:00
Christian Taedcke 530855f607 net: ppp: Reset flag is_ipv6cp_up in ipv6cp_down
Without this fix is it not possible to terminate pppd and restart
pppd afterwards without restarting the firmware, too.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2019-12-12 09:41:13 +02:00
Ulf Magnusson 984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00
Kumar Gala 24ae1b1aa7 include: Fix use of <misc/FOO.h> -> <sys/FOO.h>
Fix #include <misc/FOO.h> as misc/FOO.h has been deprecated and
should be #include <sys/FOO.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Robert Lubos e871ae9407 net: openthread: Allow to configure SED
Allow to select Sleepy End Device, and configure it during OpenThread
initialization.

According to Thread Specification, Sleepy End Devices should always
attach to the network as SED, to indicate increased buffer requirement
to a parent. Therefore, we reconfigure the Link Mode on each boot.

Note, that Poll Period value is not stored in the persistent storage,
hence we also need to initialize it on each boot.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-12-09 12:47:45 -05:00
Robert Lubos 4fe1da9f58 net: openthread: Process real ACK frame instead of fake one
OpenThread radio layer did not implement `ieee802154_radio_handle_ack`
API and provided fake ACK frame to the OpenThread.

This prevented proper Sleepy End Device operation, as it expects to
receive information in the ACK whether it should wait for more data to
come or should it put the radio to sleep.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-12-09 12:47:45 -05:00
Jukka Rissanen 196816532f net: gptp: Do not update clock if time diff is < 0
The time difference calculation did not check if the result
value would be < 0 which means really large value when converted
to unsigned.

Fixes #20100

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-12-02 09:58:51 -05:00
Andy Ross 8892406c1d kernel/sys_clock.h: Deprecate and convert uses of old conversions
Mark the old time conversion APIs deprecated, leave compatibility
macros in place, and replace all usage with the new API.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-08 11:08:58 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
Robert Lubos 83bb911a21 net: openthread: Update OpenThread version
Use the newest version of the OpenThread project, as updated in
https://github.com/zephyrproject-rtos/openthread/pull/2.

Introduce the following fixes along with the update (they're squashed to
retain bisectability of OT samples):

* Update configs and flags used
	Some OT configs were renamed, some new were introduced that Zephyr port
	needs to set.

* Add entropy platform driver
	OpenThreads `random` platform subsystem was replaced with `entropy`
	subsystem which is supposed to serve as an entropy source for the
	generic OpenThread's random generator.

* Halt OT thread when OT command is processed
	OpenThread can currently be processed from two threads - a
	genuine OpenThread thread and shell thread, which processes CLI
	commands. This could cause trouble, when context was switched
	during OT command processing (i.e. switched to process an incomming OT
	message, while still in unfinished command handler).

	In result, it was not possible to turn the commissioner role on via
	CLI, as the commissioner petition response was handled before the
	Commissioner::Start function finished its execution (if the
	petitioner is also the network leader, all messages are passed
	internally within the stack).

	Fix this by suspending the OT thread for the time of an OT command
	processing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-10-28 13:00:56 +02:00
Ulf Magnusson 9d46779ca7 net: ieee802154: kconfig: Remove unused fragmentation debugging symbol
Unused after commit a76814bfb6 ("net: Convert core IP stack to use log
levels").

Found with a script.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-10-22 13:10:52 +03:00
Christian Taedcke d720d17c90 net: ppp: Answer LCP Echo-Request with Echo-Reply
Send a Echo-Reply to every Echo-Request. This code does not verify
if the ppp stm is in LCP Opened state. See rfc1661 section 5.8.

Signed-off-by: Christian Taedcke <hacking@taedcke.com>
2019-10-11 20:47:53 +03:00
Peter Bigot e28f330a8e coccinelle: standardize k_thread create/define calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments
to k_thread_create and K_THREAD_DEFINE to use the standard timeout
macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Peter Bigot ab91eef23b coccinelle: standardize kernel API timeout arguments
Use the int_literal_to_timeout Coccinelle script to convert literal
integer arguments for kernel API timeout parameters to the standard
timeout value representations.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-03 11:55:44 -07:00
Peter A. Bigot 5639ea07f8 kernel: timeout: remove unused callback parameter from init function
The callback function has been ignored in z_timeout_init() since the
timer rework in fall 2018.  Passing real handlers to it in code is
distracting when they will be overridden by whatever callback is
provided in z_add_timeout().

As this function is an internal API deprecation is not necessary.
Remove the parameter and change all call sites to drop the argument.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-09-28 15:41:18 -04:00
Robert Lubos 063fefd15d net: openthread: Use Zephyr's mbedTLS instead of compiling own
So far OpenThread compiled it's own, internal copy of mbedTLS library.
This commit changes this behavior by using Zephyr's mbedTLS instance
appropriately configured for OpenThread needs.

Generic mbedTLS config file was used in this case, so that application
can still configure remaining parts of mbedTLS for it's own needs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-09-17 20:07:58 +08:00
Andy Ross 6564974bae userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words.  So
passing wider values requires splitting them into two registers at
call time.  This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.

Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths.  So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.

Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types.  So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*().  The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function.  It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.

This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs.  Future commits will port the less testable code.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-12 11:31:50 +08:00
Jukka Rissanen 6cf1da486d net: Add CONFIG_NET_NATIVE option for selecting native IP
Allow user to disable native IP stack and use offloaded IP
stack instead. It is also possible to enable both at the same
time if needed.

Fixes #18105

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-09-10 12:45:38 +03:00
Stephanos Ioannidis 2b9636db52 net/ieee802154: Explicitly include toolchain.h.
This commit adds an explicit inclusion of toolchain.h from
ieee802154_frame.h.

The endianness preprocessor definitions (__BYTE_ORDER__,
__ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__) are used by
ieee802154_frame.h; these being not defined can easily go unnoticed and
cause unexpected behaviours, as detailed in PR #18922.

toolchain.h ensures that these preprocessor definitions are defined and
*must* be included in a file that uses these definitions.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-09-09 21:40:54 +02:00
Jukka Rissanen 792d6fc19a net: gptp: Avoid memcpy to same buffer
Do not try to memcpy() the same buffer to itself.

This one also reverts commit 112ecb7290
("net: gptp: Fix for coverity CIDs 203471 and 203464") as that
did not fully fix the issue.

Coverity-CID: 203464
Coverity-CID: 203471
Fixes #18394

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-27 10:33:14 -04:00
Tomasz Bursztyka 112ecb7290 net: gptp: Fix for coverity CIDs 203471 and 203464
If no challenger went to replace the best port/vector, then the best
port is still the global_ds and thus point to the same memory: no need
to update the global_ds then.

Coverity-CID: 203471
Coverity-CID: 203464
Fixes #18395

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-08-23 08:54:27 -04:00
Tomasz Bursztyka 82c315aaf5 net: ppp: Fix for coverity CID 203514
Looks like the logic to count rejection is missing. Removing count_rej
variable, and set a comment about initializing the code to the right
value once this logic will be in.

Coverity-CID: 203514
Fixes #18398

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-08-23 08:54:27 -04:00
Alexander Wachter d864f5de5b net: l2: canbus: Add support for canbus Ethernet translator
This commit adds support for a 6LoCAN Ethernet border translator.
CAN frames with the translator CAN address are translated and forwarded
to Ethernet. Ethernet frames with the first 34 bits matching the MAC
address of the translator are translated and forwarded to 6LoCAN.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Alexander Wachter 7fe85170fc net: l2: canbus: Add support for pkt reception from translator
This commits adds support for reception of packets thats comes from
a Ethernet to 6LoCAN translator. This packets carry the Ethernet
MAC address (6 bytes) inline in the FF (First Frame).

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Alexander Wachter 35f01673ac net: l2: 6LoCAN implementation
This commit is an implementation of 6LoCAN, a 6Lo adaption layer for
Controller Area Networks. 6LoCAN is not yet standardised.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Alexander Wachter c8c5f3bbf3 net: canbus: Rename canbus to canbus_raw
Rename the socket_can implementation from CANBUS to CANBUS_RAW.
This is a preperation for 6LoCAN which is a CANBUS L2 for IPv6.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Jukka Rissanen 5c05ef5101 net: Move include files outside of extern "C" block
This is related to findings in #17997 and changes network related
header files to have include files outside of extern "C" { } block.

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-06 14:46:36 +03:00
Joakim Andersson c1a754f665 Bluetooth: Host: Print error codes in hex
Error codes are listed in header files and in the core spec as hex
values. Always print them in hex in debug for easier error code
checking.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-05 12:18:17 +02:00
Jukka Rissanen 4a322c6a7c net: ppp: Handle received Discard-Request
We must discard the received Discard-Request silently.
See RFC 1661 chapter 5.9 for details.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen c4a692a85f net: ppp: Add proper support to receive Echo-Reply message
Currently only net-shell calls net_ppp_ping() command, so make
it return the amount of time that it took to receive Echo-Reply
so the net-shell can print the round trip time value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen eff46a5232 net: ppp: Reject unhandled protocols
If we receive a protocol that we do not currently handle, then
return Protocol-Reject to peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 3e481f9d07 net: ppp: Allow delay of PPP protocol handshakes
By default PPP is started immediately when the network interface
goes up. This can be problematic especially when debugging the beast
so allow user to delay the startup.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 4a5543db25 net: shell: Add ppp network interface support
Print point-to-point network information properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen 02239a99a2 net: ppp: Add IPV6CP support
Initial version for PPP IPv6 Control Protocol.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Jukka Rissanen f95938da0f net: ppp: Initial support for point-to-point protocol
This implements ppp L2 component, LCP and IPCP modules.

Fixes #14034

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-29 10:24:46 +03:00
Markus Becker 3178555878 net: openthread: Allow DHCP configuration of OpenThread in Zephyr
Certain Thread implementations (notably ARMs) require a DHCPv6
implementation.
Allow the usage of the relevant OpenThread configuration parameters in
Zephyr.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2019-07-22 13:23:05 +03:00
Joakim Andersson 0ac83180fd Bluetooth: host: Move address string parsing to bluetooth API
Bluetooth address parsing has been duplicated across the different
sub-shell files. Also missing parsing of identity/resolved addresses.
Move parsing of string close to parsing to string for a symmetrical API

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-16 12:44:18 +02:00
Joakim Andersson 7a93e948a9 kernel: lib: Add convert functions for hex strings and binary arrays
Move duplicate hex2bin and add bin2hex function so that application can
use the functions and avoid code duplication.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-16 12:44:18 +02:00
Tomasz Bursztyka c8f7c329a2 net/lldp: Simplify Kconfig file
Let's remove depends on NET_LLDP from all the options. It avoids this:
 # CONFIG_NET_LLDP is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_OFF is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_ERR is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_WRN is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_INF is not set
 # CONFIG_NET_LLDP_LOG_LEVEL_DBG is not set
 CONFIG_NET_LLDP_LOG_LEVEL_DEFAULT=y
 CONFIG_NET_LLDP_LOG_LEVEL=3
 CONFIG_NET_LLDP_CHASSIS_ID="CHASSIS_ID_PLACEHOLDER"
 CONFIG_NET_LLDP_PORT_ID="PORT_ID_PLACEHOLDER"

And instead it will generate this:
 # CONFIG_NET_LLDP is not set

Make the menu as an enablement config option as well.

Adapting lldp header file relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-10 15:24:32 +03:00
Tomasz Bursztyka 845f070c1e net/ethernet: Cleanup a bit on the usage of ifdefs
ARP, LLDP and GPTP functions have dummies in case of being disabled so
let's use IS_ENABLED() accordingly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-10 15:24:32 +03:00
Robert Lubos 1ee8e0b055 net: openthread: Verify iface in net_mgmt event handler
OpenThread did not verify if the interface provided in the net_mgmt
handler is actually an OpenThread interface. In result, when multiple
network interfaces were used, different interfaces were processed by the
OpenThread handler, ending up in a crash.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-07-03 19:51:34 +03: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 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.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 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
Jukka Rissanen 95e8498c27 net: ptp: Add usermode support to net_eth_get_ptp_clock_by_index()
Make net_eth_get_ptp_clock_by_index() clock API to work with user space.
Create also unit test for testing this user mode support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-25 15:22:51 +03:00
Jukka Rissanen 11b06fab76 net: ethernet: Add net_eth_get_ptp_clock_by_index() function
This can be used to get the PTP clock if only network interface
index is known.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-25 15:22:51 +03:00
Jukka Rissanen def6b14aa7 net: ptp: clock: Create a dummy inline func for net_eth_get_ptp_clock()
Follow the style in other similar functions in this file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-25 15:22:51 +03:00
Nicolas Pitre 3c6c8ed063 gptp: don't cast pointers to ints
Let's use longs here so 64-bit pointers will fit.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 10:18:20 +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
Tomasz Bursztyka 344d4bdce0 net/arp: No need of 64bits timer precision on ARP requests
The 32bits one can hold up to about 50 days, this is more than enough
knowing that ARP request timeout is 2 seconds.

So reducing the request start time to 32bits.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-05-23 22:22:16 +03:00
Jukka Rissanen 19b48687ec net: ethernet: Drop pkt if MAC dst is bcast address but IP is not
Drop packet if it has broadcast destination MAC address but the IPv4
destination address is not multicast or broadcast address.
See RFC 1122 ch 3.3.6 for details.

Fixes #16276

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-21 16:43:38 +03:00
Jukka Rissanen 9552796361 net: arp: Drop request where src hw address is our address
We replied to an ARP request that has the same Sender Hardware Address
than that of ours. Such an ARP request must be discarded, no reply
should be sent and translation table should not be updated.

Fixes #16110

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-14 12:36:07 +03:00
Jukka Rissanen a84e9345a6 net: arp: Use proper dest hw address after receiving a request
If a packet is received with Ethernet source address different
from ARP's sender hardware address field, then DUT must use the
latter address in response packets.

Fixes #16098

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-14 12:35:48 +03: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
Luiz Augusto von Dentz 5506a4d228 net: bt: Set NET_IF_NO_AUTO_START flag
This make use of NET_IF_NO_AUTO_START flag so Bluetooth interfaces are
not automatically enabled after initialized.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-07 11:16:29 +03:00
Luiz Augusto von Dentz 95cadb7bfe net: bt: Add multi-link support
This adds support for having multiple connections based on BT_MAX_CONN.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-07 11:16:29 +03:00
David B. Kinder c5112327a7 doc: fix mentions of Wi-Fi trademark name
The approved trademark name is Wi-Fi so update references to WiFi and
other spellings to Wi-Fi in documentation and Kconfig help strings.
(Note that use of spelling variatios of "wifi" in module names, CONFIG
names, link names and such are untouched.)

https://www.wi-fi.org/

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-05-06 20:10:59 -04:00
Jukka Rissanen c4fcc604e6 net: arp: No need to check pkt for NULL
The pkt variable cannot be NULL at this point so the check for
nullness is not needed.

Coverity-CID: 198002
Fixes #15777

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-02 13:22:09 +03:00
Ravi kumar Veeramally 49cb24a5eb net: ethernet: l2: Add support for VLAN tag strip
If ethernet controller has VLAN tag strip flag enabled
(ETHERNET_HW_VLAN_TAG_STRIP), L2 etherent will not read tag from
the Rx etherent header. Instead it will fetch VLAN tag from
net packet metadata.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-04-26 10:46:27 +03:00
Robert Lubos 51a9e6f534 net: openthread: Do not overwrite stored dataset with defaults
This commit prevents a situation when stored and possibly modified
commissioner dataset is overwritten with default configuration during
OpenThread initialization.

It introduces a new function, openthread_start, which verifies if the
dataset is already stored, and if not, depending on configuration,
preloads the default configuration or initiates the join procedure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-04-23 16:43:36 +03:00
Jukka Rissanen 712103d594 net: if: Add access functions for network interface flags
Provide access functions for manipulating network interface flags.
There is no need for the caller of this API to know about the inner
details of the flags.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-23 13:11:03 +03:00
Patrik Flykt 3e798dfd88 net: ethernet: Send sender IP address in ARP announce packets
In addition to checking that the ARP entry does not exist as the
implementation is done currently, also check if the ARP packet
is due to IPv4 link local address configuration. In both cases
use the provided IPv4 address instead of the one set for the
interface.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-17 10:38:49 -05:00
Patrik Flykt 7e14cff8d7 net: ethernet: Set NET_ETH_PTYPE_ARP for IPv4 link local packet type
IPv4 link local uses ARP to detect conflicting addresses. Properly
set the ethernet packet type to NET_ETH_PTYPE_ARP when probing
for address duplicates.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-17 10:38:49 -05:00
Ravi kumar Veeramally 189b22789c net: vlan: Etherent layer missed L2 header
When VLAN is enabled, ethernet l2 layer fills ethernet header
but not added to the network buffer.

Fixes #15346

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-04-11 13:20:40 -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
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
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