Commit graph

550 commits

Author SHA1 Message Date
Florian Grandel 7db0184e1b drivers: ieee802154: nRF5: remove RX PHR offset workaround
Builds upon the newly introduced nrf_802154_phr_timestamp_get() function
to calculate RX timestamps according to the timestamp definitions
introduced in earlier commits and removes the prior workaround to
calculate the start-of-frame message timestamp point.

Fixes: #59245

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-08-16 17:06:16 +02:00
Florian Grandel eacec3dad2 modules: openthread: radio: encapsulate OT 32-bit timestamp
OT does not have 64 bit timestamp support. This is a limitation of OT
and not of the IEEE 802.15.4 driver API. Therefore any workaround
related to such OT idiosyncracies should be encapsulated inside the OT
adapatation layer.

This change moves the OT-specific conversion of OT 32 bit timestamps to
Zephyr 64 bit timestamps into the OT adaptation layer.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-08-16 17:06:16 +02:00
Eduardo Montoya f4d54fa4b9 drivers: ieee802154: nrf5: fix handling multiple CCA
Fix a couple of bugs introduced with last commits related to multiple
CCA support.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2023-08-09 08:32:26 +00:00
Florian Grandel a4cd5cee40 drivers: ieee802154: consistent high res timestamps
The IEEE 802.15.4 API and networking subsystem were using several
inconsistent timestamp resolutions and types. This change defines all
timestamps with nanosecond resolution and reduces the number of
available types to represent timestamps to two:
* `struct net_ptp_time` for PTP timestamps
* `net_time_t` for all other high resolution timestamps

All timestamps (including PTP timestamps) are now referred to a
"virtual" local network subsystem clock source based on the well-defined
types above. It is the responsibility of network subsystem L2/driver
implementations (notably Ethernet and IEEE 802.15.4 L2 stacks) to ensure
consistency of all timestamps and radio timer values exposed by the
driver API to such a network subsystem uptime reference clock
independent of internal implementation details.

The "virtual" network clock source may be implemented based on arbitrary
hardware peripherals (e.g. a coarse low power RTC counter during sleep
time plus a high resolution/high precision radio timer while receiving
or sending). Such implementation details must be hidden from API
clients, as if the driver used a single high resolution clock source
instead.

For IEEE 802.15.4, whenever timestamps refer to packet send or receive
times, they are measured when the end of the IEEE 802.15.4 SFD (message
timestamp point) is present at the local antenna (reference plane).

Due to its limited range of ~290 years, net_time_t timestamps (and
therefore net_pkt timestamps and times) must not be used to represent
absolute points in time referred to an external epoch independent of
system uptime (e.g.  UTC, TAI, PTP, NTP, ...).

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-28 09:06:35 +00:00
Florian Grandel 29988b5c04 drivers: ieee802154: nRF5: fix return type
Adapts a return type to the API specification. The changed return type
is not referenced anywhere so it can be changed without breaking
backwards compatibility.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-28 09:06:35 +00:00
Andrzej Kuros 9babac94a7 drivers: ieee802154: nrf5: multiple CCA support
The support for capability IEEE802154_OPENTHREAD_HW_MULTIPLE_CCA is added
to the ieee802154_nrf5 driver.

Signed-off-by: Andrzej Kuroś <andrzej.kuros@nordicsemi.no>
2023-07-25 09:13:41 +02:00
Andrzej Kuros 3f4da29a3c drivers: ieee802154: nrf5: Revert Add transmission with multiple CCA
This reverts commit 5443d4127b.

Signed-off-by: Andrzej Kuroś <andrzej.kuros@nordicsemi.no>
2023-07-25 09:13:41 +02:00
Robert Lubos 5c5be08ba9 drivers: ieee802154_nrf5: Use generic symbols for packet size
Use generic symbols defined in ieee802154.h for packet/FCS size instead
of redefining them in the driver header.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-20 16:24:26 +02:00
Robert Lubos cf58d11f8f drivers: ieee802154_nrf5: Add payload length check on TX
In case upper layer does not follow the convention, and the net_pkt
provided to the nRF 15.4 driver had a payload larger than the maximum
payload size of an individual 15.4 frame, the driver would end up with
buffer overflow.

Fix this by adding an extra payload_len check before attempting to copy
the payload to the internal buffer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-07-20 16:24:26 +02:00
Andrzej Kuros 5443d4127b drivers: ieee802154: nrf5: Add transmission with multiple CCA
The Kconfig IEEE802154_NRF5_MULTIPLE_CCA option is added.
The new functions `z_ieee802154_nrf5_extra_cca_attempts_set` and
`z_ieee802154_nrf5_extra_cca_attempts_get` are added.
The ieee802154_nrf5.c is updated allowing to pass extra cca attempts
to nRF 802.15.4 Radio Driver.

