Commit graph

943 commits

Author SHA1 Message Date
Torsten Rasmussen 36f5600387 kconfig: net: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/net and drivers/ethernet/Kconfig.e1000 settings
having `[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.

The following settings has EXPERIMENTAL removed as they are considered
mature:
- NET_OFFLOAD
- NET_PROMISCUOUS_MODE

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-25 10:46:48 +02:00
Torsten Rasmussen 587285e4de kconfig: canbus: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/canbus, subsys/net/l2/canbus, and drivers/can settings
having `[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-22 13:59:21 +02:00
Damian Krolik 726656dda5 net: openthread: Add crypto backend based on PSA API
OpenThread has lately got an option to provide a custom
crypto backend that replaces the default, based on mbedTLS
API. Implement a backend based on ARM PSA crypto API that
is better suited for applications willing to take advantage
of the ARM trust zone technology.

Add Kconfig option: OPENTHREAD_CRYPTO_PSA_ENABLE which
enables that backend.

Also, another Kconfig option:
OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE, implied by the
former, which enables usage of key references instead of
literal keys in OpenThread. It will eventually allow
OpenThread applications to keep sensitive data such as
encryption keys in the secure storage, accessible from the
secure world only.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2021-10-17 11:51:38 -04:00
Robert Melchers 59fcf8c031 net: ethernet: ARP addresses being filled with mcast addresses
Fixes #38994, ARP messages were being sent to IPvXmcast MAC addresses
rather than the expected source MAC address or the broadcast address.

Signed-off-by: Robert Melchers <rmelch@hotmail.com>
2021-10-07 11:23:20 +02:00
Jani Hirsimäki e913fda436 net: l2: wifi_shell: mac address in scanning results
Showing mac address in scanning results.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2021-10-07 10:55:37 +02:00
Alex Sergeev e7778b8584 net: ptp: extract PTP interfaces outside gPTP subsys under NET_L2_PTP
As per #38352, we would like to start building out PTP (IEEE 1588)
support for superset of gPTP functionality in Zephyr. This is the first
step to abstract away some key interfaces from NET_GPTP umbrella to
NET_L2_PTP.

Signed-off-by: Alex Sergeev <asergeev@carbonrobotics.com>
2021-09-28 20:01:16 -04:00
Markus Fuchs 54dbfe2229 net: ethernet: Refactor IPv4 to MAC multicast address conversion
Refactor IPv4 multicast address to MAC multicast address conversion
into its own function, so it can be reused by drivers as it is already
possible for IPv6 multicast addresses.

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2021-09-23 04:19:31 -04:00
Aleksander Wasaznik fbe7699c82 Bluetooth: Host: Doc fixup for rename of BT_SECURITY_L*
BT_SECURITY_LOW and etc. were previously renamed and are no longer
valid.

The original rename is in the following commits:
1c48757d94 (New names, deprecate old)
5f2a9ba8e4 (Remove deprecated names)

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemiconductor.no>
2021-09-13 11:56:21 -04:00
Eduardo Montoya 36459a95ea net: openthread: allow to enable/disable TCP
Allow to enable/disable the OpenThread TCP implementation. Disable
it by default.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-09-01 10:37:41 +02:00
Przemyslaw Bida f77c7dc2c8 manifest: Regular upmerge to bring the openthread CSL fixes.
Periodic upmerge of OpenThread.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2021-08-30 13:32:53 +02:00
Johann Fischer f460848002 net: ot: rework NCP interface configuration
Rework NCP interface configuration and NCP sample. Remove
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_DEV_NAME and
CONFIG_OPENTHREAD_COPROCESSOR_SPINEL_ON_UART_ACM Kconfig
options in favor of chosen node zephyr,ot-uart usage.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-23 18:53:47 -04:00
Stancu Florin 4561ea0ae2 net: ieee802154: software dest address filtering
Checks PAN ID for matching self address / broadcast, then the short /
extended address based on the used address mode.

Only when IEEE802154_HW_FILTER is not advertised by driver.

Signed-off-by: Stancu Florin <niflostancu@gmail.com>
2021-08-17 09:19:39 -04:00
Daniel Leung e912a0533a drivers: ethernet: build as static library
Instead of putting object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.

Note that the include to subsys has been moved from
under the drivers into subsys, as it is actually
the subsystem's job to make sure the include
directories are correct.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-17 06:06:03 -04:00
Fabio Baltieri f88a420d69 toolchain: migrate iterable sections calls to the external API
This migrates all the current iterable section usages to the external
API, dropping the "Z_" prefix:

Z_ITERABLE_SECTION_ROM
Z_ITERABLE_SECTION_ROM_GC_ALLOWED
Z_ITERABLE_SECTION_RAM
Z_ITERABLE_SECTION_RAM_GC_ALLOWED
Z_STRUCT_SECTION_ITERABLE
Z_STRUCT_SECTION_ITERABLE_ALTERNATE
Z_STRUCT_SECTION_FOREACH

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2021-08-12 17:47:04 -04:00
Eduardo Montoya 570dab7a1a net: openthread: add Netdata Publisher Kconfig option
Enable new feature from the upmerge:
- OPENTHREAD_NETDATA_PUBLISHER

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-08-11 11:29:36 -04:00
Lingao Meng 8e1682d1ea samples: conn_cb replace to const zsector
It is more efficient and saves part of RAM
by replacing it with static one dynamically.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-08-11 13:42:28 +02:00
Eduardo Montoya cf57b86363 net: openthread: add three configuration options
Enable to configure:
- `OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH`
- `OPENTHREAD_CONFIG_IP6_MAX_EXT_UCAST_ADDRS`
- `OPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS`

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-07-29 11:00:19 -04:00
Arvin Farahmand c95e0825d2 dsa: updated api to use net_if
Change DSA API to use `net_if` directly to make API calls instead of
indirectly via `dsa_context` and `switch_id`.
Remove unused `switch_id`, `switch_enable_port`, and `dsa_get_context`.

Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
2021-07-26 19:37:22 -04:00
Nicolas Pitre b6855b23b9 net: bridge: Ethernet bridge shell utility
This provides a command line interface to query and modify
bridge instances, similar to Linux's brctl utility.
It can be used to inspect an application's bridge usage,
or manage a bridge of its own in a generic way.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-07-21 18:20:01 -04:00
Nicolas Pitre 89482f0119 net: ethernet: bridging support
This adds the ability to create Ethernet bridges for connecting
separate Ethernet segments together to appear as a single
Ethernet network.

This mimics the Linux functionality of the same name.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-07-21 18:20:01 -04:00
Pieter De Gendt de13034502 net: openthread: add Kconfig options for periodic parent search
The openthread has enhanced features for periodic parent search,
this commit adds kconfig options to enable and configure these.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-07-15 15:16:32 +02:00
Robert Lubos 942ece2a3d net: l2: ieee802154: Fix LL address handling on frame reception
6lowpan module can swap the original buffer with a newly allocated one
during decompression in case the decompressed header would not fit into
the original buffer. Therefore, storing the LL address offset and
restoring the pointer after decompression as it is done today is not
correct, as the new packet with decompressed IPv6 header will not
contain the LL header.

As the 6lowpan module doesn't deallocate the original buffer and
doesn't overwrite the LL header, its fine to use the original
pointers as they are.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-07-09 09:10:56 -04:00
Damian Krolik bf3c6e7ba4 manifest: update openthread
Regular OpenThread upmerge to bring in a fix for a possible
infinite loop and support for DNS service subtypes.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2021-07-07 07:47:52 -05:00
Pieter De Gendt a5ec72418c net: openthread: Convert API worker thread to a work queue
Direct openthread API usage requires explicit locking,
which is also used internally.
Exposing a work queue through the openthread context allows
work to be submitted without the need to block other threads.

In particular with CONFIG_OPENTHREAD_MANUAL_START, application
logic can offload work which otherwise would need to wait for
the lock to become available.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-06-29 11:27:54 -04:00
Eduardo Montoya 0f73fbdbfe drivers: ieee802154: add CSL receiver for nRF5
Implement CSL receiver functionality in nRF5 radio driver.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-06-24 11:31:24 -04:00
Pieter De Gendt 72985d5f32 net: openthread: Protect OT API calls during initialization
The openthread initialization in turn calls platform specific
functions, lock the API during this step.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2021-06-24 11:29:50 -04:00
Eduardo Montoya 3417c9a132 net: openthread: remove unneded Kconfig dependency
`OPENTHREAD_SHELL` does no longer dependend on
`OPENTHREAD_COPROCESSOR` being disabled.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-06-19 16:54:44 -05:00
Kweh Hock Leong 77d8662454 net: eth: Add TXTIME configuration support
Allow caller to either set or receive per queue Ethernet TXTIME
configuration option.

Signed-off-by: Kweh Hock Leong <hock.leong.kweh@intel.com>
2021-06-14 07:00:10 -04:00
Jukka Rissanen 44efc18a78 net: eth: Add Qbu configuration support
Allow caller to either set or receive various Ethernet Qbu
configuration options defined in IEEE Std 802.1Qbu-2016
specification.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-14 07:00:10 -04:00
Jukka Rissanen d0a45e243f net: eth: Add Qbv configuration support
Allow caller to either set or receive various Ethernet Qbv
configuration options defined in IEEE Std 802.1Qbv-2015
specification.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-14 07:00:10 -04:00
Lukasz Maciejonczyk 8b12311bdf net: openthread: add option to configure software transmission security
If radio driver supports transmission security we need an option
to disable transmission security which by default is done by OT stack
for Thread v1.2

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-06-04 16:19:16 -05:00
Joakim Andersson faae326648 net: l2: bluetooth: Handle error if failed to register server
Return error code if init code failed to register the L2CAP server.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-28 10:44:47 -05:00
Lukasz Maciejonczyk 977aba6d02 net: openthread: Fix multiple Kconfig enablers for Link Metrics
Remove duplicated enabler for Link Metrics feature.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-05-11 09:53:29 +03:00
Aurelien Jarno c30339aa16 net: openthread: Select ECDSA when SRP is enabled
SRP client and server require ECDSA to be enabled otherwise the build
fails. Select OPENTHREAD_ECDSA for both OPENTHREAD_SRP_CLIENT and
OPENTHREAD_SRP_SERVER options.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-05-10 05:29:19 -05:00
Aurelien Jarno bc9e759ca4 net: openthread: Move SRP Kconfig options to Kconfig.features
OPENTHREAD_SRP_CLIENT and OPENTHREAD_SRP_SERVER are Thread features and
not Thread configuration, so move them to Kconfig.features.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-05-10 05:29:19 -05:00
Aurelien Jarno a80e28a26c net: openthread: Make child related options only visible on FTD
The OPENTHREAD_MAX_CHILDREN and OPENTHREAD_MAX_IP_ADDR_PER_CHILD options
make not sense for a MTD device. Make them depend on OPENTHREAD_FTD.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-05-10 05:29:19 -05:00
Torsten Rasmussen 3a0951fcd0 openthread: kconfig: rework OpenThread security configurations
With the updates to mbedTLS Kconfig it is now possible to update the
OpenThread security configurations by disabling the mbedTLS prompt and
avoid stuck symbol selection.

As part of this, the OpenThread security selection has been reworked
into a choice which ensures only a single security selection can be
chosen.

And the OPENTHREAD_MBEDTLS itself has been made promptless to ensure
other parts of the build system can select a specific OpenThread
security implementation and disable user selection, if the module or
sample require such behavior.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 15:24:23 -05:00
Ioannis Glaropoulos 61df25d867 Revert "openthread: kconfig: rework OpenThread security configurations"
This reverts commit 88f3a9899a.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 09:59:22 -05:00
Torsten Rasmussen 88f3a9899a openthread: kconfig: rework OpenThread security configurations
With the updates to mbedTLS Kconfig it is now possible to update the
OpenThread security configurations by disabling the mbedTLS prompt and
avoid stuck symbol selection.

As part of this, the OpenThread security selection has been reworked
into a choice which ensures only a single security selection can be
chosen.

And the OPENTHREAD_MBEDTLS itself has been made promptless to ensure
other parts of the build system can select a specific OpenThread
security implementation and disable user selection, if the module or
sample require such behavior.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-05-08 07:11:00 +02:00
Jukka Rissanen 2697275d23 net: ppp: Convert to use k_fifo instead of k_work
Following commits will remove k_work from net_pkt, so convert
PPP L2 to use k_fifo when sending PPP data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-05-07 09:46:44 -05:00
Jukka Rissanen 0808ead6ff net: 6locan: Convert to use k_fifo instead of k_work
Following commits will remove k_work from net_pkt, so convert
6locan L2 to use k_fifo between application and TX thread, and
driver and RX error handler.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-05-07 09:46:44 -05:00
Lukasz Maciejonczyk 103b516a3c net: openthread: add Link Metrics API
This commit implements the OpenThread APIs to configure Enhanced-ACK
Based Probing in radio for a specific Initiator. This is needed for
Link Metrics functionality.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-05-06 09:57:15 -05:00
Robert Lubos 39aee39cf9 net: openthread: Align with the new NCP API
OpenThread modified its NCP API, so we need to align with these changes
in Zephyr.

One of the major changes was removal of UART from the platform APIs.
`openthread/platform/uart.h` header file was moved to
`examples/platforms/util/uart.h` so we need to use the new location in
Zephyr. This means that OpenThread no longer impose the UART API but for
the simplicity of the upmerge I've kept the UART APIs as they are for
now.

The NCP initialization function have now to register a send handler,
and the appropriate transport driver have to call NCP callbacks when
transmission/reception is done. For now, re-use the existing code of
the UART driver, just as the upstream NCP application does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-30 12:55:02 -05:00
Robert Lubos 7ca3ccdd0d net: openthread: Introduce new OpenThread options
Introduce new OpenThread configuration options from the upmerge.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-04-30 12:55:02 -05:00
Piotr Szkotak c60d500bf9 net: openthread: Increase stack sizes with FP context
This PR increases the OpenThread stacks to compensate
for the runtime increase of the MPU stack guard
when the usage of the FP context is detected.

Signed-off-by: Piotr Szkotak <piotr.szkotak@nordicsemi.no>
2021-04-29 09:50:44 -04:00
Marcin Niestroj d30b68a39a net: ppp: ipcp: use dns_resolve_reconfigure() API
Use recently introduced API, which takes care of gracefully closing any
pending DNS requests and replacing existing DNS server list with new
one.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-29 08:00:09 -04:00
Gerard Marull-Paretas 3daf9f2d97 net: remove usage of device_pm_control_nop
If device PM is not implemented just use NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-27 16:28:49 -04:00
Luiz Augusto von Dentz 33d95894e1 Bluetooth: Align error handling of send functions
This aligns the error handling of send function to never unref the
buffer in place so the caller retain the ownership of the buffer
whenever there is an error.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-04-20 18:20:04 -04:00
Jukka Rissanen d7321152a9 net: virtual: Remove unnecessary null check
The virtual_iface is already NULL checked by net_if_get_by_iface()
at the beginning of the function so no need to do it here too.

Coverity-CID: 220535
Fixes #34006

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-20 13:44:39 -04:00
Jukka Rissanen c2877579ba net: virtual: Remove dead code
Simplifying the loop in order to remove dead code (ctx_up is
always NULL after the slist loop.

Coverity-CID: 220538
Fixes #34003

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-20 13:44:39 -04:00
Krzysztof Chruscinski 67fade04a0 net: l2: bluetooth: Add cast to forward declared struct
Logging v2 is using _Generic keyword for detecting type of
log message arguments. Apparently, it does not support handling
of pointers to forward declared structures. Added casting to void *.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Peter Bigot 188cb2cb7c net: Conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-14 07:07:40 -04:00
Eduardo Montoya 1d668d4b7c net: openthread: add microseconds timer API
Add OpenThread API to handle microseconds timer, to be used initially
by CSL receiver.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-04-12 17:01:14 +03:00
Jukka Rissanen ce2abc26b5 net: capture: Catch sent and received packets
Create net_l2_send() function which will be called by each L2
sending function so that we can catch all the network packets
that are being sent. Some L2 layers send things a bit differently,
so in those cases call the net_capture_send() directly by the L2
layer.
Add network packet capture call in receive side after the pkt has
been received by the RX queue handler. This avoids calling the
net_capture_send() from ISR context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-02 07:24:06 -04:00
Jukka Rissanen e917d80473 net: capture: Add support for network packet capturing
Add infrastructure to allow user to configure the system so that
all the network packets, that are sent to or received from a specific
network interface, are sent to remote system for analysis.
The captured network packets are placed as a payload in UDP packet,
which is then sent inside a tunnel to a remote host. The host can
then receive the packets and for example show them in wireshark.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-02 07:24:06 -04:00
Jukka Rissanen 934caba82b net: l2: ipip: Support more than one IPIP tunnel
Alloc code to create more than one IPIP tunnel interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-02 07:24:06 -04:00
Jukka Rissanen 574b8725e0 net: l2: ipip: Add capability bit for IPIP tunnel
The IPIP tunnel capability bit helps to detect which network
interface supports IPIP tunneling.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-02 07:24:06 -04:00
Jani Hirsimäki 5d76e8aca8 net: ppp: dialup enablers
Introducing PPP dialup features to enable e.g. usage of nrf9160
based board as a dialup modem for transferring ip data over PPP
 (e.g. windows dial up), i.e. usage of Zephyr PPP as a server for
 providing MTU/MRU, IP address and DNS addresses for a PC:
- PPP LCP MRU option (configurable)
- PPP server: IPCP ip and dns address peer options to enable
providing IP and DNS addresses for PPP peer.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2021-04-01 09:43:56 +03:00
Jukka Rissanen 10142ac99c net: virtual: ipip: Add IP tunneling driver
Add a IP-to-IP tunneling driver. It supports both IPv4 and IPv6.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-29 07:40:24 -04:00
Jukka Rissanen 36be096c43 net: virtual: Add virtual network interface support
This can be used to implement tunneling, VPN etc. The virtual
interfaces can be chained together to support multilayer
network interfaces.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-03-29 07:40:24 -04:00
Kumar Gala 0bb4665df7 include: Move ptp_clock.h to drivers/ptp_clock.h
Move ptp_clock.h out of the top level include/ dir into
include/drivers/ptp_clock.h and deprecated the old location.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-25 10:09:33 +02:00
Marcin Niestroj c1f7b9f45a net: l2: ethernet: fix k_work API usage in carrier on/off handling
net_eth_carrier_on() and net_eth_carrier_off() call k_work_init() on
work item that can be pending or still be processed in another thread.
This results in undefined behavior.

Initialize work item once and use an atomic flag to switch between
up/down carrier state. Submit work to workqueue whenever up/down carrier
state changes, so that last state is always properly propagated to
network interface layer.

While at it, save network interface pointer during ethernet context
initialization, so that is becomes static (and thread-safe) during whole
ethernet context lifetime.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-03-23 16:18:29 +02:00
Marcin Niestroj e3a41194f7 net: l2: ppp: fix k_work API usage in carrier on/off handling
net_ppp_carrier_on() and net_ppp_carrier_off() call k_work_init() on
work item that can be pending or still be processed in another thread.
This results in undefined behavior.

Initialize work item once and use an atomic flag to switch between
up/down carrier state. Submit work to workqueue whenever up/down carrier
state changes, so that last state is always properly propagated to
network interface layer.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-03-23 16:18:29 +02:00
Eduardo Montoya ddf5f607e1 net: openthread: enable deterministic ECDSA
When using `OPENTHREAD_ECDSA` deterministic variant has to be
enabled after some OpenThread changes. Also generic public key
functions are required.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-03-17 09:25:04 +02:00
James Harris b10428163a kernel: sem: add K_SEM_MAX_LIMIT
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".

Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.

In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.

These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-05 08:13:53 -06:00
Jim Paris ffec5aa7f7 ppp: add net events for PPP dead and running
This lets an application detect when a PPP connection fails to establish
or terminates, so that the connection can be reattempted (for example,
by setting carrier off and on).

Signed-off-by: Jim Paris <jim@jim.sh>
2021-03-03 15:56:13 +02:00
Kamil Kasperczyk 7b26544547 net: openthread: added heap related otPlat methods implementation
* Added implementations of otPlatCAlloc and otPlatFree methods
necessary for the OpenThread in case of using EXTERNAL_HEAP.
* Added CONFIG_OPENTHREAD_DNSSD_SERVER option to allow enabling
OT_DNSS_SERVER feature.

Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
2021-02-18 18:23:06 +02:00
Eduardo Montoya 99ccdabee3 net: openthread: remove misleading NCP configuration option
Remove `OPENTHREAD_CONFIG_NCP_BUFFER_SIZE` define since it does not
exist in OpenThread.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-02-16 15:30:36 +03:00
Eduardo Montoya fb20d0022a net: openthread: add CoAP Block Kconfig option
Enable new feature from the upmerge:
- OPENTHREAD_COAP_BLOCK

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-02-08 11:36:45 -05:00
Tomasz Bursztyka a980762f70 net/ieee802154: Drop fragmented packet if first frag is not present
Bogus fragmented packet could be sent without a FRAG1 fragment and hit
reassembly. Let's make sure this does not happen.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka 2a423bc6d3 net/ieee802154: Do not unreference one time too many a fragmented packet
In case the current packet is the same as the cached one, let's not
unreference it while clearing the cache.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka 0ebd300001 net/ieee802154: Make sure L2 drop any ACK frames
Though ACK frames are not meant to reach L2 (drivers must ensure this
never happens), let's "re-enforce" the L2 by dropping them.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka 6917d26848 net/ieee802154: Avoid NULL pointer de-reference in packet reassembly
In case the very first fragment holds all the data already.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka 606807940c net/ieee802154: Each fragment should be at least of its header's length
Not validating this length could lead to integer underflow and memory
corruption.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Tomasz Bursztyka 6f1ab93c66 net/ieee802154: Invalidate frame in case of no address in relevant modes
All addressing mode but IEEE802154_ADDR_MODE_NONE should have a valid
address. If not, the frame is invalid.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2021-02-03 17:39:26 -05:00
Eduardo Montoya 58fe3e1fd6 net: openthread: add SRP Kconfig options
Enable new features from the upmerge:
- OPENTHREAD_SRP_CLIENT
- OPENTHREAD_SRP_SERVER

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-01-26 07:29:10 -05:00
Eduardo Montoya 80c0f3fbb6 net: openthread: configure required masterkey
After the latest upmerge, OpenThread requires explicit configuration
of the Master Key. This commit adds a Kconfig symbol that can be
used to setup its value. By default no Master Key is configured and
OpenThread generates a random one.

The Sockets Echo samples are configured with a fixed key with this
commit.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2021-01-26 07:29:10 -05:00
Anas Nashif 7f44d74433 doc: fix typo trough -> through
Fix common typo.

Fixes #31543

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 17:53:06 -05:00
Lukasz Majewski ca5e3ea654 eth: Add support for Distributed Switch Architecture [DSA] switches
This patch add support for DSA switches to Zephyr.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2021-01-20 10:03:42 +02:00
Fabio Baltieri 36d8230d15 net: bt: enable solicit node multicast group registration
6lowpan over BLE should work without solicit node multicast messages
according to RFC7668[1], but that requires Neighbor Solicitation with
Address Registration Option, which is currently not implemented in
either Zephyr or Linux. This is causing the router to fallback to normal
neighbor solicitation based discovery, but the NS frames are being
discarded in the host stack because the solicit node multicast groups
are not registered.

This drops the NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE as a workaround
and adds a TODO about it.

[1] https://tools.ietf.org/html/rfc7668#section-3.2.3

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-01-14 16:57:07 +02:00
Lukasz Maciejonczyk ad360c42af net: openthread: Make radio workqueue stack size configurable
Add Kconfig option for configuring OpenThread radio transmit workqueue
stack size.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2021-01-13 11:29:30 +02:00
Joel Frazier 2d215484cc net: l2: openthread: join thread mcast addrs added to zephyr
Modifies openthread shim layer to automatically join multicast
addresses as they are added to zephyr from openthread, unless the
address is interface-local or link-local. This allows incoming
openthread multicast group messages to avoid being filtered by
zephyr ipv6 recv.

Fixes #31085

Signed-off-by: Joel Frazier <frazieje@gmail.com>
2021-01-11 10:48:26 +02:00
Kumar Gala 82767ef3bb bluetooth: Convert DEVICE_AND_API_INIT to DEVICE_DEFINE
Convert drivers to DEVICE_DEFINE instead of DEVICE_AND_API_INIT
so we can deprecate DEVICE_AND_API_INIT in the future.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-19 20:01:42 -05:00
Rafał Kuźnia 3bf526beea net: openthread: add shell dependency to OPENTHREAD_SHELL
This commit replaces the 'select SHELL' statement with
'depends on SHELL' in OPENTHREAD_SHELL config option.

This ensures, that shell will not be implicitly enabled
when OpenThread stack is built.

Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
2020-12-18 12:56:33 -05:00
Alexander Wachter 05275ecf6e drivers: can: rework zcan_frame and zcan_filter
Reordering of the struct elements to match the Linux format.
The __packed() is not necessary anymore.
std_id and ext_id is merged to id in the frame and filter.
Additionally, the frames are ready for CAN-FD.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2020-12-17 11:07:53 +01:00
Eduardo Montoya f0379e7ccb net: openthread: enable new CSL and TREL config options
Enable new OpenThread configuration options:
- OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
- OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
- OPENTHREAD_CONFIG_CSL_SAMPLE_WINDOW
- OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD

Update OPENTHREAD_CONFIG_PLAT_LOG_MACRO_NAME

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-12-16 18:06:47 +01:00
Robert Lubos 5d038eb014 net: openthread: Add option to enable software CSMA backoff
Add option to enable software CSMA backoff in the OpenThread MAC layer.

This allows to run CSMA procedure correctly in radios that do not
support hardware CSMA backoff, and use them as RCP, where this feature
is required.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-12-10 12:58:07 +01:00
Jukka Rissanen f02fd19706 net: Adjust the thread priorities
If networking pre-emptive thread priorities are enabled,
then use the proper macro to enable them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-11-20 12:57:29 +02:00
Markus Becker 638b5f389f net: openthread: OpenThread RCP mode integration into Zephyr
* Add RCP library.
* Conditionally remove non required libraries not required for RCP.
* Drop :option: marker for CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_ACM

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-11-19 12:34:14 +01:00
Anas Nashif 63b7313c06 net: lldp: use llabs with int64_t
subpress warnings from llvm:

warning: absolute value function 'abs' given an argument of type
'int64_t' (aka 'long long') but has parameter of type 'int' which may
cause truncation of value [-Wabsolute-value]

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-11-19 08:41:56 +01:00
Eduardo Montoya dc56ace3da net: openthread: fix maximum number of children range
This commit corrects the maximum allowed amount of children to
match Thread specification.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-11-04 18:08:48 +02:00
Eduardo Montoya 8399a6067d net: openthread: allow to configure platform info
This commit adds the option to configure the platform information
string of OpenThread.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-11-04 18:08:48 +02:00
Lukasz Maciejonczyk 102084f873 net: openthread: Add Kconfigs to change values in Zephyr port
Refactor openthead zephyr config file. Add missing KConfigs.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2020-10-21 16:09:56 +03:00
Damian Krolik 62a5179b7b openthread: add openthread_api_mutex_try_lock()
Existing openthread_api_mutex_lock()/unlock() functions are
crucial to assure thread safety of an application which
needs to use OT API directly, but some applications may also
require a non-blocking version of the former for less critical
OT-related tasks.

Add openthread_api_mutex_try_lock() which never waits and
exits immediately if the mutex is held by another thread.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2020-10-20 16:39:22 +03:00
Benjamin Lindqvist c7b6706b42 net: ppp: Ensure IPCP address is always removed
If an address was obtained by IPCP, it should always be removed in
ipcp_down(). This commit replaces the predicate with something slightly
more robust.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-19 18:29:02 +02:00
Eduardo Montoya 84158f54b9 net: openthread: fix unwanted 802.15.4 radio up
This commit moves IPv6 initialization from OT init to OT start to
avoid unwantedly bringing 802.15.4 radio up.

Previously, even when OT manual start was enabled, the radio would
be receiving frames resulting in unnecessary power consumption and
causing issues for instance when the device just wants to use
Bluetooth for provisioning befor moving to Thread.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-10-19 12:55:52 +03:00
Marek Porwisz 5d57b396b8 net: openthread: Increase the number of allowed children
Another team reported that current default values for number of allowed
IP addresses per child (4) and and max number of children (10) are too
small for some customers.
Increased the values allowed configuring child count.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-10-19 12:55:07 +03:00
Benjamin Lindqvist 8c22983234 net: l2: ppp: Remove ipcp address on network down
Without removing the stale address obtained during IPCP, it will still
be present the next time we do IPCP, marked as "in use" by the network
stack even if it is stale. This turned out to be a showstopper for
restarting the PPP stack on devices without static IP.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-06 11:57:46 +03:00
Rafał Kuźnia 5b7efd3277 net: openthread: add kconfigs to change values in zephyr port
This commit adds additional Kconfigs that allow for changing
configuration values for the Zephyr port in OpenThread.

Those values are:
- number of the internal OT message buffers
- number of the state change callbacks
- number of the EID-to-RLOC cache entries
- size of the NCP buffer

Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
2020-09-30 14:38:04 +03:00
Jukka Rissanen ccea4d3258 net: ethernet: Check IPv4 multicast pkt using util function
Instead of directly checking the multicast IPv4 address, use
the net_ipv4_is_addr_mcast() utility function.

Fixes #26584

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-09-30 14:31:13 +03:00
Jakub Rzeszutko 005103739c shell: examples cleanup
Remove obsolete include of the shell_uart.h file.
It is sufficient to include the shell.h file.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
2020-09-29 10:48:47 +02:00
Aurelien Jarno 1df2de346b net: openthread: Remove old flash code
Since commit b3a1ede830 OpenThread uses the Zepyhr settings submodule
instead of writing to the flash directly. The flash.c file is not
compiled anymore, so let's just remove it. Also remove the
OT_PLAT_FLASH_PAGES_COUNT Kconfig option which was solely used by that
file.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2020-09-28 14:17:22 -05:00
Jukka Rissanen 3b64d57943 net: ethernet: Make sure Ethernet header is in the recv pkt
Check that Ethernet header is in the first net_buf fragment.
This is very unlikely to happen as device driver is expected
to only deliver proper Ethernet frames to upper stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-09-28 14:25:13 +03:00
Jukka Rissanen be072b1255 net: ethernet: Check that header is valid
Saw this crash with heavily loaded system in mimxrt1050_evk:

<err> os: ***** MPU FAULT *****
<err> os:   Data Access Violation
<err> os:   MMFAR Address: 0xc
<err> os: r0/a1:  0x80000ab0  r1/a2:  0x800f6a60  r2/a3:  0x00000000
<err> os: r3/a4:  0x800f72a0 r12/ip:  0x00000000 r14/lr:  0x6000eb43
<err> os:  xpsr:  0x41000000
<err> os: Faulting instruction address (r15/pc): 0x6000dc82
<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
<err> os: Current thread: 0x80001a18 (rx_workq)
<err> os: Halting system

Where the fault at 0x6000dc82 points to ethernet_recv()

	uint16_t type = ntohs(hdr->type);
6000dc82:	89ab      	ldrh	r3, [r5, #12]

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-09-28 14:25:13 +03:00
Marek Porwisz 4ad1e0cfd1 net: openthread: Fix stack overflow for joiner
Fixed stack being to small for joiner operations.
Enabled auto joining even in case of manual start.
Fixed attachement of SED on norfic radios.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-09-24 15:55:30 -05:00
Jukka Rissanen e3fd17072e net: gptp: Allow user to tweak priority1 and priority2 values
Instead of hardcoding the priority1 and priority2 values used
in BMCA, let the user tweak the values via Kconfig.

Fixes #28151

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-09-22 16:45:45 -05:00
Eduardo Montoya a136f2f695 net: openthread: fix initialization with link raw enabled
Fix the OpenThread initialization to prevent the IPv6 interface to
be enabled when `CONFIG_OPENTHREAD_RAW` is set.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-09-16 12:05:07 +02:00
Marek Porwisz 05972fff5a lib: openthread: allow passing multiple libraries as mbedtls
Some implementation consist of multiple libraries to be linked instead
of one. Added possibility to pass multiple libraries. Additionally
renamed the config name as it was stateing something different than it
does.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-09-04 11:10:34 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Jukka Rissanen 2ba4d5c2f0 net: socket: packet: Add support to SOCK_DGRAM packet sockets
Allow user to create SOCK_DGRAM type AF_PACKET socket. This
allows user to send raw IP packets without specifying
L2 (like Ethernet) headers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-27 10:56:06 +03:00
Jukka Rissanen 3d8bae814e net: gptp: Fix field ordering in gptp_priority_vector struct
The steps_removed field must be placed right after root_system_id
so that priority vector comparision can be done in one memcmp()
call. This fixes the best master clock selection algorithm (BMCA).

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-27 10:53:57 +03:00
Joakim Andersson 5880f3d74f Bluetooth: UUID: Use BT_UUID_16_ENCODE to set UUIDs in adv data
Use BT_UUID_16_ENCODE to set UUIDs in advertising data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-25 16:09:22 +03:00
Flavio Ceolin 0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Marcin Niestroj 4c8d1496ea net: l2: ppp: don't move back to NETWORK state when link goes down
PPP Phase Diagram [1] allows only one way phase change. In current
implementation there is an additional RUNNING phase, which is entered
just after NETWORK phase.

Prevent going back from RUNNING to NETWORK phase when Term-Req was
received, as this is meaningless for overall PPP operation and violates
PPP Phase Diagram property of having one way direction change.

This change also improves Adminitrative Close handling (calling
lcp_close()). This request results in moving into TERMINATE phase. Then
LCP is put down (by calling lcp_down()) and then ppp_link_down() is
called, which so far (before this patch) resulted in moving back to
NETWORK and then to DEAD. Right now (after this patch) we move directly
from TERMINATE to DEAD phase, which is exactly how [1] specifies it.

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

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-21 11:53:59 +03:00
Marcin Niestroj 47a39b567e net: l2: ppp: lcp: do not force STOPPED state after Adminitrative Close
State Transition Table [1] specifies that Administrative Close should
result in CLOSING state. This is not respected in case of LCP, as
STOPPED state was forced in lcp_close().

Don't force going into STOPPED state in lcp_close() and rely on
ppp_fsm_close() to move to CLOSING state instead.

This patch fixes overall Adminitrative Close procedure and allows to
move back into fully operating PPP connection once again after
Adminitrative Open.

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

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-21 11:53:38 +03:00
Jukka Rissanen 8e9e79b21d net: gptp: Separate common strings from warning messages
Save some memory and separate common string snippets from larger
strings. In this case "does not match" sub-string is printed by
several warning prints so separate the sub-string from the bigger
string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-08-19 12:47:09 -04:00
Marcin Niestroj a542de46ac net: l2: ppp: add initial support for PAP authentication
This patch implements optional authentication phase, which is done
between link establishment and network phases. It is part of LCP option
negotiation to decide whether authentication is needed and which
protocol will be used. For now we add only PAP support and try to
negotiate it when some other protocol (e.g. CHAP or EAP) is proposed
earlier. For simplicity reason we only add one way authentication
support, which means that we try to authenticate to the other peer, but
do not require authentication from it.

This is an important step to make PPP work with cellular network modems,
because most of them require to provide username and password within PPP
authentication phase. Those credentials are used by modem to login to
cellular network. In most cases however it is enough to provide dummy
values, because they are not verified. For this reason and simplicity of
this patch we hardcode PAP Peer-ID and Password now.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-18 20:03:05 +03:00
Marcin Niestroj adb7725a35 net: l2: ppp: remove unused auth.c module
This module had only some header includes, without actual code. Remove
it, as it is better to create one module per authentication protocol
anyway.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-18 20:03:05 +03:00
Marcin Niestroj 12553b3c83 net: l2: ppp: add enums and strings for authentication protocols
Add enums of PAP, CHAP and EAP authentication protocols. Also add their
string representations, so they will nicely show up in logs during
debugging.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-18 20:03:05 +03:00
Marcin Niestroj 58a142a0ba net: l2: ppp: support returning Conf-Nak on unsupported option values
Interpret -EINVAL return value from options' parse() callback as "option
value is not supported". After receiving such value nack() callback will
be executed in order to put supported value in the response.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-18 20:03:05 +03:00
Eduardo Montoya 526fca251f net: openthread: Align Kconfig with cmake symbols
Reorder and add missing symbols.
Organize some options in submenus.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-08-18 15:57:14 +03:00
Marcin Niestroj 22f43a5e50 net: l2: ppp: drop unused PPP_TIMEOUT macro
This macro has no use in code and was most probably replaced by
FSM_TIMEOUT (which resolves to CONFIG_NET_L2_PPP_TIMEOUT) with the same
default value.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-13 07:52:19 -04:00
Marcin Niestroj 221f1143ba net: l2: ppp: drop unused MAX_IP{,V6}CP_OPTIONS macros
Those macros are not used anymore after commit 35a2519091 ("net: l2:
ppp: add generic function for handling Conf-Req"), because we no longer
need preallocated table on stack for parsing option information.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-13 07:52:19 -04:00
Marcin Niestroj bfb1b45fd3 net: l2: ppp: drop unused NET_L2_PPP_MAX_OPTIONS option
This option is not used after commit 50b2cafc42 ("net: l2: ppp: use
net_pkt API for replying to Configure-Req") has been applied. We don't
need to preallocate table on stack for parsing option information, so
information about maximum number of supported options is useless.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-08-13 07:52:19 -04:00
Tomasz Bursztyka 98d9b01322 device: Apply driver_api/data attributes rename everywhere
Via coccinelle:

@r_device_driver_api_and_data_1@
struct device *D;
@@
(
D->
-	driver_api
+	api
|
D->
-	driver_data
+	data
)

@r_device_driver_api_and_data_2@
expression E;
@@
(
net_if_get_device(E)->
-	driver_api
+	api
|
net_if_get_device(E)->
-	driver_data
+	data
)

And grep/sed rules for macros:

git grep -rlz 'dev)->driver_data' |
	xargs -0 sed -i 's/dev)->driver_data/dev)->data/g'

git grep -rlz 'dev->driver_data' |
	xargs -0 sed -i 's/dev->driver_data/dev->data/g'

git grep -rlz 'device->driver_data' |
	xargs -0 sed -i 's/device->driver_data/device->data/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Kamil Kasperczyk e5c65ebe2e net: openthread: Added config for OpenThread version selection.
Config options used for selecting OpenThread stack version
were added.

Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
2020-08-05 15:20:52 +02:00
Andrew Boie c0d3ed0d1c net: use kernel stacks
These threads don't run in user mode, save some memory if
userspace is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-01 08:13:15 -04:00
Marcin Niestroj 5a754af945 net: l2: ppp: drop old option parsing routine
Drop unused ppp_parse_options_array() function and 'struct
ppp_option_pkt' data type. Both were used in initial PPP implementation,
but are not longer needed after recent PPP refactoring.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj 35a2519091 net: l2: ppp: add generic function for handling Conf-Req
Introduce new ppp_config_info_req() function that can be used in order
to handle options received within Conf-Req packet. As an input it takes
array of supported options. If received Conf-Req packet contains unknown
options, then a Conf-Rej packet is automatically generated with all of
those options. If all of received options are supported, then function
continues to parse each provided option individually by calling option
specific callbacks.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj b20c927b93 net: l2: ppp: ipv6cp: handle Configure-Rej packets
Use a generic handler for received options in Conf-Rej packet. This will
mark all those options as rejected, to they will no longer be included
in subsequence Conf-Req packets.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj c7a310123b net: l2: ppp: ipcp: handle Configure-Rej packets
Use a generic handler for received options in Conf-Rej packet. This will
mark all those options as rejected, to they will no longer be included
in subsequence Conf-Req packets.

This allows to communicate with PPP peers, which do not support DNS1 and
DNS2 options.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj 5326d11e8c net: l2: ppp: add generalized "my options" negotiation
So far there was no generalized way how to handle negotiation of "my
options" (those sent with Conf-Req packet to peer). Peer response for
proposed options and their values were not tracked in any way, so
rejected (by peer) options were sent over and over again in subsequent
Conf-Req packets. In case of IPCP it means that all sent options such as
IP_ADDRESS, DNS1, DNS2 were mandatory for being supported by peer in
order to successfully finish negotiation. For example if 'pppd' was the
configured peer (e.g. when using with QEMU and net-tools scripts),
without ms-dns being configured (which is the default), then "my
options" negotiation failed.

Introduce generalized mechanism for negotiating "my options", so it is
easier to maintain current set of supported options and easily add new
options to the implementation in future. FSM instance inititialization
function can provide information about supported "my options".
Information is is passed as a table of 'struct ppp_my_option_info'
containing:

 * option code (type),
 * callback for adding option to Conf-Req packet,
 * callback for received Conf-Ack with that option,
 * callback for received Conf-Nak with that option.

Store also runtime information about each negotiated option. First of
all remember which options have been rejected, so they are not sent to
peer once again in the next Conf-Req packet. This will solve issue with
IPCP negotiation when peer doesn't support DNS1 or DNS2 options. Keep
also track about which options have been acked, so such information can
be verified before bringing FSM instance up.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj f0f56ff773 net: l2: ppp: generalize option parsing function
Rework implementation of ppp_parse_options() to be more generic and
flexible to use. Pass callback and user data for parsing each option
separately.

Keep old functionality of ppp_parse_options() accessible via
ppp_parse_options_array() function. This will make sure that old code
using this function doesn't need to be changed now. There are plans
however to remove ppp_parse_options_array() once there are no more users
of it in future.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj 08988999ca net: l2: ppp: prepare Configure-Req with net_pkt API
Use net_pkt API to assemble Configure-Req messages. Compared to net_buf
API it allows us to simplify code.

Remove append_to_buf() helper functions, as their functionality is now
totally replaced by net_pkt API. Additionally net_pkt API handles data
that wraps several net_buf packets, which was not the case with
append_to_buf().

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj 50b2cafc42 net: l2: ppp: use net_pkt API for replying to Configure-Req
Use net_pkt instead of net_buf API for replying to Configure-Req. We use
the fact that for now we reply with either Configure-Ack or
Configure-Rej only. In both cases we can allocate net_pkt ahead, because
we know its maximum length (which is equal to length of received
Configure-Req packet).

Make also an improvement in generic FSM code and reply with
Configure-Rej to all Configure-Req for which there is no config_info_req
callback set. Use that to drop LCP specific Conf-Req handling code,
because there is no option properly supported there yet.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj b091181fa5 net: l2: ppp: rework ppp_parse_options() to return error code
So far ppp_parse_options() has returned enum net_verdict. This type was
never used directly by network stack. Instead, caller was always
checking for NET_OK and returning error code in case of failure.

Change implementation of ppp_parse_options(), so it returns error code
in case of error and 0 when succeeded. This better fits its generic
purpose.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj edd39ba4ba net: l2: ppp: drop unused BUF_ALLOC_TIMEOUT macro
There is no allocation in ppp_l2.c file, which mean that
BUF_ALLOC_TIMEOUT macros is not used anywhere. Drop it.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj f161af9996 net: l2: ppp: drop unused negotiation flags
Those flags were never used and any plans for them are not known. So
drop them.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 16:38:37 +02:00
Marcin Niestroj 80e54e04ed net: l2: ppp: fsm: change state before sending Conf-Req
There was a race condition when ppp_fsm_open() was called in CLOSED
state. Conf-Req was sent first, then state was changed to
REQUEST_SENT. In the meantime however we have already received Conf-Req
to which we responded with Term-Ack.

Change state before sending Conf-Req, so we handle Conf-Req from peer
properly instead of dropping it.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-29 08:06:28 -04:00
Robert Lubos 43a3b7ed27 net: openthread: Protect OT API calls from being preempted
OpenThread API is not thread safe, therefore it shall be protected
from being preempted by OT thread, or other thread issuing API calls.
The problem showed up after a recent OpenThread upmerge, where changes
in the Joiner class made this problem visible. W/o extra protection,
`otJoinerStart` call can be preempted by the OT thread, leading to an
unexpected behavior.

Introduce new function to allow to lock any API operations for others.
Anyone willing to call OT APIs, shall lock the mutex first to get
exclusive access to the stack.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-27 19:04:43 +02:00
Robert Lubos 9690ee7eeb net: openthread: Add missing static keyword in several functions
A few functions were missing static.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-27 19:04:43 +02:00
Robert Lubos 13bd96ab61 net: openthread: Align with Link raw API changes
`otLinkRawSetEnable` was removed and Link Raw mode is now enabled with
`otLinkRawSetReceiveDone` which requires to register a callback
function. Since it makes little sense for OT L2 to register a Link Raw
callback in current setup, leave it up to the application to register
the callback.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-27 19:04:43 +02:00
Robert Lubos a2cfc40264 net: openthread: Set link-layer address pointer before OT setup
OT makes use of it during initialization after the upmerge.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-07-27 19:04:43 +02:00
Marcin Niestroj 9dd220dc2b net: l2: ppp: remove useless is_init checks
is_init field is useless, because there is only single code path that
always sets it to true before using it.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-27 13:22:01 +02:00
Marcin Niestroj a956942a4d net: l2: ppp: ipv6cp: remove network address in ipv6cp_down
Make sure IPv6 address is removed from network interface in IPV6CP
protocol down handler. This makes sure that application can receive
high-level notification about missing network connection.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-27 10:06:14 +02:00
Marcin Niestroj 74167c74e9 net: l2: ppp: ipcp: remove network address in ipcp_down
Make sure IPv4 address is removed from network interface in IPCP
protocol down handler. This makes sure that application can receive
high-level notification about missing network connection.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-27 10:06:14 +02:00
David Leach b201cf3356 subsys/ieee802154: Add 'fall through' comment to switch
Added the 'fall through' comment to switch to quiet compiler
and coverity warnings.

Fixes #25724
Fixes #25726

Signed-off-by: David Leach <david.leach@nxp.com>
2020-07-24 21:51:14 -04:00
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
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
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
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
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
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 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 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
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
Marek Porwisz 1130f8484e net: lib: openthread: Handle OT transmission in Thread task
OpenThread API is not thread-safe.
Moved creation of otMessage to the Thread task and created api
for passing it properly.
This way it should be less possible for an issue to occure eg.
during message buffer allocation.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-06-18 19:37:06 +02:00
Jukka Rissanen f7d584a0ce net: ethernet: Check that device has PTP clock before access
Avoid null pointer access by checking that Ethernet device has
PTP clock before trying to get the actual PTP clock device.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-15 16:40:36 +03:00
Robert Lubos 7f9b85e8c3 net: openthread: Fix u16_t usage
PR #25936 introduced u16_t type usage and was merged after the type
transition in Zephyr.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-10 19:24:20 -04:00
Lukasz Maciejonczyk ff8b864f48 net: openthread: Make OT thread priority class be configurable
It add an option to configure openthread thread priority class
by the application if there is a such need.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2020-06-09 11:00:17 +03:00
Lukasz Maciejonczyk 3fa2fa9a50 net: openthread: Fix the order of adding net pkt in ot_receive_handler
Net pkt is added into the ot net list after queued net pkt into
the net_rx which bases on it. It affects in losting net pkt when for
instance ot thread is preemptive.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2020-06-09 10:57:00 +03:00
Lukasz Majewski 0e32a84bcc net: eth: Add check if passed iface pointer is NULL
The eth_stats_update_errors_rx() implicitly assumes that passed pointer
to struct net_if is not NULL.

This is not true for MCUX's eth_rx() (in eth_mcux.c), where we can
execute eth_stats_update_errors_rx() after net_recv_data() returning
-EINVAL because of passed NULL iface pointer.

This change fixes this problem with adding extra check on iface not
being NULL before it is dereferenced.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2020-06-09 10:54:29 +03:00
Eduardo Montoya fc1d0635df net: l2: openthread: Add config option to enable OpenThread ref. device
This option enables specific features used by Thread Certification
reference devices.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-06-08 21:41:40 +03:00
Marcin Niestroj 747f20720a net: wifi: shell: store shell in context before scan
Right now shell pointer is not assigned before doing a scan, so scan
results are printed using printk(). Save shell instance in context, so
results are printed using shell_fprintf(), thus better aligned in the
console output.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-06-08 21:37:33 +03:00
Markus Becker 2115b575a4 net: ieee802154: Allow to disable auto-start of 802.15.4 interfaces
Some radio drivers need configuration before start-up. Up to now only
the RF2XX drivers allowed this, but other radio drivers need this as
well. In particular for setting EUI64 addresses.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-06-08 19:55:19 +03:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Robert Lubos bc5b05f223 modules: mbedtls: Add Kconfig entry for MBEDTLS_MD and MBEDTLS_CIPHER
Due to new checks in mbedTLS config sanitizer, TLS option can no longer
be left enabled, when TLS is not used. OpenThread needs MBEDTLS_MD_C
and MBEDTLS_CIPHER_C even without TLS being used, so we need an option
to enable them manually.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-06-02 15:24:36 +02:00
Eduardo Montoya dd1a71f0c4 net: config: align Kconfig debug levels with OpenThread ones
OpenThread moved from 4 to 5 debug levels and it was not possible
to configure all of them with Kconfig.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2020-05-25 20:41:42 +02:00
Jukka Rissanen d940a813b1 net: lldp: Write LLDPDU data to pkt correctly
Make sure that net_pkt_write() sets the LLDPDU data correctly
in net_pkt.

Fixes #25184

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-11 17:11:23 +02:00
Jukka Rissanen ad9f32a4e9 net: lldp: Sent LLDP packet was missing proper net_pkt type
The LLDP packet was created but its type was not set to LLDP
and was sent as ARP message.

Fixes #25084

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-08 11:43:00 +03:00
Robert Lubos 139da50e3c net: openthread: Allow to disable automatic network attachment
Add OpenThread configuration option, which allows to configure and start
OpenThread stack operation manually. This mode should be used in NCP
devices, as well as is needed for certification purposes, where
OpenTread stack have to be configured by the test framework and not
initialize and join the network on its own.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-05-08 10:44:27 +03:00
Robert Lubos 3fa97df43c net: openthread: Update mbedTLS configuration
After the update, CMAC is also required when DTLS is not used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-05-07 23:27:49 -05:00
Tomasz Bursztyka 38970c07ab net/ieee802154: Validate length on received frames
Frame format was validated, but its length should be also validated
relevantly against the format.

Fixes #24970

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-07 13:20:46 +03:00
Alexander Wachter 464f135ce6 canbus: Convert canbus driver and subsys to new timeout API
Convert all canbus related API/samples/tests/subsys
to the new timeout API with k_timeout_t.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2020-05-06 10:19:13 +02:00
Lukasz Maciejonczyk ae68354428 net: l2: openthread: Add function for getting openthread default instance
The new function simplifies use of OpenThread API in Zephyr.

Signed-off-by: Lukasz Maciejonczyk <Lukasz.Maciejonczyk@nordicsemi.no>
2020-05-05 16:30:20 +03:00
Jukka Rissanen 54864d063d net: gptp: Convert to use k_timeout_t
One k_timer_start() was missing k_timeout_t conversion.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-01 10:50:03 +03:00
Lukasz Maciejonczyk 3ba7a3c82a net: l2: openthread: Add config option to enable OpenThread CoAP api
There was no way to use Openthread CoAP api in zephyr application so
far. These changes enable the feature. Now you can fully use CoAP
communication in an application working in Thread network.

Signed-off-by: Lukasz Maciejonczyk <Lukasz.Maciejonczyk@nordicsemi.no>
2020-04-17 09:21:41 +03:00
Marek Porwisz ccd74755d5 net: openthread: Pass received frame to the proper thread.
Received frames shall be handled in the OpenThread thread, not in
the receiver thread.
Passed received frame to the function that will handle it in a proper
thread instead of calling otPlatRadioReceiveDone directly.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-04-09 16:19:20 +03:00
Jukka Rissanen 00a8406d7f net: ieee802154: Fix the scan duration data type
Converting to k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen fb33da6f81 net: arp: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen ab5aba4f8f net: ppp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 40f269f033 net: lldp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen f1d886ad29 net: gptp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Marcin Niestroj 29cb9271ed net: wifi: fix log message printing ssid and psk
The following logs show up when trying to connect:

  uart:~$ wifi connect xxxxxx xxxxxxxxxx
  Connection requested
  <dbg> net_wifi_mgmt.wifi_connect: (0x20000500): xxxxxx 6 255 1 \
                xxxxxxxxxx 10
  <err> log: argument 6 in source net_wifi_mgmt log message \
                "%s: (%p): %s %u %u %u %s %u" missinglog_strdup().
  <err> log: argument 2 in source net_wifi_mgmt log message \
                "%s: (%p): %s %u %u %u %s %u" missinglog_strdup().
  Connected
  uart:~$

Fix that by using LOG_HEXDUMP_DBG() to print SSID and PSK.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-04-07 15:00:55 +03:00
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
Jukka Rissanen ac4db1b329 net: gptp: Fix bit shifting in time interval
It is invalid to try to bit shift the same amount of bits as
what is the number of bits in the left expression’s type.

Coverity-CID: 187079
Fixes #8988

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-25 13:38:38 -04:00
Tomasz Bursztyka d6d52ce9e5 net/pkt: Remove _new suffix to net_pkt_write 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
Thomas Stenersen 7516476386 kconfig: Use depend on instead of select to avoid kconfig loop
Remove use of select to "force" enabling other configs in subsys/fs
and subsys/net/l2. The forcing will cause infinite kconfig recursion.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2019-03-12 19:42:40 +01:00
Andrei Emeltchenko a9090c9538 net: lldp: Move optional End TLV to send function
In a case we have optional TLVs we need to send End TLV in the very
end.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-03-09 16:02:11 -05:00
Andrei Emeltchenko 480f93fbb5 net: lldp: Add optional TLV API
Add possibility to set optional TLVs to LLDP DU.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-03-09 16:02:11 -05:00
Andrei Emeltchenko fba09bffb2 net: lldp: Move LLDP structure definition to lldp
Move duplicated structure definitions to lldp subsystem from
drivers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-03-09 16:02:11 -05: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
Ulf Magnusson 48753144bd kconfig: ethernet: Remove duplicated dependencies
Some of these are from 'source'ing a file within a menu that has a
'depends on NET_L2_ETHERNET' (in drivers/ethernet/Kconfig) and then
adding another 'depends on NET_L2_ETHERNET' within it.

Similarly, subsys/net/l2/ethernet/Kconfig sources files within an
'if NET_L2_ETHERNET'.

'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-08 07:23:02 -05:00
Ulf Magnusson 73efd78432 net: gptp: Remove ref. to undef. CONFIG_NET_GPTP_STACK_SIZE
No Kconfig symbol called NET_GPTP_STACK_SIZE has ever been defined in
the Zephyr repo. Drop the CONFIG_* prefix from the #define.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-05 08:23:22 -05:00
Takumi Ando 1981eef674 net/l2: openthread: Add support for automatic joiner start
We sometimes want to join a device to OpenThread mesh automatically.
This commit adds supports to do by Kconfig.

The default of CONFIG_OPENTHREAD_JOINER_PSKD is based on this page:
https://codelabs.developers.google.com/codelabs/openthread-hardware/

Signed-off-by: Takumi Ando <takumi.ando@atmark-techno.com>
2019-03-04 19:51:10 -05:00
Maksim Masalski b324f35e61 macros: deleted macros SECONDS(), MSEC(), USEC()
Changed everywhere these macros to the K_MSEC(), K_SECONDS()

Signed-off-by: Maksim Masalski <maxxliferobot@gmail.com>
2019-03-04 19:04:21 -05:00
Jukka Rissanen 81e83ba462 net: arp: Update the ARP cache if receiving ARP req
If we receive the ARP request, then check if the ARP cache
contains an entry for this IP address already. If it does,
then update the MAC address in the cache.

Fixes #10188

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-02 03:56:48 +01:00
Jukka Rissanen 52dc50dc6b net: lldp: Allow generation of documentation
No need to hide the symbols in the header file if CONFIG_NET_LLDP
is not enabled. This also allows the documentation to be generated
properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-01 09:45:06 +01:00
Ulf Magnusson 9aab5cef96 kconfig: Remove redundant 'default n' properties
Some more were added since the cleanup pass in June 2018. See e.g.
commit 2d50da70a1 ("drivers: ipm: Kconfig: Remove redundant 'default n'
properties") for a motivation. It also avoids people wondering whether
or not they need to put in 'default n'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:25:22 +01:00
Tomasz Bursztyka ca7b3b3703 net/ieee802154: Switch fragmentation support to new net_pkt API
- differentiating actual "fragment" to buffer element from a net_pkt
- instead of copying data (and thus allocating buffer) let's just take
the fragment buffer and put it into result packet.
- fixing compilation issue in relevant test

It's more efficient that way, as we use already allocated fragment
buffer instead of reallocating/deallocating after each fragment
reception.

A possible optimization would be to calculate the actual size + header
difference if only the actual size is close to the target size.
It would avoid to get a dry run of the header decompression for each
fragment received. The difficulty being in finding the sweet spot when
it is relevant to calculate the header difference.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-23 07:44:59 -05:00
Tomasz Bursztyka 90ae99274f net/ieee802154: Switch L2 to new net_pkt allocator
Now buffer is allocated at the same time.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-23 07:44:59 -05:00
Tomasz Bursztyka d086f50243 net/l2: Switch OpenThread L2 to new net_pkt allocator
Maybe there is an easier way to fill in the buffer in one call from an
otMessage.

Switch "frag" keyword to "buf", as "frag" is now reserved for actual
packet fragmentation and not buffer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-21 09:30:20 -05:00
Tomasz Bursztyka 9d68f94d0e net/l2: Switch bluetooth L2 to new net_pkt allocator
Not much changes here as the buffer comes from BT stack already.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-21 09:30:20 -05:00
Krzysztof Chruscinski 3605e48c44 shell: Modify subcommands to use SHELL_STATIC_SUBCMD_SET_CREATE
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.

Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Jukka Rissanen ef7081ee44 net: Fix the function API documentation generation
Make sure that network related functions are always documented.
This means keeping the prototype and possible stub together.

Fixes #12615

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-15 16:39:06 -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
Tomasz Gorochowik 0604c30a1b net: gptp: Fix pkt allocation with debugs enabled
Commit 44964c735e ("net/gptp: Switch GPTP to new net_pkt API") changed
the callback used for allocation (from net_pkt_get_reserve_tx to
net_pkt_alloc_with_buffer), but for compilation with
CONFIG_NET_DEBUG_NET_PKT_ALLOC enabled, both callbacks are used
(the first pointer was just overwritten, causing MPU FAULT).

This commit removes the extra callback and fixes the fault.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-02-14 05:15:25 -06:00
Tomasz Bursztyka a6426620da net/private: Rename net_hexdump_frags to net_pkt_hexdump
And remove the parameter "full" as there is no "ll reserve" distinction
anymore. The parameter was unused since the ll reserve concept removal.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Jukka Rissanen 989eeaf96b net: canbus: Set link address type correctly
The link address type should be CANBUS of course.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Tomasz Bursztyka 499ffd6573 net/ethernet: Remove inserted L2 header buffer
The packet can be referenced somewhere else and letting the newly added
L2 header will generate corrupt packet. If the same packet is being
resent, ethernet will add again its L2 header. Thus the need to remove
such L2 header every time a packet has been sent, successfully or not.

Fixes #12560

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-08 14:24:03 +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
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
Ravi kumar Veeramally 5012223b31 net: l2: ethernet: Handover net packets to driver
If packet family is AF_PACKET and CONFIG_NET_SOCKETS_PACKET
is enabled, just handover the packet to driver for sending.
L2 layer will not touch AF_PACKETs at the moment.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Daniel Glöckner 1e676d654f net: gptp: fix src MAC address
The return value of net_if_get_link_addr points to a struct net_linkaddr
instead of to the raw MAC address. Without this fix the source address
will always end in 06:03 and will most likely be the same for different
boards running the same software.

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-02-07 12:58:57 +02:00
Tomasz Bursztyka 89dae2aabd net/lldp: Switch LLDP to new net_pkt API
Minor changes:
- allocator needed to be changed
- and writing the lldp_pdu as well

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 9a41078c51 net/lldp: Fix where Ethernet PTYPE is set for LLDP message
Since the rework of L2/L3 split, only L2 has access to its header. Thus
up to Ethernet one to set LLDP PTYPE.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 44964c735e net/gptp: Switch GPTP to new net_pkt API
Allocation and a minor writing logic needed to be changed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 970e234965 net/arp: Switch ARP to new net_pkt API
Only the allocators needed to be changed there.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka c14a5c896f drivers/ethernet: Use new net_pkt API for sending and receiving
Use the new API where relevant. Only sam_gmac is left aside for now.

This simplifies a lot the code as the caller should only care about
allocating net_pkt and its buffer once, and thus will not need to mess
with "frags" etc...

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
Daniel Glöckner 5ef825fdf6 net: pkt: fix race condition in packet reference counting
It has been observed that some network drivers, f.ex. the SAM E70 GMAC,
call net_pkt_unref from inside the interrupt that signals the successful
transmission of a packet. This conflicts with the net_pkt_unref call
made by ethernet_send after the packet has been given to the driver.

We fix this by using an atomic_t to hold the reference count as there
might be other, difficult to find cases of net_pkt_(un)ref being used
across threads and interrupts.

The name of the element has been changed from "ref" to "atomic_ref" to
cause a compile error when code still has not been converted to use the
atomic_* functions.

Fixes #12708

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-01-29 09:22:14 +02:00
Robert Lubos 43a431e149 net: openthread: Set mesh_local flag in mesh-local OT addresses
Mark automatically and statically configured mesh-local addresses
with mesh_local flag, so that they are not used as a source for
off-mesh destinations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-28 21:24:26 -05:00
Robert Lubos c349bafab3 net: openthread: Do not register RLOC and ALOC addresses
In OpenThread RLOC address and ALOC address are used for internal mesh
routing and should not be used by applications as they can change
dynamically during runtime. Therefore prevent registering them on Zephyr
interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-25 10:09:27 +02:00
Loic Poulain 192733c096 net: wifi: Add Access Point mode interface
Add access point mode disable/enable to wifi mgmt/offload.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-19 07:20:36 -05:00
Loic Poulain d9365dff92 net: wifi: shell: Add access point commands
Expose access point disable/enable commands.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-19 07:20:36 -05:00
Robert Lubos 73ec83a9a5 net: openthread: Increase default stack size when commissioner is on
OpenThread commissioner feature has extra stack requirements, hence
increase it in this configuration.

Fixes #12455

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 15:24:16 +02:00
Robert Lubos 635191ac8c net: ieee802154: Fix ack check
15.4 MHR is no longer set in net_buf pointed by net_pkt, but in a
separate net_buf, hence we need to check that net_buf now to
determine if we need to wait for ACK or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-17 11:16:26 +02:00
Robert Lubos 8f8c6017f4 net: 6lo: Fix ieee802154 fragmentation
Two issues identified with 6lo fragmentation for ieee802154 that broke
the communication:

1) ieee802154_fragment_is_needed function did not take 15.4 FCS size
into account, hence taking wrong decision in some cases.
2) set_up_frag_hdr was writing with wrong offset, which resulted in 6lo
bytes being overwritten by 15.4 header.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-17 11:16:26 +02:00
Oleg Zhurakivskyy 20ee76ab22 net: ethernet: Clean an obscure ref/unref logic in ethernet_send()
Do not extra ref and then obscurely unref the packet inside
the statistics update function.

Actually, this extra ref/unref isn't needed here at all.

The packet is unreferenced only on a successful send, statistics
updating can be done before the unref in a clean and understandable way.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-01-08 13:39:40 +02:00
Tomasz Bursztyka dc9e408e22 net/ieee802154: Compute ll hdr size before 6lo compression
Or then the IP header access will be bogus afterwards.

Fixes #12154

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-01-08 13:36:14 +02:00
Jukka Rissanen 235ebd0ca0 net: gptp: Track memory allocations better
Try to catch the original caller of setup_gptp_frame() function
in order to see who is allocating buffers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-08 13:29:18 +02: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
Tomasz Bursztyka 7f8d92827f net/ethernet: Remove usage of net_pkt_ll() function
This function is planned to be removed, thus avoiding its usage.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 91a9994aaf net/ieee802154: Remove usage of net_pkt_ll() function
This function is planned to be removed, thus avoiding its usage.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +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
Tomasz Bursztyka c8d26f845a net/l2: Finally get rid of reserve concept from L2
Now that net core does not use ll reserve, it can be nuked from L2.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 6ea225e34a net/ieee802154: Finally removing usage of ll_reserve in L2
Moving towards serialized fragmentation, adapting mac command creation
to avoid the need of ll_reserve etc...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka f923d2cb1e net/ieee802154: Serialize packet fragmentation
This will permit to avoid the need for ll_reserve.
It also removes net_buf allocation and deletion, as it works per-frame.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 57a0c55dac net/6lo: Remove fragmentation function parameter on compression
Fragmentation has nothing to do with 6lo. Up to the bearer to do so.

This change is required for futur serialization of 15.4 fragmentation.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka bff65b6330 net/ethernet: Let's remove the use for ll reserve
There is no need to reserve any space for each frag, as the l2 will
allocate a frag for the ethernet header, arp will do the same.

This is one step further to removing the concept of ll reserve.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Jukka Rissanen bafa802657 net: gptp: Calculate the link delay same way as Avnu/gptp
Make sure that the link delay (propagation time) is calculated
same way as how Avnu/gptp is doing it with checks for rate ratio.
This is done like this in order to behave same way as their gptp.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:13:15 +02:00
Jukka Rissanen 11bb406332 net: gptp: Add debug print if a gptp packet cannot be created
This is useful info as otherwise we get no indication to user
if the packet is not created and not sent.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:13:15 +02:00
Jukka Rissanen 5a56900b07 net: gptp: Make sure that neighbor_rate_ratio cannot be 0
Neighbor rate ratio cannot be 0 as that would mean 0 packet
delivery time which is not plausible.
Add also some debugging to print current neighbor propagation
delay value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:13:15 +02:00
Jukka Rissanen e41fd1ddf9 net: gptp: Update pdelay req lost counter when needed
The pdelay_allowed_lost_resp_exceed_count was updated even if we
had received pdelay response.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-11 16:38:12 +02:00
Jukka Rissanen e21d7cc72d net: gptp: Refactor the gPTP header addition
Increase the net_buf length in proper places. So when gPTP
header is added, increase the buf->len properly, and then
when gPTP packet type is added, increase it again properly.
This way the net_buf length is updated in more logical way.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-11 13:50:54 +02:00
Jukka Rissanen 2b268f8d3d net: gptp: state2str() func is only available if debugging
The state2str() function should only be used if debugging
is enabled thus add some pre-processor checks there.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Jukka Rissanen 3af324033e net: gptp: Add more debugging when changing state
Print function and line number when changing state and when
debugging is enabled. Otherwise it is a bit difficult to follow
the program logic and locate the state change operation.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Jukka Rissanen 83f38b5f2d net: gptp: Remove log_strdup() when printing packet info
As the msg parameter for PRINT_INFO() is always a const string
that is not coming from stack, there is no need to use
log_strdup() here. This helps to avoid the
"<log_strdup alloc failed>" messages.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Jukka Rissanen ff0483c5af net: gptp: Get the gPTP header properly
If the link layer header is in the separate net_buf,
then skip that one.

Fixes #11827

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Tomasz Bursztyka 952e494bdd net/ethernet: Let L2 updating common rx/tx statistics
Common statistics should be updated in one centralized place and
ethernet_send is the right place for tx stats, as well as ethernet_recv
for rx stats.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-07 14:30:06 +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 b928b71756 shell: rename shell_help_print function
Function printing help has been renamed to shell_help.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01: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
Vijay Kumar B 5ff42e038d net: ethernet: Add helper functions to update error stats.
Add missed out helper functions to update the errors.tx and error.rx
in the stats structure.

Signed-off-by: Fadhel Habeeb <fadhel@zilogic.com>
Signed-off-by: Nirav Parmar <niravparmar@zilogic.com>
Signed-off-by: Vijay Kumar B <vijaykumar@zilogic.com>
2018-12-04 09:36:51 -06:00
Andrei Laperie 35a95a9b2f net: gptp: Replace calls to power function with pre-computed values
gPTP subsystem was calling pow(x,y) function with X and Y being
constants; these are replaced with the pre-computed values.

Signed-off-by: Andrei Laperie <andrei.laperie@intel.com>
2018-12-04 15:05:36 +02:00
Tomasz Bursztyka 5fb9a7bc4a net/gptp: Let Ethernet setting up the header
Instead of redoing what Ethernet L2 already does, let just create the
gptp message without any Ethenet header. Which one will be done as
sending phase by Ethernet L2 relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 2b3046df70 net/bluetooth: Switch to L2 sending path
This is a much more trivial move than in Ethernet or ieee802154 L2s.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka ebb40ba338 net/ieee802154: Switch to L2 sending path
As for Ethernet, up to ieee802154 L2's send to actually sent the packet.
It's currently unoptimized as 6lo compression, 15.4 fragmentation and so
on will reallocate net_buf etc... but it's the first step towards
removing ll reserve space and more.

Applying changes to Openthread L2 as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 7f2cb02720 net/dummy: Switch to L2 sending path
And adapt loopback and slip drivers relevantly

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 9464ec3343 net/iface: Switch fully to a one-pass sending logic in net_if
Now instead of such path:

net_if_send_data -> L2's send -> net_if tx_queue -> net_if_tx -> driver
net_if's send

It will be:

net_if_send_data -> net_if tx_queue -> net_if_tx -> L2's send -> driver
net_if's send

Only Ethernet is adapted, but 15.4 and bt will follow up.
All Ethernet drivers are made compatible with that new scheme also.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 114521c4bf net/arp: ARP packet can be queued right away
Now that sending is done at last time, in one pass, no need to go
through net_if_send_data here.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 500eca745d net/ethernet: Move sending to a one-pass logic
Currently, first part is done in L2's send, then the next one in
ethernet device driver net_if send function. That last one was already
moved to a L2 based implementation. Let's just move forward and place
the whole logic of the L2's send in that second function.

This is the first step, ethernet centric only, to move towards a
one-pass sending logic in net stack. In future, net_if's send will
disappear.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka dcc6eddfef net/ethernet: Centralize where and when header is filled in
Current code generating Ethernet header is scattered all over the place,
sometimes in functions that are supposed to check something (and not
filling the header). Not to say about innefficiency.

Src ll address does not need to be set in L2 as net_if.c handles that
already.

Broadcast dst ll address is the same in ipv4 or ipv6, thus factorizing.
In each case, multicast is filled in only at the relevant place.

This is the first step towards changing L2 sending logic, when L2 send
API function will be the only point of sending. The redirection from
driver to L2 again (which finally uses the right device API function to
send) it a temporary hack.

This simplifies the code but will also enable using statically
allocated net_buf and ethernet header payload buffer afterwards.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 94e89a11b7 net/ethernet: Make ethernet allocating its own frag for the header
This is currently unoptimized, as all frags are allocated with relevant
ll reserve for such header space. However, this is the first step
towards getting rid of that ll reserve concept everywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Himanshu Jha dbcc5392fe net: openthread: 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
Ravi kumar Veeramally 3746652f85 net: arp: Drop ARP requests from localhost address
If ARP Request with sender IP address set to localhost then drop
the request.

Fixes #11489

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally 6227b12fb4 net: arp: Fix ptype for non arp messages
If network stack found ARP entry for peer address, then it
tries to send pending IP packet. But it always keeps ptype
as ARP only. In this particular scenario it has to be IP
packet.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally 0c547f9da9 net: arp: Discard ARP request on special scenario
Discard ARP request if Ethernet address is broadcast and
Source IP address is Multicast address.

REFERENCES:
RFC 826: page 4
RFC 1122: section 3.3.6 {Silently discard link-layer-only b'cast dg's}
RFC 1812: section 3.3.2, page 34

ARP related issues fixed.

Fixes #11329

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Andrei Emeltchenko 1cd95969e3 ieee802154: Remove dead code
Remove unused ieee802154_shell_init()

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-15 08:42:52 -05:00
Ravi kumar Veeramally 483378027a net: arp: Check invalid fields in ARP header
If ARP header contains invalid fields then drop the packet.

Fixes #11257
Fixes #11254
Fixes #11253
Fixes #11248

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-12 15:42:54 +02:00
Krzysztof Chruscinski fa95089b3d net: l2: Fix NET_L2_BT dependency in KConfig
Added NET_IPV6 dependency to NET_L2_BT.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Ravi kumar Veeramally 4b0aa92bba net: arp: Verify incoming packet HW and protocol type
Verify incoming ARP packet hardware and protocol type. Drop
unknown type of packets.

Fixes #11215
Fixes #11217

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-09 15:21:28 +02:00
Jukka Rissanen 42c180ed5b net: eth: Remove old IPv6 interface identifier address
If we change the ethernet MAC address, then we must also remove
the old IPv6 interface identifier (iid) address from the
interface. Otherwise there might not be enough space in the IPv6
address array for the new iid address and beside the old iid
address is not useful any more after the MAC address is changed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-08 15:23:05 +02:00
Tomasz Bursztyka 3200914ed9 net/ethernet: Remove as many ifdef for CONFIG_NET_VLAN as possible
Most of vlan functions have dummy aliases when it's not enabled, so
let's use this.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-06 12:42:06 +02: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
Kumar Gala cabdf5e9dd subsys: Remove board.h include
The subsys code doesn't need anything from board.h so lets remove the
include.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:15:18 +01:00
Jukka Rissanen 7d83543379 net: Properly handle pkt IPv4 broadcast destination address
If we receive an IPv4 that has broadcast destination address, then
properly handle it.
This means that for
  * ICMPv4, if CONFIG_NET_ICMPV4_ACCEPT_BROADCAST is set (this is the
    default value) and we receive echo-request then accept the packet.
    Drop other ICMPv4 packets.
  * TCP, drop the packet
  * UDP, accept the packet if the destination address is the broadcast
    address 255.255.255.255 or the subnet broadcast address.
    Drop the packet if the packets broadcast address is not in our
    configured subnet.

In sending side, make sure that we do not route broadcast address
IPv4 packets back to us. Also set Ethernet MAC destination address
properly if destination IPv4 address is broadcast one.

Fixes #10780

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Gil Pitney 621ec506e2 net: wifi: Update connect cmd to deal with new shell quoted args
Previously, the wifi shell needed to remove the quotes from the
SSID parameter, passed in by the underlying shell.

The new shell is now able to parse quoted strings as arguments,
so this adjustment can be removed.

Otherwise, it results in a failure to connect to an AP, as the first
character of the SSID name is stripped off.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-25 20:46:38 +03:00
Jukka Rissanen fb73aee36f net: openthread: Remove remaining SYS_LOG usage
Remove the last SYS_LOG reference from OpenThread code as SYS_LOG is
being deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Jukka Rissanen 8f76169190 net: wifi: Make sure shell is valid before trying to print to it
It is possible that connect callback is called when shell is not
yet set. Make sure to check this and fallback to use printk() if
shell_printf() cannot be used.

Fixes #10617

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:16:48 -04:00
Jukka Rissanen 1d72af0393 net: wifi: Fix connect command parameter checks in shell
The connect command parameters were not checked properly if
user decided to supply only mandatory parameters.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:16:48 -04:00
Jukka Rissanen dab9030ab9 net: wifi: Check offloading pointers before accessing them
If the device does not support wifi offloading, then return -ENOTSUP
so that wifi support can be enabled for testing purposes even if
the actual device does not have wifi support. This is happens for
example in qemu which does not support wifi offloading.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:16: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
Jukka Rissanen 10c77dfbba net: gptp: Calculate GM rate ratio properly
Typo when calculating new value for local_time_n.low, the calculation
was just a constant expression and the value was not modified.

Coverity-CID: 188759
Fixes #10568

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-18 20:35:02 +03: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
Jukka Rissanen d8defbd08a net: bt: Convert network Bluetooth shell 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
Jukka Rissanen 1f4bae79e2 net: ieee802154: Convert IEEE 802.15.4 shell 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
Jukka Rissanen 681ff12379 net: wifi: Convert wifi shell 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
Jukka Rissanen fa8ff4f379 net: arp: Add support for receiving gratuitous ARP request
If we receive a valid gratuitous ARP request, then update ARP
cache accordingly. This feature is optional and by default
it is enabled, but can be turned off if needed.

This is similar to a feature available in Linux, and is enabled
by default in many distros.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-10 16:12:35 +03:00
Dong Xiang 026f06efeb net: l2: update wifi mgmt to adapt non-offload wifi chip.
The wifi mgmt does only support TCP/IP offload wifi chip,
while non-offload wifi chip can not scan/connect to AP.

Signed-off-by: Dong Xiang <dong.xiang@unisoc.com>
2018-10-10 11:38:04 +03:00
Jukka Rissanen 7138e34d31 net: wifi: Removing SYS_LOG_DBG as that is no longer used
The wifi management interface was still using one SYS_LOG_DBG
macro call, replacing that with NET_DBG.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 10:08:32 -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 15e7e3ea4b net: ip: Split debug prints into smaller pieces
Currently logging subsystem supports quite small number of function
parameters. So split some long functions into smaller pieces.
Hopefully this is just a temporary patch and we can support more
parameters to logging macros.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen a76814bfb6 net: Convert core IP stack to use log levels
Instead of one global log level option and one on/off boolean
config option / module, this commit creates one log level option
for each module. This simplifies the logging as it is now possible
to enable different level of debugging output for each network
module individually.

The commit also converts the code to use the new logger
instead of the old sys_log.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Tomasz Gorochowik 3a51c8d932 net: gptp: Fix sync interval timeout timer starting
The last parameter is 'period', we should not pass duration twice.
Doing so makes zephyr hang with current mainline when it is chosen to be
the Grand Master.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik a979841ec4 net: gptp: Fix sync receipt timeout timer starting
Completely remove the last_sync_receipt_timeout time. It is not part of
the standard (see 802.1AS-2011, 10.2.11 for the complete list of
variables for this state machine). Additionally this extra variable was
never really initialized so the calculated duration made no sense.

Just start the timer based on the regular sync receipt timeout time
interval from the port data set.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 0888da4dfe net: gptp: Add clock accuracy selection
This commits adds a possibility to select PTP clock accuracy through
KConfig.

The chosen accuracy should reflect the capabilities of the used
hardware.

See IEEE 1588-2008, chapter 7.6.2.5 for more details.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 68127a3100 net: gptp: Initial GrandMaster capability support
Implements GMCAP-1, GMCAP-2, and GMCAP-3 and their dependencies from
802.1AS-2011. See Annex A.10 for more details.

The Grand Master Capability can be turned on and off through KConfig.

Note: the correction field in FUP packets is not yet properly
calculated. There is a TODO left in the code, near which some parameters
are zeroed to make the correction field be set to 0. This mimics the
behavior of openAvnu (a Linux gPTP client). For full compliance the
field should be calculated and set properly.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 117b9ac3e9 net: gptp: Use packed enums when applicable
Optimize memory usage of enums that are used within structs.
Reorganize the affected structs to avoid holes.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 5c5a4461a4 net: gptp: Fix port number in SYN and FUP packets
Make sure the packets contain the port number they are actually coming
from.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 792dfd4a04 net: gptp: Convert SyncReceiptTime to ExtendedTimestamp
SyncReceiptTime should use an ExtendedTimestamp (with fractional
nanoseconds precision). Add a struct with the definition of the needed
type and convert that variable.

The struct representing the ExtendedTimestamp is named
net_ptp_extended_time to keep consistency with the existing net_ptp_time
which is used for regular PTP timestamps.

See 802.1AS-2011 chapters 10.2.3.4 and 6.3.3.5 for more reference.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik a84e60b8de net: gptp: Rename the ClockMasterSyncReceive state struct
There are other ClockMasterSync state-machines (to be implemented).
Current name would either cause conflicts or be too ambiguous.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Luiz Augusto von Dentz 3151d26572 Bluetooth: L2CAP: Add return to recv
This adds a int return to recv callback which can be used to notify the
stack about errors when receiving a packet. In addition to that the user
can return -EINPROGRESS to inform the stack the data will be processed
asynchronously which can be complete by calling
bt_l2cap_chan_recv_complete.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +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
Tomasz Gorochowik 24a91afa38 net: gptp: Remove unused macro
Minor cleanup.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +03:00
Tomasz Gorochowik 3c68a06743 net: gptp: Fix the default value of sync receipt timeout
The default value shall be 3.

See 802.1AS-2011, 10.6.3.1 for reference.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +03:00
Tomasz Gorochowik c3baa22778 net: gptp: Fix sync timeout calculation
Sync timeouts were calculated incorrectly - this led to a 'Multiple
Masters Issue' as denoted by PTP debugging software.

See 802.1AS-2011, chapter 10.2.4.2 for reference.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +03:00
Tomasz Gorochowik 09b6f956d4 net: gptp: kconfig: Fix log-based intervals help
Fix the formula listed in help messages which is used to calculate
actual intervals given their log2 values.

It is all calculated properly in the code, because the unit of the
actual field uses the UScaledNs type of which the unit is 2^(-16)ns, so
it is just the help messages that got it wrong.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +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
Tomasz Bursztyka b6468999e4 net/pkt: Rename link layer address accessors relevantly
*_ll_src/*_ll_dst/*_ll_swap/*_ll_if were not self explanatory, ll
meaning "link layer" it's ambiguous what the names meant.
Changing to:
*_lladdr_src/*_lladdr_dst/*_lladdr_swap/*_lladdr_if to fix this.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-11 16:06:13 +03:00
Andrei Emeltchenko e1757277ae net: lldp: Implement LLDP RX API
Add RX API to LLDP. Caller should register callback which is called
from ethernet_recv().

Fixes #9407

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-11 10:55:01 +03:00
Jukka Rissanen 42a23e2b83 net: gptp: Set stack size correctly for handler thread
The gptp stack size was not properly set, one must use
the K_THREAD_STACK_SIZEOF() macro to calculate stack size.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-06 09:56:51 -04:00
David B. Kinder 1c29bff055 doc: fix kconfig misspellings
Fix misspellings in kconfig files missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-28 13:58:46 -04:00
Paul Sokolovsky 49732b27d9 net: Move CONFIG_NET_OFFLOAD definition to net/ip/
CONFIG_NET_OFFLOAD was defined in Kconfig of net/ip/l2/, but actually
used by the code in net/ip/.

Fixes: #8646

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-22 12:56:34 +03:00
Jukka Rissanen a5f7e3345b net: lldp: Fix timeout triggering if multiple workers
The code was not working properly if there was multiple timers
that were triggered in different times.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 17:49:53 +03:00
Oleg Zhurakivskyy 99dc5aef88 net: ip: Refactor usage of net_sprint_ip*()
Refactor usage of net_sprint_ip*() where multiple
invocations are needed per single log call.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Flavio Ceolin 0866d18d03 irq: Fix irq_lock api usage
irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.

In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07: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
Oleg Zhurakivskyy ac92a01f5a net: ipv6: Refactor IPv6 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-13 13:53:14 +03:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

This commit includes some default-related cleanups as well:

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

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

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

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

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Jukka Rissanen 31f89b0303 net: eth: Add start and stop L2 functions
If the driver has created start() and stop() functions, then those
are called when ethernet L2 is enabled or disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-10 12:36:19 +03:00
Oleg Zhurakivskyy fbac80bb94 net: ipv4: Refactor IPv4 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-09 16:25:17 +03:00
Jukka Rissanen d003d0e6a6 net: ipv4: Corrupted ARP pkt was sent instead of real IPv4 pkt
The ethernet sending routine sent a corrupted ARP packet instead
of the actual IPv4 packet.

Fixes #9348

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-09 11:56:44 +03:00
Jukka Rissanen 1f855095b4 net: l2: Add promiscuous mode to L2 flags when applicable
This allows more bearers than just ethernet to have promiscuous
mode support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen 66244a0e67 net: if: No need to always join solicit node mcast group
For example for Bluetooth IPSP, it is not needed to join solicited
node multicast group address.

From https://tools.ietf.org/html/rfc7668#section-3.2.2 :

"""
There is no need for 6LN to join the solicited-node multicast address,
since 6LBR will know device addresses and hence link-local addresses
of all connected 6LNs.
"""

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen ccfcdabaf6 net: l2: Add flags to tell if L2 supports multicast
If multicast is not supported, then we do not need to join
multicast group.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jesus Sanchez-Palencia 598276262c net: l2: Add support for Link Layer Discovery Protocol (LLDP)
The LLDP protocol defines 2 separate agents, the Transmitters and
the Receivers. For the context of Zephyr, we are only interested in
the Tx agent, thus we drop any LLDP frames received by Zephyr.

LLDP frames are basically composed by an ethernet header followed by
the LLDP Protocol Data Unit (LLDPDU). The LLDPDU is composed by several
TLVs, some of them being mandatory and some optional.

Our approach here is having TLVs fully configured from Kconfig, thus
having the entire LLDPDU constructed on build time.

The commit adds NET_ETH_PTYPE_LLDP definition and related handling.

If CONFIG_NET_LLDP is enabled then ethernet_context has a pointer to
the struct net_lldpdu that belongs to that ethernet interface. Also
when CONFIG_NET_LLDP is enabled, the LLDP state machine will start to
send packets when network interface is coming up.

Currently the LLDP state machine is just a k_delayed_work() sending the
LLDPDU at a given period (defined by CONFIG_NET_LLDP_TX_INTERVAL).

Fixes #3233

Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 09:53:24 +03:00
Tomasz Gorochowik b6852e5a3a net: eth: mgmt: Add remaining 802.1Qav parameter types
This are all the parameters defined by the standard (12.21.1).

Additionally the parameters that are read-only are validated in the
ethernet_set_config callback.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:37:09 +03:00
Jukka Rissanen bab35512f8 net: ipv4_autoconf: Fix requested IPv4 address in ARP packet
Unspecified address 0.0.0.0 was used as a requested IPv4 address
because the ARP message was generated second time. So for IPv4
autoconf ARP message, generate the message only once.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-02 12:42:52 +03:00
Tomasz Gorochowik 805e2f2c79 net: eth: mgmt: Merge 802.1Qav related mgmt requests
There are too many individual requests for Qav related parameters. There
are more Qav parameters that need to be supported (and will be supported
soon - both on the GET and SET side). Handling it the way it was handled
so far would render the eth mgmt API dominated by Qav parameters. That
would make the file hard to read and understand.

Instead of that - use a single GET and SET requests for all Qav
parameters. This works by adding a separate enum with Qav request type
to the ethernet_qav_param struct.

Additionally this approach makes it much easier to document it all since
we now have just a single request and documentation comments in the
ethernet_qav_param struct.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-01 15:58:05 +03:00
Tomasz Gorochowik f568be48d0 net: eth: mgmt: Add Qav status hooks
Add calls responsible for getting and setting on/off status of Qav on
capable priority queues.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-31 17:54:24 +03:00
Jukka Rissanen 00e37cbb5b net: IPv4 link local support
Add basic IPv4 Link Local support as described in RFC 3927.

Signed-off-by: Matthias Boesl <matthias.boesl@gmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-31 16:34:28 +03:00
Robert Lubos 80e828b983 net: openthread: Don't regsiter mcast addresses in Zephyr multiple times
OpenThread L2 could've called multicast address registration multiple
times for specific address, which resulted in having multiple entries
containing the same multicast IPv6 address in Zephyr.
Checking if address was already registered prevents that.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-31 11:13:04 +03:00
Robert Lubos 96e794e6b7 net: openthread: Register OT unicast adresses in Zephyr
Register all OpenThread unicast adresses in Zephyr, not only multicast
adresses.

Fixes #9160

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-31 11:13:04 +03:00
Jukka Rissanen 21a27e8807 net: l2: Move individual L2 to dedicated directories
No need to keep technologies in main L2 directory so for consistency
create a directory for each of them and place each L2 component to
relevant L2 directory.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-30 09:02:02 -04:00
Jukka Rissanen 9ffab9e63a net: arp: Fix ARP message sending if VLAN is enabled
VLAN tags were not set properly for ARP messages.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-30 12:47:02 +03:00
Tomasz Gorochowik 3cd1425b58 net: eth: mgmt: Extend the management interface with a getter
This makes use of the get_config callback added to the Ethernet API.

For now the only parameter to get is the number of available priority
queues.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-27 20:27:59 +03:00
Tomasz Bursztyka 9c5725a69d net/ethernet: Pre-assigned declaration always comes first
And no need of extra parenthesis for casting.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-26 13:55:38 +03:00
Tomasz Bursztyka 5ebc86bdc6 net/ethernet: A device driver api uses struct device *dev
Always use struct device *dev as first parameter for a device driver
API.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-26 13:55:38 +03:00
Jukka Rissanen 9b8c83f44a net: Avoid holes in structs
Move struct members around in networking code so that we avoid
unnecessary holes inside structs. No functionality changes by
this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-25 15:20:34 +03:00
Jukka Rissanen bf9bae58d1 net: eth: Add generic promiscuous mode support
Allow ethernet L2 driver to set / unset the device driver
promiscuous mode flag.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen 408a580644 net: ethernet: mgmt: Fix Qav deltaBandwith check
As the value type is unsigned int, it cannot be <0.

Coverity-CID: 187063
Fixes #9002

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen dfa3f10b26 net: gptp: Add comment for falling through case
Make sure that it is clear that we are suppose to fall through
a case statement.

Coverity-CID: 187078
Fixes #8989

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen 27fef49d17 net: gptp: Check overflow of log msg interval
Make sure that we do not overflow when creating UScaledNS
value for interval.

Coverity-CID: 187079
Fixes #8988

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen 4670214c26 net: gptp: Fix unsigned value comparison
The nanosecond check was using <0 for unsigned value.

Coverity-CID: 187080
Fixes #8987

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jonathan Yong 40f743669b net: eth: Convert to use callbacks to query stats
The advantage to this approach allows drivers for
devices that already keep statistics data on hardware
registers to use those instead, rather than try to
replicate it the same counters again within the driver
itself.

The eth_native_posix.c driver though do not benefit
from this, is modified to use the new callback system.

Suggested-by: Jukka Rissanen <jukka.rissanen@intel.com>
Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
2018-07-19 13:46:13 +03:00
Ramon Ribeiro 0e626f5ef5 net: openthread: Add NETWORKNAME and XPANID config
This patch add the option to the user sets the network name and
the extended PAN ID

Signed-off-by: Ramon Ribeiro <rhpr@cesar.org.br>
2018-07-17 16:40:53 +03:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

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

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

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

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

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Jukka Rissanen 37125781aa net: gptp: Fix debug prints and use correct modifier
Use %zd instead of %lu when printing size_t variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-05 13:08:04 +03:00
Tomasz Gorochowik 226fa97304 net: ethernet: Add 802.1Qav settings to eth mgmt api
This commit adds a possibility to use Qav (credit-based shaping) in the
ethernet drivers.

There are two parameters exposed through the mgmt api: deltaBandwidth
and idleSlope.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:27:34 -04:00
Tomasz Gorochowik 22ba08faa3 net: gptp: Send Announce messages with correct GM info
There is no point in sending Announces with GM chosen in BMCA if it is
expired and InfoIS is changed to MINE.

Check where does the GM info come from and fill the Announce packet
accordingly.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik 1a0968bd74 net: gptp: Normalize seconds and nanoseconds differences
Do not allow seconds and nanoseconds drifts to have the opposite signs.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik fd62617ce2 net: gptp: Fix memcpy calls on arrays
Copy array content, not pointers.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik 2ca3b1e3c4 net: if: Fix TX timestamp callbacks invocation
The problem is that net_if_call_timestamp_cb only checked if the
callback was registered for the PORT which invoked the whole action.

There is a possibility, that the callback will be registered, and packet
A will be passed to eth driver. Before the driver is finished with
packet A, network layer will start handling another packet (B) - so it
will unregister the callback for packet A and register it for B. After
that the network driver will finish processing packet A and invoke the
timestamp callback. The mechanism would then only check if a callback is
registered for the port of the driver and invoke the callback for the
packet that was registered earlier (so A instead of B).

This commit fixes that by storing info not only about the port but about
the packet too.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Jukka Rissanen 65e9177a27 net: gptp: Print port state change information
If debugging is enabled, then print port state change information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik fb6223b893 net: gptp: Drop the older pdelay req after receiving a new one
Previously the newer one got dropped.

The older ones will be dropped in a way that the follow up messages for
them will not be sent.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik 214aebc6e1 net: gptp: Fix gptp port number validation
The gptp port number starts from 1, so the check was incorrect.
Use the proper define values before printing stats.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Jukka Rissanen 5356ee5d20 net: gptp: Init only the ports we have configured
The MI state machine was init with too many ports, even if
we only had one of them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-04 11:22:23 -04:00
Jukka Rissanen e9228a3964 net: gptp: Allow gPTP to run over VLAN
Allow this setup as Linux supports this too.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Jukka Rissanen 65b15c3226 net: eth: Add helper to return VLAN info for an interface
A small helper function will return information whether
a given network interface has VLAN enabled or not.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Jukka Rissanen 3fd2d53e56 net: mgmt: Add VLAN enabled / disabled event support
Send network management event if VLAN tag is enabled or disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Jukka Rissanen f3146c09ab net: gptp: Fix buf leak in PDELAY_REQ send
Do not clear pending PDELAY_REQ pointer when sending a new one.
Unref the state->tx_pdelay_req_ptr first and only then set the
new pointer value. This will prevent buffer leak if we miss the
response from the peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik 5e3ea84e64 net: gptp: Use calculated neighbor ratios only once
Make sure that the calculated ratio values are used just once.
Without this, if the ratio is even insignificantly larger than 1, the
actual clock quickly drifts to really large numbers. This causes the
sync procedure to restart too often.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik 93fe54d148 net: gptp: Fix sync timestamp callback registration
The logic was inverted which prevented the callback from ever being
registered.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik 7e545c998c net: gptp: Do not handle multiple pdelay requests at once
The problem with the previous approach was that the response timestamp
callback which calls net_pkt_unref could be skipped if the callback was
already registered for another packet. The net_pkt_ref function was
always called which led to memory leaks.

This commit simply disallows handling multiple pdelay requests at once.
If the timestamp callback is already registered, the received request
will not be handled.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik b422d38650 net: gptp: Fix sync follow up packets content
The issue was that the length field of the tlv extension in the sync
follow up packets was wrong. It is supposed to skip the length of the
header of that extension. The easiest fix was separating the header and
the actual contents into separate structs and that's what this commit
does.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Jukka Rissanen cf272e6667 net: gptp: Use the ptp clock instead of zephyr uptime
As the PTP clock should return the correct time, use that
instead of zephyr uptime for time as that has only ms accuracy.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 16:52:49 +03:00
Jukka Rissanen 70b60cca1d net: gptp: Set priority of the sent gPTP packets
Use priority 3 (critial app) for outgoing event messages (Sync,
Pdelay_Req and Pdelay_Resp). Use priority 6 (Internetwork Control)
for all other outgoing packets.
See IEEE 802.1Q chapter 8.4.4 for more details.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 16:52:49 +03:00
Dong Xiang 7ba7119f82 net: l2: Fixed wifi can not connect to open AP.
When connect to open AP, the security is always set to
WIFI_SECURITY_TYPE_PSK.

Signed-off-by: Dong Xiang <dong.xiang@unisoc.com>
2018-07-02 15:19:37 +03:00
Tomasz Bursztyka 922d63cee5 net/arp: Normalize all function names
Let's follow the same prefix for all function.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 2df23f567b net/arp: Let's reduce the size of each ARP entry
An ARP entry, if not free, will be either in pending list or in the ARP
table. What differentiate both is the type of data they hold: either a
pending packet or an actual ethernet address.

It is then possible to unite these 2 attributes to save 4 bytes
per-entry.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 35a7804cdf net/arp: Centralize ARP request timeout through one k_delayed_work
Until now, each ARP entry had a k_delayed_work to be used as a timer
when the ARP entry is a pending one, waiting for the ARP request to
succeed in order to get to the ARP table.

But k_delayed_work is not a small object (40 bytes). Thus reworking the
ARP request timer by having one central k_delayed_work and a timestamp
in every ARP entry properly handled at every timeout (1+ entry might
have reached the timeout then).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 0025a3fce2 net/arp: Optimize ARP table by switching to various single list
Instead of looping over the entries array, which will keep the same
order, let's use slist: one for free entries, one for pending ones and
finally one as the actual ARP table.

This permits some optimizations in how to look up and making small
heuristics by changing entries order when it seems relevant.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 89eeba4250 net/arp: No need to expose publicly arp header
ARP is something internal to ethernet L2, let's just hide its header
file.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Jukka Rissanen 67b4c5d5d4 samples: net: gptp: Sample application for gPTP support
The application does not do much, it just registers to a callback
in order to get information about gPTP.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-28 16:50:50 +03:00
Jukka Rissanen 45b06a252f net: gptp: Initial core IEEE 802.1AS support
Core IEEE 802.1AS-2011 (gPTP) support and application interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2018-06-28 16:50:50 +03:00
Jukka Rissanen 8ae6bad21d net: l2: Move the layer 2 code into subsys/net/
The subsys/net/ directory is more logical place for L2 code instead
of ip/ directory. No functionality changes by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-27 17:02:59 +03:00