Signed-off-by: Andrzej Kuroś <andrzej.kuros@nordicsemi.no>
2023-07-14 09:46:36 -04:00
Damian Krolik a6e9782b01 drivers: ieee802154: fix declaration in case blocks
The code declares variables in switch-case blocks. This
seems to compile without an error on GCC 11 and newer,
but older compilers don't accept this code.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2023-07-07 11:29:33 +02:00
Florian Grandel 7232c38828 drivers: ieee802154: cc13/26xx_subg: fix PHY overrides
PHY overrides have been checked against the latest version of TI's
SmartRF(TM) Studio. The result was regression tested (PER/performance)
against LAUNCHXL-CC1352P1 boards.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel fe03bb5f1a drivers: ieee802154: cc13/26xx_subg: fix subg_start() return value
The radio API should indicate errors when the interface is started.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 122a10fdaa drivers: ieee802154: cc13/26xx_subg: fix header len const
The length field in the header refers to the size of the MAC so it
shouldn't rely on constants describing PHY header length. While
currently both constants have the same value this will no longer be true
for enhanced PHYs and/or MAC frames as the number of FCS bytes may then
be four.

Also introduces an assertion that ensures that the given package buffer
does not exceed the TX buffer's length. An assertion is enough as the
package buffer is allocated at compile time.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel ea89a1f9b5 drivers: ieee802154: cc13/26xx_subg: conditional RX after set_channel
The call to radio_api->set_channel() must not switch on RX if it was
previously off.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 0ea5658491 drivers: ieee802154: cc13/26xx_subg: remove unused radio commands
The CMD_CLEAR_RX and CMD_SET_TX_POWER commands are declared and
initialized but not used anywhere. They are therefore removed to reduce
RAM/flash footprint.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel a94877b8b1 drivers: ieee802154: cc13/26xx_subg: improve CSMA/CA compliance
Switch the driver to the soft CSMA/CA algorithm as an intermediate
compromise for improved standard compliance (namely expontential
backoff) until true hardware support can be implemented by chaining
radio commands.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 8a86f0c30e drivers: ieee802154: cc13/26xx_subg: fix CCA method
The driver's CCA method had various issues and would always return an
error code. This is fixed in this change.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel f0cb607a87 drivers: ieee802154: cc13/26xx_subg: inline documentation
This change introduces inline documentation with references to the
current version of the IEEE 802.15.4 standard.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 6bb03b5e3b drivers: ieee802154: cc13/26xx_subg: fix/document non-standard CSMA/CA
The CC13xx/CC26xx Sub-GHz driver announces a hardware CSMA/CA capability
which it provides only partially. This change documents the gap.

The change also fixes two related issues with the current CCA
implementation:

- The given default ED threshold was above the allowed threshold
  defined in the specification.

- The CCA timeout was not calculated according to the requirements
  defined in the standard.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 0f21a18f4b drivers: ieee802154: cc13/26xx_subg: readability improvements
This change introduces standard variable names used elsewhere in the
stack for improved naming consistency and readability.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel f05277a367 drivers: ieee802154: cc13/26xx_subg: fix invalid KConfig reference
The driver contained references to KConfig variables w/o the required
CONFIG_ prefix. This change introduces the missing prefixes.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 6683c2833c drivers: ieee802154: cc13/26xx_subg: remove dead code
The channel-to-frequency conversion had unreachable code which is
removed in this change.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 154ac22608 drivers: ieee802154: cc13/26xx_subg: remove redundant configuration
The low-level configuration of the chip's radio commands was mostly
redundant. This change removes redundant configuration code.

This is also relevant as a preparation to supporting further frequency
bands and operating modes on the same SUN FSK channel page with
similar but slightly different settings (center frequencies, channel
spacing, modulation index as defined in the standard). The SUN FSK
standard defines plenty of such variations with different physical
characteristics and trade-offs. Such variations are highly relevant in
industrial applications which will be targeted by TSCH. Using the
correct settings is required for additional features (e.g. frequency
hopping) and interoperability.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 81fa03f7a3 drivers: ieee802154: cc13/26xx_subg: clean up constants
The CC13xx/CC26xx Sub-GHz driver header file defined several constants
that were not used in the driver.

Other constants could be replaced with generic constants which were
introduced in the prior commit.

This change removes and/or replaces redundant definitions.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 09:20:55 +02:00
Florian Grandel 7571be3261 net: l2: ieee802154: deprecate NET_L2_IEEE802154_ACK_REPLY
Acknowledgment is mandatory if legitimately requested by the package's
"ACK requested" flag. The L2 layer will have to ensure that compliant
ACK packages will always be sent out automatically as required by the
standard.

For IEEE 802.15.4 compliance, the NET_L2_IEEE802154_ACK_REPLY option is
therefore being deprecated.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel f96b620d12 net: l2: ieee802154: properly handle TX HW capabilities
The existing calls to ieee802154_radio_send() and soft MAC ACK handling
were inconsistent and/or not properly integrated with more recent
radio driver capabilities as CSMA/CA and ACK in hardware.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Florian Grandel 1ee4d3ed77 net: l2: ieee802154: document L1/L2 sep. of concerns
The method ieee802154_radio_handle_ack() does not belong to the
PHY/radio layer but to the L2 layer. It is a callback called from the
radio layer into the L2 layer and to be implemented by all L2 stacks.
This is the same pattern as is used for ieee802154_init(). The
'_radio_' infix in this function is therefore confusing and
conceptually wrong.

This change fixes the naming inconsistency and extensively documents
its rationale.

It is assumed that the change can be made without prior deprecation of the
existing method as in the rare cases where users have implemented custom
radio drivers these will break in obvious ways and can easily be fixed.

Nevertheless such a rename would not be justified on its own if it were
not for an important conceptual reason:

The renamed function represents a generic "inversion-of-control" pattern
which will become important in the TSCH context: It allows for clean
separation of concerns between the PHY/radio driver layer and the
MAC/L2 layer even in situations where the radio driver needs to be
involved for performance or deterministic timing reasons. This
"inversion-of-control" pattern can be applied to negotiate timing
sensitive reception and transmission windows, it let's the L2 layer
deterministically timestamp information elements just-in-time with
internal radio timer counter values, etc.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 16:20:21 -04:00
Eduardo Montoya 574a533cb6 net: openthread: allow to configure CSL debugging
Add new `IEEE802154_CSL_DEBUG` Kconfig option that, when enabled,
prevents the radio to sleep after a delayed reception is finished.

This allows to debug CSL timing issues due to accuracy drifts in
communications between receiver and transmitter.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2023-06-17 07:48:25 -04:00
Florian Grandel b224a099fd net: l2: ieee802154: standardize RSSI value
The RSSI value in net_pkt (net_pkt_cb_ieee802154.rssi) was used
inconsistently across drivers. Some drivers did cast a signed dBm value
directly to net_pkt's unsigned byte value. Others were assigning the
negative value of the signed dBm value and again others were offsetting
and stretching the signed dBm value linearly onto the full unsigned byte
range.

This change standardizes net_pkt's rssi attribute to represent RSSI on
the RX path as an unsigned integer ranging from 0 (–174 dBm) to 254 (80
dBm) and lets 255 represent an "unknown RSSI" (IEEE 802.15.4-2020,
section 6.16.2.8). On the TX path the rssi attribute will always be
zero. Out-of-range values will be truncated to max/min values.

The change also introduces conversion functions to and from signed dBm
values and introduces these consistently to all existing call sites. The
"unknown RSSI" value is represented as INT16_MIN in this case.

In some cases drivers had to be changed to calculate dBm values from
internal hardware specific representations.

The conversion functions are fully covered by unit tests.

Fixes: #58494

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-17 07:16:32 -04:00
Gerson Fernando Budke 612d5b3796 drivers: ieee802154: rf2xx: Check gpio_add_callback return
The rf2xx does not check the return value from gpio_add_callback
function, which can prevent it from detecting unexpected states and
conditions. This add error processing check and log.

Fixes: #58595

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2023-06-01 18:04:08 -04:00
Robert Lubos f3bdac91b2 net: ieee802154: Remove IEEE802154_2015 option usage
The IEEE802154_2015 option is misleading, as it does not introduce full
802.15.4-2015 standard compliance but only random bits, plus it's
defined at the radio driver level, which brings yet another confusion.
Because of that, the option will be deprecated, and respective parts of
code that made use of it converted to use more specific configurations:

* nRF driver will now use CONFIG_NRF_802154_ENCRYPTION to specify
  whether to compile in TX security
* net_pkt will only add extra 802.15.4 control block fields if
  OpenThread is used, as they were solely used by this L2
* OpenThread radio layer will now use the OpenThread version to
  determine whether to compile in TX security.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-06-01 04:53:02 -04:00
Florian Grandel 32e1213b0c net: l2: ieee802154: improve inline documentation
Over time, some non-standard concepts and extensions were introduced
into the stack (in KConfig, in drivers, in the internal API and into the
implementation) which makes introduction of additional standard-
compliant extensions like TSCH (and others) unnecessarily difficult.

To introduce extensions like TSCH it is required for the IEEE 802.15.4
stack to become more structurally aligned with the standard again which
will be the focus of some of the upcoming preparatory changes.

One way to check and prove standard compliance is to reference the
standard from within the source code. This change therefore introduces
inline references to the IEEE 802.15.4-2020 standard wherever possible.
Deviations from the standard are documented with TODO or deprecation
labels to be addressed in future changes.

In the future, new code introduced to the IEEE 802.15.4 stack should
be documented and reviewed for standard-compliance to avoid further
divergence. Most importantly:
* MAC/PHY configuration (via net mgmt, radio API, devicetree or
  KConfig) should always be directly linked to well-defined MAC/PHY
  PIB attributes if visible to the MAC API or the end user.
* Net management/shell/radio API commands should have a documented
  reference to the corresponding MLME action from the standard.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-05-24 16:41:57 +02:00
Andrzej Kuros 174b7f4775 nrf_802154: nrf_802154_serialization_error never returns
Functions nrf_802154_serialization_error and
nrf_802154_sl_fault_handler shall never return.
However `__ASSERT()` might expand to an empty instruction
CONFIG_ASSERT=n and is not enough to stop execution.

Signed-off-by: Andrzej Kuroś <andrzej.kuros@nordicsemi.no>
2023-05-24 16:41:39 +02:00
Ryan McClelland eb5a52070b drivers: ieee 802.15.4:: fix double-promotions warnings
some floats were getting promoted to doubles or they needed to be
casted as doubles to be used by printf

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-04-26 12:58:28 +02:00
Keith Packard 6dd86fdb39 drivers/ieee802154: Cast float abs param to int first
This case takes a float value and passes it to the integer abs function,
storing the result in an integer type variable. That looks like a possible
error to clang, so insert an explicit cast to int to make the compiler
happy.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-05 10:38:34 +02:00
Eduardo Montoya 570110e672 drivers: ieee802154: remove not useful log
Remove a warning log which shows on every delayed transmission and
it is not helpful.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2023-03-28 15:07:33 +02:00
Henrik Brix Andersen c41dd36de2 drivers: kconfig: unify menuconfig title strings
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".

Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 15:06:06 +02:00
Maciej Baczmanski bcf1e8150b drivers: ieee802154: Fix csl_rx_time overflow issue for NRF5 and
clean up redundant static functions

convert `csl_rx_time` to uint32_t and remove redundant `nrf5_schedule_rx`
`nrf5_config_csl_period` and `nrf5_receive_at` static functions.

`csl_rx_time` has been passed as uint32. It is compared to uint64 value
returned by `nrf_802154_sl_timer_current_time_get` in
`nrf_802154_ie_writer.c` which leads to wrong calculation of phase in CSL.

Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
2023-03-20 10:47:33 +01:00
Vaishnav Achath c6da2ebe77 drivers: ieee802154: cc13xx_cc26xx: Allow both radios to coexist
Currently the 2.4G radio driver for CC1352 has few implementations which
prevents both the radios to be used in a single build, thus preventing
applications to have different builds to switch the RF bands even though
the hardware supports dual bands simultaneously.

The following updates are made:
 * Remove RF patches from stack.
 * Implement if_stop() to stop the interface and yield the interface.
 * Use RF_runCmd() instead of RF_runImmediateCmd() so that two RF handles
 can work simultaneously.

All the updates are similar to the more recent cc13xx subg driver which
implements all these recommended practices already.

Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
2023-03-10 10:22:16 -05:00
Vaishnav Achath 2535a46995 drivers: ieee802154: cc13xx_cc26xx_subg: Skip CRC for invalid packets
During extended testing, rx_done() callback was seen to be invoked with
zero-length packets.When RAW_MODE is enabled, CRC is being appended to
these packets thus making downstream consumers think the packet is valid.
Root cause of the callback being invoked with zero-length packet is
unknown, but appending CRC to these packets is incorrect, thus fix it.

Also fix a minor error which causes build failure when
CONFIG_NET_L2_IEEE802154_SUB_GHZ is not defined.

Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
2023-03-10 10:22:16 -05:00
Przemyslaw Bida dc5155e5a5 openthread: ieee802154_nrf5: Add implementation of new api.
Adding an Openthread radio API `otPlatRadioSetMacFrameCounterIfLarger`
implementation and the corresponding call to the IEEEE802154 driver.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2023-03-08 11:07:22 +01:00
Maciej Baczmanski 01884c857a drivers: ieee802154: nrf5: added continuous_carrier API call
implemented `nrf5_continuous_carrier()` which starts continuous
carrier wave transmission

Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
2023-02-24 09:26:01 +01:00
Krishna T 186fbc33a2 drivers: ieee802154: Fix build error for variable net buffers
The assert is only applicable for fixed network buffers, so, add a
protection.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-22 12:18:24 +01:00
Andrei Emeltchenko 9c1076e7f7 drivers: ieee802154_rf2xx: Remove magic number
Define and use RF2XX_TRAC_STATUS instead of magic number.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-02-10 18:13:48 +01:00
Andrei Emeltchenko 72c5bc3ae2 drivers: ieee802154_rf2xx: Correct bit mask
Correct bit mask for RF2XX_RX_TRAC_BIT_MASK. Current mask produce dead
code warnings when comparing to value:

RF2XX_TRX_PHY_STATE_TRAC_INVALID = 0x07

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-02-10 18:13:48 +01:00
Alberto Escolar Piedras 0de83109de drivers: ieee802154_nrf5: Fix warning in ISR prototype
The ISR prototype was changed some time ago
(6df8b3995e)
to (const void*) => fix the prototype used when
CONFIG_IEEE802154_NRF5_EXT_IRQ_MGMT is not set
to avoid a compile warning.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-01-27 12:35:33 +01:00
Stancu Florin 817e41f965 boards: cc1352p1_launchxl: new board, support antenna switching
Added new CC1352P1 LaunchXL board supporting 20dBm TX for its
sub-GHz radio.

Note that the board has a multiplexer circuit to switch between
2.4GHz, High-Power TX and Sub1GHz states, for which a custom board
module was implemented, together with board-specific device-tree
bindings and pinctrl definitions for each of the RF states.

Signed-off-by: Stancu Florin <niflostancu@gmail.com>
2023-01-27 17:44:38 +09:00
Stancu Florin e41de9235a drivers: ieee802154: cc13xx_cc26xx_subg: PA TX amplifier support
Enhance IEEE802154 Sub-GHz driver to support CC13x2P's internal power
amplifier (20dBm) for TX.

Note: requires board-specific antenna switching for it to work
properly.

Signed-off-by: Stancu Florin <niflostancu@gmail.com>
2023-01-27 17:44:38 +09:00
Andrei Emeltchenko ec8c9f05fc drivers: ieee802154_rf2xx: Fix logical operation
Fix using AND instead of OR.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-25 14:58:09 +00:00
Gerson Fernando Budke 97967f0526 drivers: ieee802154: rf2xx: Fix hang on 0x2c isr_status
When transceiver is overload on reception a frame can be stored on
the internal buffer without processing a frame start interrupt. The
frame will complete and system will received a interrupt and signal
receiver thread with an isr_status equal to 0x2c.

The current implementation process one flag at time and it may hang
when status is 0x2c. This issue can be reproduced using two nodes
where one perform a regular TX broadcast and tThe other one should
be wait for frames. The receptor should run on debug mode and system
should be started normally. The problem happens when pressing CTRL+C
on the debugger, which will cause system to stop. However, the
transceiver still can receive one last frame. After a few transmission
user can continue application and a isr_status of 0x2c will be visible
if CONFIG_IEEE802154_DRIVER_LOG_DEBUG is enabled.

This fixes the current issue by processing all RF2XX_TRX_END events.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2023-01-23 09:33:53 -08:00
Erwan Gouriou 66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Bartosz Bilas e077fb73ec drivers: tests: replace usage of spi_is_ready with spi_is_ready_dt
`spi_is_ready` function is being deprecated in favor of
`spi_is_ready_dt` so let's replace the old usage in the tree.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-12-07 09:40:23 -06:00
Anas Nashif cffe98d9de crc: Make the build of crc function dependent on a Kconfig
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.

Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.

Partial fix for #50654

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-23 13:30:00 +01:00
Robert Lubos 387a66131e net: pkt: Introduce minimum length requirement to net_pkt_get_frag()
net_pkt_get_frag() and a few other functions did not specify the
allocated fragment length, incorrectly assuming that fixed-sized
buffers are always used.

In order to make the function work properly also with variable-sized
buffers, extend the function argument list with minimum expected
fragment length parameter. This allows to use net_buf_alloc_len()
allocator in variable buffer length configuration, as well as verify if
the fixed-sized buffer is large enough to satisfy the requirements
otherwise.

Update the existing codebase to provide the expected fragment length,
based on the context.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-11-19 07:39:32 -05:00
Artur Hadasz f610743ef8 drivers: ieee802154_nrf5: Removed CSL placeholder window
Since nRF IEEE 802.15.4 radio driver is now capable of calculating CSL
phase based on provided anchor time and CSL period, the CSL placeholder
window is no longer necessary. This commit removes it and switches to
the new calculation method.

Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
Signed-off-by: Jędrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
2022-11-16 11:19:33 +01:00
Florian Grandel b674ed6b8b net: pkt: decouple from ieee802154 internals
This change implements part two of the program laid out in the TSCH RFC,
see #50336#issuecomment-1250250154 :

> Consolidate IEEE 802.15.4 options in net_pkt

This change improves decoupling of generic net core code from
IEEE 802.15.4 internals. It also simplifies IEEE 802.15.4
attribute cloning and thereby makes it easier to maintain and less
error prone (and probably even faster as individual bits are no longer
copied over separately).

This enables us to extend and design IEEE 802.15.4 L2 attributes inside
the package in isolation from the net core code which will no longer
have to be changed when introducing changes or additions to the flags.

This flexibility will be built upon in later change sets to model the
IEEE 802.15.4 attributes closer to the spec.

The solution is inspired by Linux's sk_buff->cb attribute which addresses
the same concern as the attribute introduced in this change set:
https://elixir.bootlin.com/linux/v6.0.1/source/include/linux/skbuff.h#L871

As the inline comment says: The cb attribute can be made a union or even a
uint8[something] in the future, if further L2s need a control block, too.
Right now such full indirection would make the code overly abstract, so
I chose to compromise with maintainability in mind.

Care has been taken to ensure that this changes does not introduce
additional padding into the net package. To maintain zero-padding, future
changes to the net packet struct will have to ensure that the
IEEE 802.15.4 struct is 4-byte aligned (iff the IEEE 802.15.4 struct
continues with max uint32_t scalar members) which is no deviation from
the previous implementation.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-17 16:54:37 +02:00
Florian Grandel 93647ed52b drivers: ieee802154: nrf: wrapped pkt attribute access
Nordic's IEEE 802.15.4 radio driver adapter layer had a few raw accesses
to net packet attributes.

Packet attributes should never be accessed directly, though, but only
through the dedicated accessor methods provided by the net core.

This change replaces raw accesses to packet attributes by their
respective wrapper functions.

This also is a necessary precondition to the isolation and
encapsulation of IEEE 802.15.4 specific packet attributes which will be
introduced in a later commit of this change set.

Fixes: #51264

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-17 16:54:37 +02:00
Florian Grandel 62ed153a86 drivers: ieee802154: don't allocate rx pkt from tx pool
Several IEEE 802154 drivers allocated RX packets from the TX pool.

This may seem like a minor problem at first sight but it may become
problematic if the pool is used to distinguish package types as is the
case in some code paths, e.g. for packet priority or determination of
the packet buffer pool.

This bug also has the potential of starving the TX pool capacity which
even may make devices vulnerable to DoS attacks as sending may be
prohibited by addressing enough RX packets to a device to let it run out
of TX capacity.

Fixes: #51261

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-17 16:54:37 +02:00
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Florian Grandel 631f117ed1 drivers: ieee802154: document endianness
The IEEE 802.15.4 radio driver encodes attributes in:

* little endian for everything that is close to the protocol as
  IEEE 802.15.4 frames are little endian encoded.

* mixed big and little endian in its configuration where extended
  addresses are being represented. These inconsistencies are unfortunate
  but cannot be easily fixed in a backwards compatible way so will be
  left untouched in this change.

Endianness was almost nowhere documented which explains these
inconsistencies and led to several bugs where assignments of different
byte order are not converted (or sometimes converted, sometimes not).

This change documents intended endianness within the realm of the
IEEE 802.15.4 radio driver code. Conversion bugs are fixed in a separate
commit.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-10-12 18:40:59 +02:00
Gerson Fernando Budke 6d5cdc17b4 drivers: ieee802154: rf2xx: Add support to Sub-Giga
Add support to at86rf212[b] sub-giga devices. This work enables use of
pages 0, 2 and 5 in accordance with IEEE-802.15.4/2003/2006/2011. The
proprietary speeds can be object of future work.

Note: It is recommended that user define a power table for better
performance, low emissions and to save power. A reference power table
can be found in the datasheet and should be used for tests only and
not on a final product.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-09-09 10:31:35 -07:00
Gerson Fernando Budke 65960c4d32 drivers: ieee802154: rf2xx: Move power table to devicetree
The current version of power table is hardcoded in the driver which is a
problem when use devices in production. This change remove all hardcode
from driver and reimplement the feature to allow people create a table
which is defined in devicetree. The big advantage is that each board can
define their own table based on lab tests and allows use of FEM devices
inclusive.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-09-09 10:31:35 -07:00
Florian Grandel c3b080166e drivers: ieee802154: introduce consistent MTU definition
This change applies the newly introduced consistent MTU definition to
all IEEE 802.15.4 radio drivers.

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-31 21:52:37 +00:00
Gerard Marull-Paretas a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Kumar Gala 616342d58b drivers: ieee802154: Move to using select in Kconfig for SPI bus
* Move to using 'select SPI' instead of 'depends on'
  (see commit df81fef944 for
   more details)

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-08-12 11:33:02 +02:00
Florian Grandel 4f8c952c4a drivers: ieee802154: Make raw mode and l2 mutually exclusive
Activating both, the IEEE 802.15.4 raw mode /and/ the L2 mode is not
possible and in fact leads to a build error.

It should therefore not be possible to activate both options at the same
time. This is achieved by only offering the (rather exotic) raw mode
once the L2-support for the IEEE 802.15.4 has been switched off.

Fixes: #48715

Signed-off-by: Florian Grandel <jerico.dev@gmail.com>
2022-08-05 15:04:43 +02:00
Gerard Marull-Paretas a6058dc4b1 drivers: ieee802154: IEEE802154 depends on NETWORKING
Previous to this change, each individual driver option depended on
NETWORKING. Instead, move dependency one level up.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-05 12:56:47 +02:00
Gerard Marull-Paretas 352c9c34ee drivers: ieee802154: depend on DT status and default to y
Make all drivers default to 'y' and dependent on being enabled in DT.
This will allow simplifying many samples/tests.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-05 12:56:47 +02:00
Gerard Marull-Paretas e6a345f967 drivers: ieee802154: uart_pipe: make driver DT-based
Use Devicetree to describe the UART UPIPE IEEE 802.15.4 driver. This
allows to remove usage of IEEE802154_UPIPE_DRV_NAME in preparation for
the removal of NET_CONFIG_IEEE802154_DEV_NAME.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas d904b5d908 drivers: ieee802154: uart_pipe: split Kconfig
As all other drivers, keep uart_pipe driver Kconfig settings into its
own file.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 1d6862c4e9 drivers: ieee802154: rf2xx: remove unused IEEE802154_RF2XX_DRV_NAME
The option is no longer used (driver is DT-based).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 2df965f490 drivers: ieee802154: nrf5: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_NRF5_DRV_NAME in preparation for the
removal of NET_CONFIG_IEEE802154_DEV_NAME.

All SoC files have been updated with the addition of an ieee802154 node
(disabled and only on those SoCs that define ieee802154-supported. The
peripheral has been enabled in the nRF52840DK board (used for testing
ieee802154).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 7d5272db62 drivers: ieee802154: kw41z: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_KW41Z_DRV_NAME in preparation for the removal
of NET_CONFIG_IEEE802154_DEV_NAME.

KW41Z files have been updated with the addition of radio and an
ieee802154 nodes The peripheral has been enabled in the frdm_k41z board
(used for testing ieee802154).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas dc0728fb2a drivers: ieee802154: cc2520: drop IEEE802154_CC2520_CRYPTO_DRV_NAME
The crypto driver is used internally, so there's no real need to expose
its name as a Kconfig option. Just drop it in favor of a plain string
with the same previous value.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas fb9dbdd60e drivers: ieee802154: cc13x2_cc26x2_subg: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_CC13XX_CC26XX_SUBG_DRV_NAME in preparation
for the removal of NET_CONFIG_IEEE802154_DEV_NAME.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas fa16891625 drivers: ieee802154: cc13x2_cc26x2: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_CC13XX_CC26XX_DRV_NAME in preparation for the
removal of NET_CONFIG_IEEE802154_DEV_NAME. All boards used in testing
have been updated to enable the peripheral in DT as well.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 1ff6577e30 drivers: ieee802154: cc1200: make driver DT-based
Use Devicetree to describe the radio and IEEE 802.15.4. This allows to
remove usage of IEEE802154_CC1200_DRV_NAME in preparation for the removal
of NET_CONFIG_IEEE802154_DEV_NAME.

In this case, the driver already had bindings, however, it was still
using NET_DEVICE_INIT.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 13:25:35 +02:00
Gerard Marull-Paretas 3dd0904ea6 drivers: ieee802154: cmake: remove TI compile definitions
Compile definitions are now injected by the HAL automatically.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-07-28 20:51:55 +02:00
Simon Hein d0921018fc drivers: Fix coding guidelines MISRAC:2012 Rule 14.4 do-whiles/Zero checks
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)

Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.

The commit is a subset of the original auditable-branch commit:
5d02614e34a86b549c7707d3d9f0984bc3a5f22a

Signed-off-by: Simon Hein <SHein@baumer.com>
2022-07-26 15:30:24 -04:00
Kumar Gala e99652b67d drivers: ieee802154: cc2520: Convert to DEVICE_DT_INST_DEFINE
Move driver to use {NET_}DEVICE_DT_INST_DEFINE.  This lets us
remove the IEEE802154_CC2520_DRV_NAME Kconfig symobl.

We also update the ieee802154 build_all test to actually enable
the CC2520 driver.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-19 10:32:21 +02:00
Kumar Gala 5cca6ed087 drivers: ieee802154: b91: Convert to DEVICE_DT_INST_DEFINE
Move driver to use {NET_}DEVICE_DT_INST_DEFINE.  This lets us
remove the IEEE802154_B91_DRV_NAME Kconfig symobl.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-19 10:32:09 +02:00
Johann Fischer 5e5ea9a21d drivers: use unsigned int for irq_lock()
irq_lock() returns an unsigned integer key.
Generated by spatch using semantic patch
scripts/coccinelle/irq_lock.cocci

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-07-14 14:37:13 -05:00
Pieter De Gendt aba4c4ea3e uart_pipe: move driver from console to serial
The uart_pipe driver is not dependent on any console driver,
however a serial driver is required.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2022-07-07 09:59:49 +02:00
Jedrzej Ciupis 8ed202b43d drivers: ieee802154: fix freeing Rx buffer
This commit fixes a bug where an already received Rx frame could not be
processed by the IEEE 802.15.4 driver.

In the current implementation, buffer is marked as free and released to
the buffer pool after `nrf_802154_buffer_free_raw` finishes executing.
However, delays caused by thread scheduling might result in a new frame
being already received and provided to the driver before
`nrf_802154_buffer_free_raw` returns. Such a situation ends in an
assertion now.

This commit changes that behavior by marking the buffer as free before
calling `nrf_802154_buffer_free_raw`.

Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
2022-07-04 16:39:14 +02:00
Jedrzej Ciupis c5df601ed5 drivers: ieee802154: print serialization error on nRF5340
This commit increases verbosity of serialization error handler for
nRF5340 application core. The handler prints the error code now.

Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
2022-07-04 16:39:14 +02:00
Kumar Gala a52f7a4e3a drivers: ieee802154: mcr20a: Remove unused variable
Since the driver uses spi_dt_spec there is no need for an explicit
spi_cs_control variable.  The variable is unused.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-06-29 06:02:28 -05:00
Gerard Marull-Paretas fd2052d524 drivers: remove redundant <zephyr/zephyr.h> includes
Files including <zephyr/kernel.h> do not have to include
<zephyr/zephyr.h>, a shim to <zephyr/kernel.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-06-15 09:13:11 +02:00
Jedrzej Ciupis 847f68ae10 drivers: ieee802154: nrf: set TX power selectively
This commit extends Nordic's ieee802154 driver with the possibility to
set Tx power for every transmission separately.

Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
2022-06-14 09:30:43 +02:00
Jedrzej Ciupis 644da741f4 net: pkt: add IEEE 802.15.4 TX power field
This commit extends the `struct net_pkt` structure with
`ieee802154_txpwr` field that contains signed value of the desired
transmission power of a IEEE 802.15.4 frame in dBm.

Signed-off-by: Jedrzej Ciupis <jedrzej.ciupis@nordicsemi.no>
2022-06-14 09:30:43 +02:00
Artur Hadasz 2094bfa183 drivers: ieee802154: nrf5: Fix DRX_ADJUST workaround
This PR introduces a fix for DRX window being triggered to early during
CSL. Fixes were also introduced in the nrf 802154 radio
driver, so removed the unneeded DRX_ADJUST constant.

Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
2022-06-13 12:09:57 +02:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Lukasz Maciejonczyk 5d5dcfa0b9 drivers: ieee802154_nrf5: fix target time for indirect transmission
After change in RD into 64-bit time, target time must be express in
absolute 64-bit time. Upper layer e.g. OpenThread still utilizes only
LSB of the RD time therefore the conversion is required.
Make sure that target time is absolute 64-bit target time.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-04-28 10:25:38 +02:00
Lukasz Maciejonczyk e661f6e96a drivers: ieee802154_nrf5: fix rx failure error propagation for CSL
For delayed reception only NRF_802154_RX_ERROR_DELAYED_TIMEOUT is
expected to happen, others rx errors should be handled in regular
manner.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-04-08 09:31:17 +02:00
Lukasz Maciejonczyk 55c3afab1c drivers: ieee802154_nrf5: add log for rx failure
Some failures are possible and expected from fime to time e.g.
NRF_802154_RX_ERROR_TIMESLOT_ENDED. Add informational log for the frame
reception failure to differentiate the specific case.
It can be helpful for analizing failure in network trafic.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-04-08 09:31:17 +02:00
Joakim Andersson 4b80afdd27 drivers: ieee802154: Use secure services
Allows the setting of ieee802154 EUI64 address in non-secure processing
environment by reading the FICR device ID through the secure service.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-04-04 11:15:28 +02:00
Lukasz Maciejonczyk 00a6d4cf78 drivers: ieee802154_nrf5: limit IEEE802154_NRF5_DELAY_TRX_ACC
Currently IEEE802154_NRF5_DELAY_TRX_ACC can exceed the max possible
value. Add upper bound to limit this.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-03-31 16:23:59 +02:00
Lukasz Maciejonczyk 8c6f49c845 drivers: ieee802154_nrf5: fix delayed operation accuracy
Align clock accuracy used in CSL calculations to the value in platform.
This is recomended setting for devices working in wide range
temperature. Nevertheless it can be profiled in end product to decrease
CSL window duration and finally the power consumption.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
2022-03-31 10:30:31 +02:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00