Commit graph

18755 commits

Author SHA1 Message Date
Nithin Ramesh Myliattil df45858d0f Bluetooth: BAP: Broadcast Source: Update stream codec config data
When creating a BAP broadcast source with bt_bap_broadcast_source_create
only the subgroup information is stored in the streams and the remaining
BIS specific information is not stored in the stream->codec_cfg,
which it should.
Fix is to store bis specific information also in stream codec config.
Updated broadcast source BSIM test to verify above usecase.

Signed-off-by: Nithin Ramesh Myliattil <niym@demant.com>
2024-06-13 08:04:27 -04:00
Fabio Baltieri 2c5b09cbda usb: device_next: rename the rate properties to use the correct unit
The polling properties are a period in us but are named as "-rate" right
now, which would imply that that's a frequency. Rename them to
"period-us" to make that unambiguous.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-06-13 08:03:49 -04:00
Rubin Gerritsen 5098bf3539 Bluetooth: Host: Callback registering functions to return status
Returning a status code will allow the application developer
to detect logic issues.

We consider this as not breaking the API.
If `-Werror -Wunused-result` is enabled, the application developer needs
to validate the return code.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Rubin Gerritsen 3eb975deb2 Bluetooth: Host: Rename callback_list -> conn_cbs
This improves consistency with other callback lists like
scan_cbs and pa_sync_cbs.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Rubin Gerritsen 2ec3cd307c Bluetooth: Host: Avoid registering callback twice
Callbacks can only be registered once. Otherwise the slist
will become circular.

In this commit we have choosen to ignore the second registration
call if the callback has already been registed. The alternative
is to trigger an assertion. That doesn't work if the assertions
are turned off.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Rubin Gerritsen 6e6bb26107 Bluetooth: Host: Conn callback list to use slist
This allows us to use functionality provided by slist.
First use case: Avoid adding an element twice.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-13 08:03:28 -04:00
Adrien Ricciardi b76d630682 fs: nvs: Add CRC-32 to protect data
Allow to protect the data part of each NVS item with a 32-bit CRC.
This uses 4 more bytes per NVS item.

Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
2024-06-13 05:51:56 -04:00
Konrad Derda cb3c087350 net: ipv6: mcast_routing: hop limit handling
While forwarding a multicast packet decrement hop limit in a common net
buffer. Also, packets with hop limit equal to 0 should not be forwarded.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-06-13 05:44:30 -04:00
Emil Gydesen db4d4cfda2 Bluetooth: Audio: Add fallback to cfg_meta_get_pref_context
Added a fallback parameter to
bt_audio_codec_cfg_meta_get_pref_context
as absence of pref context in BAP implicitly means a unspecified
for LC3.

In the case that it is absent BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED
is the returned value.

While the metadata for codec cfg and codec cap are similar,
this only applies for codec cfg as per BAP.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen c4b3b72b07 Bluetooth: Audio: Add fallback to max_codec_frames_per_sdu
Added a fallback parameter to
bt_audio_codec_cap_get_max_codec_frames_per_sdu
as absence of max codec frames per SDU in BAP implicitly
means a single frame for LC3.

In the case that it is absent 1 is the returned value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen 579b4f7e37 Bluetooth: Audio: Add fallback to supported_audio_chan_counts
Added a fallback parameter to
bt_audio_codec_cap_get_supported_audio_chan_counts
as absence of channel count in BAP implicitly means a single channel
for Lc3.

In the case that it is absent 1 is the returned value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen c6cc034b5c Bluetooth: Audio: Add fallback to get_chan_allocation
Added a fallback parameter to
bt_audio_codec_cfg_get_chan_allocation as absence of
channel allocation in BAP implicitly means Mono.
In the case that it is absent,
BT_AUDIO_LOCATION_MONO_AUDIO is the returned value.

This commit also fixes the implementation of
bt_audio_codec_cfg_get_frame_blocks_per_sdu as it only applies to
LC3 (as per the BAP spec). It also adds additional testing of it

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Adam Wojasinski 08689e1a20 net: ptp: Network interface status check in PTP thread
Adding network interface status monitor function. Depending
on the interface operation state and change of the state
events are generated and handled by the function.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 28111ba254 net: ptp: Implement PTP thread
This commit adds implementation of the PTP thread that will
poll sockets descriptors and PTP Port's timeres for timeouts,
generate events and handle them and trigger STATE_DECISION_EVENT
handling when needed.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski db07aa2c00 net: ptp: Add handler for STATE_DECISION_EVENT
The STATE_DECISION_EVENT in PTP is a pivotal mechanism that
facilitates dynamic state management within the protocol,
allowing devices to adapt their operational states based on the BTCA's
recommendations and the health of the network.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski edfe4cd8cc net: ptp: Add event generation and event handler for PTP Port
Introduction of PTP stack's core functions responsible for
event generation and handling of these events. Events are generated
base on timeouts and/or PTP messages received via BSD sockets
assigned to a specific PTP Port. These function will be used
in PTP thread.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski f22f36dd90 net: ptp: Implement PTP Port enabling and disabling functions
The commit adds functions that enable and disable PTP Port.
This is going to be used by event handling routine.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski e14e878084 net: ptp: Add timers processing for PTP Port
Timers are used to trigger message transmission and detect
inactivity of other PTP Clocks what should result in an action
of the PTP Port.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 73eaab29a0 net: ptp: Add functions for messages transmission
This commit introduces routines for PTP message transmission.
It includes transmission of three types of messages (Announce,
Sync, Delay_Req) that should be send periodically depending
on the PTP Port's state.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski cb35cc919a net: ptp: Add management message processing
Introduction of routines processing received PTP Management messages.
The processing is split into clock-oriented and port-oriented parts.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski fe0cc7dd26 net: ptp: Implement Best TimeTransmitter Clock algorithm for PTP stack
Add handler for STATE_DECISION_EVENT it consists of following routines:
- state decision algorithm
- best timeTransmitter clock algorithm
- data sets comparison algorithm

Based on IEEE 1588-2019 section 9.3.3

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 577e58cb17 net: ptp: Implement PTP message processing for ports
This commit adds routines for handling incoming messages
needed for correct operation of the PTP stack in end to end
mode with multicast operation mode.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 5c4be2be8c net: ptp: Introduce routines for PTP Hardware Clock adjustment
Initial implementation of the clock adjustment and delay calculation.
Timestamp values used for calculations will be obtained from
proper PTP messages (Sync, Follow_Up, Delay_Req, and Delay_Resp)

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 9aabe2e477 net: ptp: Add foreign timeTransmitter records
Foreign timeTransmitters are other PTP Clocks in a domain. They announce
their parameters via announce messages. PTP Ports should record
these foreign timeTransmitters.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 0575a500ce net: ptp: Add PTP Port ID comparison function
Based on Port ID decision about message processing can be made.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 3d7dd0d6fa net: ptp: Add sockets to PTP stack
This commit introduces module responsible for sending and receiving
messages. It is based on BSD Sockets API.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 8016fa1de1 net: ptp: Extend TLV with Management TLVs
This commit adds handling of Management TLVs

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 806ba0dcd3 net: ptp: Add TLV extension to PTP
Add allocation of container used for TLVs and dummy functions for
preparing correct byte order of data. TLV stands for Type, Length,
Value, and it is extension of PTP messages that's used to transmit
extra information. This data is attached at the end of PTP message.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 8f00c5f4de net: ptp: Add byte order manipulation for PTP messages
Add functions preparing messages to network byte order before sending
and changing to host byte order after reception and before processing
by PTP stack.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski e17cf5868d net: ptp: Add PTP message allocation and management
Add dynamic memory allocation for PTP messages. Memory allocation
is done with Zephyr's memory slab. It's size can be configured
with `PTP_MSG_POLL_SIZE` Kconfig symbol.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 7e45be1bf2 net: ptp: Add definition of PTP messages types
Introduces definition of structures for all types of PTP messages
defined in the IEEE 1588-2019 standard.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski af09e4abfb net: ptp: Add Kconfig symbols and preprocessor guards for some states
Based on IEEE 1588-2019 some of PTP Port states might not be used
if the option of 17.7 is implemented. This patch prepares state
machine implementation for such scenario.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 2e7dbf1091 net: ptp: Add TIME_RECEIVER_ONLY feature
Implement possibility to configure PTP stack in TIME_RECEIVER_ONLY mode.
This restrics stack behaviour and doesn't allow for any PTP Port
of the PTP Clock become a TimeTransmitter Clock.

The change includes:
- Kconfig option
- Additional field in `struct ptp_port` structure
- New state machine function for a timeReceiver-only PTP Port.
- Extra steps in PTP Clock and PTP Port initialization.

New finite state machine is based on the figure 31
in section 9.2.5 of the IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 74a25772c5 net: ptp: Add PTP Clock and PTP Port initialization
This commit introduces PTP Clock and PTP Port structures
and API for initializing PTP Clock and PTP Ports. Configuration
options has been added as Kconfig symbols to configure parameters
of the Clock and Ports at compile time.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 70e3183c40 net: ptp: Add definitions for PTP datasets
Datasets defined in the header file are going to be used
in PTP Clock's structure and PTP Port's structure. They
gather data into structures defined in IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 424c3706d1 net: ptp: Add finite state machine implementation for PTP stack
The patch brings implementationof a state machine for full
PTP implementation. It returns new PTP Port's state based
on event that occured and previous state.

Based on the figure 30 in section 9.2.5 of the IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 6a40371790 net: ptp: Add derived data type header
The header's file content is based on 5.3 section of
the IEEE 1588-2019 standard describing Precise Time Protocol (PTP)
used to synchronize devices in the network.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 58a611d814 net: ptp: Initial PTP library implementation
This is an initial commit that introduces PTP library in the Zephyr.
It adds basic Kconfig symbols for enabling library, CMakeLists.txt
for compiling it, public header file, and initial PTP thread definition
and library initialization. Implementation of the functional PTP stack
will be introduced in following commits.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski ee06da545d net: socket: Add SO_TIMESTAMPING data to messages received via socket
Add returning timestamp of received packet in ancillary data buffer
in `msghdr` structure. This commit enables getting timestamp of
the received packet by calling `recvmsg()` function. The function
returns in the `msg_control` field timestamp if following criteria
are met:
- `CONFIG_NET_CONTEXT_TIMESTAMPING` is set
- `SO_TIMESTAMPING` socket option has `SOF_TIMESTAMPING_RX_HARDWARE`
  option enabled for that socket
- driver used by sockets supports packet timestamping

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski cf89e1ca29 net: socket: Add support for SO_TIMESTAMPING socket level option
This is the last commit of the set of patches that introduces
`SO_TIMESTAMPING` socket level optino in Zephyr. The patch
adds `SOF_TIMESTAMPING_RX_HARDWARE` and `SOF_TIMESTAMPING_TX_HARDWARE`
bitmasks. It can be extedned in the future to cover more timestamping
features. Currently the feature can be used with ptp_clock driver.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 7ef4f470e2 net: context: Add support for timestamping in network context
This is next commit from the set of patches that brings to the
Zephyr, SO_TIMESTAMPING socket level option. It stores timestamping
option bitmask that can be transfered to the net_pkt.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 56338de16a net: pkt: Add flags to indicate the pkt should be timestamped
This is the first commit from the set of patches that brings to the
Zephyr, SO_TIMESTAMPING socket level option. This enables to pass to
the network driver information whether given network packet should
be timestamped or not.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski c87c36d313 net: if: Increment the packet ref count when adding to timestamp queue
Added incrementation of the packet reference count when puting
the packet on the queue used in tx timestamping thread. This fixes
an issue when user wants to access the packet data in the timestamp
callback context. Before the fix was introduced if sockets were used
packet has been unreferenced before execution reached timestamp callback
context.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Théo Battrel 7c3a5d5c3a Bluetooth: Host: Add Per Adv Sync handle getter
The same way as `bt_hci_get_adv_handle` and `bt_hci_get_conn_handle` add
a function to get the handle of a periodic advertising sync.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2024-06-13 05:34:14 -04:00
Emil Gydesen edbe34eaf2 Bluetooth: BAP: Add check for num_subgroups in parse_recv_state
In the parse_recv_state we did not verify that we can handle all
the subgroups before we started parsing them.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:32:43 -04:00
Valerio Setti 30c9f5eaa5 net: add proper PSA_WANT kconfigs for TLS sockets and RSA key exchanges
Add proper PSA_WANT kconfigs for TLS sockets and RSA key exchanges
when CONFIG_PSA_CRYPTO_CLIENT is set.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-13 09:22:20 +02:00
Valerio Setti 30717437f5 jwt: add missing PSA_WANT dependencies to RSA signature
This commit add the proper PSA_WANT kconfigs which are required
to perform an RSA signature when a PSA crypto provider is
available in the system (i.e. CONFIG_PSA_CRYPTO_CLIENT is set).

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-13 09:22:20 +02:00
Lyle Zhu 6458c5ab1f Bluetooth: HFP_AG: fix building warning
Give `err` a initialization value 0.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-12 21:13:58 -04:00
Lyle Zhu bbfa3bc1b9 Bluetooth: HFP_AG: Optimize lock/unlock of the SCO creating
When testing https://github.com/zephyrproject-rtos/zephyr/pull/72090/,
there is an issue found.

The change in the previous commit is to put all data sending
operations into the work queue context, and lock the current
AG before sending data.

And in change of #72090, the HCI TX thread is removed. All
sending sequence are happened in work queue context.

There is a possible problem when AG creates a SCO connection
by calling the function bt_conn_create_sco. Before the
function bt_conn_create_sco is called, AG will be locked to
avoid creating repeated SCO connection.
And the execution of the function bt_conn_create_sco
depends on the work queue. Because the HCI command of
function bt_conn_create_sco is sent in work queue context.

In the normal case, there is not any issue.
But there is a case that when the function
bt_conn_create_sco is being executed, there is a pending AG
TX waiting to be executed.

Once the work queue starts executing the handler, the AG TX
handler is executed first. Since the lock has been acquired
by other threads, the AG TX handler cannot acquire the lock.
As a result, the SCO connection creation fails.

Remove the AG lock from SCO creating. Instead, use a flag
to mark whether a SCO connection is be created.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-12 21:13:58 -04:00
Lyle Zhu 6939c8c02d Bluetooth: HFP_AG: Optimize the TX process
Due to the sent callback of RFCOMM is changed, the
sending buf need to be primed waiting for the
previous one to be completed. Add a worker for
this purpose.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-12 21:13:58 -04:00
Lyle Zhu f055fe7165 bluetooth: hfp_hf: update channel sent callback prototype
Due to the parameter `buf` has been removed by rfcomm,
update the prototype of channel sent callback hfp_hf_sent.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-12 21:13:58 -04:00
Lyle Zhu 17e2564ff2 bluetooth: rfcomm: remove tx meta
Due to the sending buf cannot be referred
by sending layer.
It is unsafe to use `buf` identification
for a transmission, because the buf may
have been newly transmitted when the
sent callback is triggered.

Now instead, when the send completion
callback is received, the upper layer
is notified that a transfer is completed.
If multiple bufs are sent at the same
time, there is no guarantee which buf
is completed when the sent callback
triggered. Therefore, it is recommended
that the caller transfers the next data
block after the previous transfer is
completed.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-12 21:13:58 -04:00
Lyle Zhu 7f71ad38cc bluetooth: rfcomm: fix issue of sending buf invalid
There is a change (commit no.: 93d0eac834) that if
the `ref` of sending buf is not 1, the error code
`-EINVAL` will be returned from bt_conn_send_cb.

It causes the RFCOMM functionality cannot work
properly.

Remove the ref operation from the buf to be sent
to fix the issue.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-06-12 21:13:58 -04:00
Daniel Leung 54af5dda84 kernel: mm: rename z_page_frame_* to k_mem_page_frame_*
Also any demand paging and page frame related bits are
renamed.

This is part of a series to move memory management related
stuff out of the Z_ namespace into its own namespace.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-06-12 21:13:26 -04:00
Daniel Leung 7715aa3341 kernel: mm: rename Z_SCRATCH_PAGE to K_MEM_SCRATCH_PAGE
This is part of a series to move memory management related
stuff from Z_ namespace into its own namespace.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-06-12 21:13:26 -04:00
Michał Barnaś 0b4365ef29 usbc: add support for TCPC control of vbus sourcing
Adds calls to the set_src_ctrl of TCPC driver to enable and disable
the VBUS sourcing. If the TCPC doesn't support these functions,
no errors should be printed.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2024-06-12 18:17:17 -04:00
Andries Kruithof a435dd3ee0 Bluetooth: Audio: CAP broadcast reception start bugfix
When validating the parameters for broadcast reception start some
return statements were missing, they have been added, as well as
proper initialisation of a variable

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-06-12 18:15:38 -04:00
Emil Gydesen 4c31e4b337 Bluetooth: BAP: Fix missing len increment when merging non-LC3 data
If we are merging subgroup and BIS codec configuration data
for a codec other than LC3, then we just append them, but
did not properly update the length.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-12 17:15:00 -05:00
Emil Gydesen be307f8ad9 Bluetooth: Audio: Change lang to 3-byte value from uint32_t
The 3-byte value suits the assigned number much better,
and also allows for less memory copies when getting and
setting the values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-12 12:54:16 -04:00
Emil Gydesen f08bc644a1 Bluetooth: Audio: Rename stream_lang to lang
Remove the "stream" part of the value and functions to
better fit with the name in the assigned numbers document.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-12 12:54:16 -04:00
Jonathan Rico 9b3f41de55 Bluetooth: host: don't pull data if no view bufs
View buffers are now also a limited resource. Acquire them before
attempting to pull data. `CONFIG_BT_CONN_FRAG_COUNT` should be tuned on
a per-application basis to avoid this.

A possible optimization, that was present before, is to not create a
frag when the original buffer fits the controller's HCI size.

I prefer deferring this optimization to a future patchset.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico 5a7ef422bb Bluetooth: host: use __maybe_unused for convenience variables
In order to suppress compiler warnings w/o using void/ifdef.

Suggested in #72854

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico b6cdf10310 Bluetooth: L2CAP: remove seg_pool
We can get rid of the view pool for SDU segments :)
We have to make the code slightly more complex :'(

The basic idea is always giving the original SDU buffer to `conn.c` for it
to pull ACL fragments from.

In order to do this, we need to add the PDU headers just-in-time.
`bt_l2cap_send_pdu()` does not add them before putting the PDU on the queue
anymore. They are added by `l2cap_data_pull()` right before the data leaves
`l2cap.c` for `conn.c`.

We also have to inform `conn.c` "out of band" of the real L2CAP PDU size so
it doesn't fragment across segment boundaries. This oob is the new `length`
parameter to the `.pull()` method.

This is the added complexity mentioned above.

Since SDU segmentation concerns only LE-L2CAP, ISO and Classic L2CAP don't
need this extra logic.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico 28be8909a6 Bluetooth: host: remove TX thread
We don't need the TX thread anymore.

Generalizing the pull-based architecture (ie. `tx_processor`) to HCI
commands makes it possible to run the whole TX path from the the system
workqueue, or any workqueue really.

There is an edge-case, where we call `bt_hci_cmd_send_sync()` from the
syswq, stalling the system. The proposed mitigation is to attempt to drain
the command queue from within `bt_hci_cmd_send_sync()`.

My spidey sense tingles however, and it would be better to just remove the
capability of calling this fn from the syswq. But doing this requires
refactoring a bunch of synchronous procedures in the stack (e.g. stack
init, connection establishment, address setting etc), dragging in more
work. I will do it, but in a later patch.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico 48d1cffb4d Bluetooth: L2CAP: remove CONFIG_BT_L2CAP_RESCHED_MS
We don't need it thanks to the new TX architecture.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico 38820efd8d Bluetooth: L2CAP: Make bt_l2cap_send_pdu()
This API replaces `bt_l2cap_send()` and `bt_l2cap_send_cb()`.

The difference is that it takes the `struct bt_l2cap_le_chan` object
directly instead of a connection + CID.

We need the channel object in order to put the PDU on the TX queue. It
is inefficient to do a search for every PDU when the caller knows the
channel object's address and can just pass it down.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico 28535fe2f2 Bluetooth: host: Change TX pattern (push -> pull)
The current TX pattern in the host is to try to push a buffer through all
the layers up until it is ingested by the controller.

Since sending can fail at any layer, we need error-handling and separate
retry logic on pretty much all layers. That logic obscures the "happy path"
for people trying ot understand the code.

This commit inverts the control, in a way that doesn't require changing the
host or HCI driver API (yet):

Layers don't send buffers synchronously, they instead put their buffer in a
private queue of their own and raise a TX flag on the lower layer. Think of
it as a `READY` interrupt line that has to be serviced by the lower layer.

Sending is now non-blocking, rate depends on the size of buffer pools.

There is a single TX processing function. This can be thought as the
Interrupt Service Routine that will handle the `READY` interrupt from the
layers above.

That `tx_processor()` will then attempt to allocate enough resources in
order to send the buffer through to the controller. This allocation logic
does not block.

After acquiring all the resources, the TX processor will attempt to pull
data from the upper layer. The upper layer has to figure out which buffer
to pass to the controller. This is a good spot to put scheduling or QoS
logic in the upper layer.

Notes:

- user-facing API for tuning QoS will be implemented in a future patch

- this scheme could (and probably will) be extended to upper layers (e.g.
  ATT, L2CAP CoC segmentation).

- this patch removes the `pending_no_cb()` memory optimization for
  clarity/correctness. It might get re-implemented after a stabilization
  period. Hopefully with more documentation.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Co-authored-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico 1c8cae30a8 Bluetooth: host: Introduce "view" buffer concept
Instead of allocating segments/fragments and copying data into them, we
allocate segments as "views" (or slices) into the original buffer.

The view also gives access to the headroom of the original buffer, allowing
lower layers to push their headers.

We choose not to allow multiple views into the same buffer as the headroom
of a view would overlap with the data of the previous view.

We mark a buffer as locked (or "in-view") by temporarily setting its
headroom to zero. This effectively stops create_view because the requested
headroom is not available.

Each layer that does some kind of fragmentation and wants to use views for
that needs to maintain a buffer pool (bufsize 0, count = max views) and a
metadata array (size = max views) for the view mechanism to work.

Maximum number of views: number of parallel buffers from the upper layer,
e.g. number of L2CAP channels for L2CAP segmentation or number of ACL
connections for HCI fragmentation.

Reason for the change:
1. prevent deadlocks or (ATT/SMP) requests timing out
2. save time (zero-copy)
3. save memory (gets rid of frag pools)

L2CAP CoC: would either allocate from the `alloc_seg` application callback,
or worse _steal_ from the same pool, or allocate from the global ACL pool.

Conn/HCI: would either allocate from `frag_pool` or the global ACL pool.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Co-authored-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Aleksander Wasaznik 52dc64f0d9 Bluetooth: conn: Allocate TX context JIT
`bt_conn_send_cb` used to allocate a TX context (K_FOREVER).
Instead, we now put the context in the userdata of the buffer.

This means that now this fn will never block and always succeed since the
tx_queue is a FIFO (infinite size). It just puts the buf on the queue.

The metadata is stored safely in there until we have acquired all the
necessary resources to send it to the controller without failing: TX
context and controller buffer.

I.e. when `bt_conn_process_tx` is called, that's when a TX context is
try-allocated and the contents of `buf->userdata` is moved into it.
The buffer is now ready to be sent to the lower layer.

`bt_conn_process_tx` will return -EWOULDBLOCK if it's not able to acquire a
TX context, this PR modifies `bt_conn_prepare_events` to respond to this by
also waiting on the TX context pool.

Unfortunately, this increases the required userdata size for any buffers
handed to `bt_conn_send_cb`. This will be fixed in a later commit.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Seppo Takalo 441d970417 net: lwm2m: Bypass send_queue when sending empty Ack
In case we want to immediately send empty Ack to server,
we should bypass all send queues.

This is required when we try to send Ack from callbacks
that happen from socket-loop context. On those cases
the Ack would have not been send because the callback
might be blocking the socket-loop while processing
a request (like write callbacks).

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-12 12:50:46 -04:00
Martí Bolívar b93fe6ad2d shell: device_service: print DT metadata
Example output on qemu_cortex_m3:

  devices:
  - uart@4000e000 (READY)
    DT node labels: uart2
  - uart@4000d000 (READY)
    DT node labels: uart1
  - uart@4000c000 (READY)
    DT node labels: uart0
  - gpio@40026000 (READY)
    DT node labels: gpio6
  - gpio@40025000 (READY)
    DT node labels: gpio5
  - gpio@40024000 (READY)
    DT node labels: gpio4
  - gpio@40007000 (READY)
    DT node labels: gpio3
  - gpio@40006000 (READY)
    DT node labels: gpio2
  - gpio@40005000 (READY)
    DT node labels: gpio1
  - gpio@40004000 (READY)
    DT node labels: gpio0

Signed-off-by: Martí Bolívar <mbolivar@amperecomputing.com>
2024-06-12 18:49:54 +02:00
Yong Cong Sin 131e6bf494 logging: allow OOT backend to enable LOG_BACKEND_FORMAT_TIMESTAMP
The `LOG_BACKEND_FORMAT_TIMESTAMP` Kconfig currently depends on
a list of hardcoded backends.

Let's modify it to depend on an intermediary Kconfig
`LOG_BACKEND_SUPPORTS_FORMAT_TIMESTAMP` instead, which can be
selected by a OOT log backend.

Updated all exisitng supported backends to select this new
Kconfig.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-12 12:49:32 -04:00
Roman Studenikin fdd81f87c2 testsuite: coverage: Add CONFIG_ZTEST_COVERAGE_RESET_BEFORE_TESTS
Add an option to reset gcov counters before running tests.
This ensures that only code lines triggered by test itself are counted in
the coverage report and all the board initialization code and pre-test
bootstrap is not counted. This is useful when, for example, you are
testing code that is also executed during bootup

Test Plan:
west build -p always -b qemu_x86_64 tests/ztest/base/ -- \
-DCONFIG_COVERAGE=y -DCONFIG_COVERAGE_GCOV=y -DCONFIG_COVERAGE_DUMP=y \
-DCONFIG_ZTEST_COVERAGE_RESET_BEFORE_TESTS=y
ninja -Cbuild run | tee log.log

Signed-off-by: Roman Studenikin <srv@meta.com>
2024-06-12 14:32:04 +03:00
Roman Studenikin 179585e54b testsuite: coveerage: support counters reset
Ability to reset gcov counters allows better isolation of tests
coverage. Specifically it allows to:
1. Not include counters for any code that was executed prior running the
   test, which includes all the code executed during the board boot.
2. Run multiple tests without firmware reload by resetting counters
   between each.

Signed-off-by: Roman Studenikin <srv@meta.com>
2024-06-12 14:32:04 +03:00
Johann Fischer ed8c99977f usb: device: allow uneven SN to be obtained from HWINFO
If the length of the string literal reserved for the serial number
descriptor is odd, the string is not used because its length is always
even and therefore one character longer. Fix this by using the shortest
length for the copy.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-06-12 14:31:11 +03:00
frei tycho 5d1be67e83 shell: change controlling expressions in while to Boolean
Use `do { ... } while (false)` instead of `do { ... } while (0)`.

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-12 14:22:36 +03:00
Johan Hedberg bf363d7c3e Bluetooth: Host: Avoid processing "no change" encryption changes
If the new encryption state is the same as the old one, there's no point in
doing additional processing or callbacks. Simply log a warning and ignore
the HCI event in such a case.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2024-06-11 19:45:09 -04:00
Johan Hedberg af750cd5a6 Bluetooth: Use device tree to indicate vendor exension support
Introduce a new bt-hci-vs-ext device tree boolean property to indicate
device tree support.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
2024-06-11 19:42:49 -04:00
Johan Hedberg 589b92baaf Bluetooth: Kconfig: Remove BT_NO_DRIVER
There are no actual users in the main tree anymore, so just remove this
option.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
2024-06-11 19:42:49 -04:00
Johan Hedberg 97c3a1e4be Bluetooth: drivers: hci: Get rid of Kconfig choice
The drivers should be independent after the move to the new HCI driver
API. Having them as a choice also has unexpected consequences with some
drivers being unexpectedly enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
2024-06-11 19:42:49 -04:00
Johan Hedberg f8befbd67a Bluetooth: host: hci_raw: Use existing H4 defines from hci_types.h
Use existing defines instead of redefining our own.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
2024-06-11 19:42:49 -04:00
Johan Hedberg 44e0f5fee3 Bluetooth: controller: Update to new HCI driver API
Update the native controller to the new HCI driver API. The devicetree
node is placed under existing `radio` nodes, which seemed like the most
intuitive option.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
2024-06-11 19:42:49 -04:00
Johan Hedberg dcff0be792 Bluetooth: host: Add support for new-style HCI drivers
Add support for HCI drivers which use the newly defined HCI driver API.
Since Zephyr (currently) only supports a single HCI driver instance,
boards are expected to indicate the instance using a new devicetree
chosen property `zephyr,bt_hci`.

In order to maintain compatibility with not-yet-converted drivers the
code has been placed behind `#if DT_HAS_CHOSEN(zephyr_bt_hci)`
conditionals.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
2024-06-11 19:42:49 -04:00
frei tycho 382670690c net: change controlling expressions in while to Boolean
Use `do { ... } while (false)` instead of `do { ... } while (0)`.

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-11 20:03:16 +03:00
frei tycho ac8620c791 tracing: change controlling expressions in while to Boolean
Use `do { ... } while (false)` instead of `do { ... } while (0)`.

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-11 20:02:40 +03:00
Rubin Gerritsen 9cf6839b18 Bluetooth: Host: Allow conn create timeout longer than RPA timeout
https://github.com/zephyrproject-rtos/zephyr/pull/72674 fixed
a bug where this configuration did not work.

Now that this configuration is tested, we should mark it
as supported.

The timeout check that was present in the code before
was useless and was not working because the check was
run before a default timeout of 0 was converted to a timeout.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-11 16:17:46 +02:00
Troels Nilsson bed717e2a5 Bluetooth: Controller: Refactor of ull_adv_sync_pdu_set_clear()
ull_adv_sync_pdu_set_clear does pretty much everything, causing
it to be very complex and awkward to use. In addition, it only handles
a single PDU, meaning callers have to handle the chain.
It has been replaced with simpler, more complete functions for handling
the relevant operations

Fixed issues include:

- Fragmentation of adv data over HCI is now decoupled from PDU
  fragmentation, fixing HCI/DDI/BI-13-C, LL/DDI/ADV/BV-26-C and
  LL/DDI/ADV/BV-55-C
- Adding BigInfo now preserves the PDU chain
- Enabling periodic advertising with ADI on would sometimes fail
  due to insufficient space in a single PDU to add ADI

Signed-off-by: Troels Nilsson <trnn@demant.com>
2024-06-11 16:38:05 +03:00
Alberto Escolar Piedras e34f29f9ea subsys/portability/CMSIS: Do not redefine TRUE & FALSE
These macros tend to be defined by too many headers.
Let's guard these definition with ifdefs to avoid
redefining them to practically the same.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-06-11 16:29:22 +03:00
Lucas Romero cad56e8005 lorawan: services: frag decoder: add lowmem implementation
that utilizes the fact that the ldpc recovery matrix is triangular and only
stores the half with non-zero values.

This implementation is hopefully going to make forward error correction
usable on lower memory devices.

Signed-off-by: Lucas Romero <luqasn@gmail.com>
2024-06-11 16:09:23 +03:00
Lucas Romero 69c5ef9665 lorawan: services: frag transport: prepare for pluggable decoder
by wrapping decoder implementation specific bits in #ifdefs

Signed-off-by: Lucas Romero <luqasn@gmail.com>
2024-06-11 16:09:23 +03:00
Lucas Romero ff906974b8 lorawan: services: frag transport: refactor status
to no longer be a long-lived status variable because we already map it into
is_active and this reduces the number of states the transport can be in.

It also helps us prepare for being able to plug in more decoders by
removing implementation specific bits from the general transport interface.

Signed-off-by: Lucas Romero <luqasn@gmail.com>
2024-06-11 16:09:23 +03:00
Rubin Gerritsen a35d5e7851 ztest: Add macros for comparing strings
These macros allows us to compare strings in a simpler way.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-11 11:39:36 +01:00
Bjarki Arge Andreasen 1f7d0b6cb0 modem: add modem_pipelink module
Add modem pipelink module which exposes modem pipes globally.
The pipelink module implements a callback to inform when a
pipe becomes available to use by whichever modem is attached
to it. This could be a shell, or a network interface.

The module aims to allow modem drivers to be split into modules,
and allowing applications to implement their own custom logic
without altering the modem drivers.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-06-10 15:12:34 -05:00
Jukka Rissanen 7bb4013d8e net: tracing: Add socket tracing support
If network socket tracing is enabled, then the system will track
various socket API calls for usage.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-10 15:03:20 -05:00
Fin Maaß 54cb89b8d7 tracing: fix k_realloc trace functions
fix wrong amount of arguments for
k_realloc trace functions.

fixes #73996

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-06-10 14:54:49 -05:00
Daniel Nejezchleb d6ed91795d net: tcp: Fix context leak during connect
Replaced tcp_out() with tcp_out_ext() when sending
SYN during tcp connect, so we can intercept error value,
beacuse in such case the packet would not be sent at all
and the stack would not trigger any mechanism to flush
this context so it ends up leaking. These scenarios can
arise when the underlaying interface is not properly
configured or is disconnected. The conn is marked to be
closed and is closed before exiting tcp_in().
Since we can now identify this case we can also exit
early in the net_tcp_connect() function and not wait
for any timeout.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2024-06-10 16:56:39 +03:00
Piotr Koziar e66b382639 ipc: fix return code of icbmsg backend send operation.
This commit fixes the issue where a serialization
error was reported after properly sending a data with 'icbmsg' backend.

The icbmsg send function's return code is set to
the sent data's len as in other backends.
The related docs were fixed and updated.

Signed-off-by: Piotr Koziar <piotr.koziar@nordicsemi.no>
2024-06-10 15:00:01 +03:00
Georges Oates_Larsen 7fa6b53ac3 net: shell: Add IPv4 and IPv6 connectivity events
Add descriptions for recently introduced IPv4 and IPv6
connectivity events to the net event monitor.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Georges Oates_Larsen 85c4cb9265 net: conn_mgr: Add IPv4 and IPv6 tracking
conn_mgr now fires:

- NET_EVENT_L4_IPV4_CONNECTED
- NET_EVENT_L4_IPV4_DISCONNECTED
- NET_EVENT_L4_IPV6_CONNECTED
- NET_EVENT_L4_IPV6_DISCONNECTED

These events track whether there are any ready ifaces offering
specifically IPv4 or specifically IPv6 connectivity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Georges Oates_Larsen 32ae816d0b net: conn_mgr: Simplify blame handling
Don't track up/down blame separately.
Instead, track a single last-blame iface.

Don't track blame iface inside set_ready.
Instead, track directly inside handle_update.

These two changes will simplify the addition
of blame for IPv4- and IPv6-specific events.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Georges Oates_Larsen 875755fbb2 net: conn_mgr: Track ready count ephemerally
Instead of incrementing and decrementing global counter,
just recompute the ready-count from scratch every time
conn_mgr_mon_handle_update is called.

This will simplify the introduction of additional ready count types.

This should have no externally observable impact on the behavior of
conn_mgr.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Robert Lubos 3501d6e6d4 net: shell: ipv4: Add information about ACD
Print information in IPv4 shell whether address conflict detection is
enabled or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos c0161c8052 net: l2: ethernet: arp: Simplify ACD case
In case of ACD Probe/Announcement, all we need is to generate ARP
packet, we don't really want any cache entries to be created or searched
for. There was a bug, that a cache entry was created for the
Announcement sent, resulting in skipped ARP packet generation and
malformed packet being sent by the ACD module.

Therefore, simplify all this, by simply returning early in case of
conflict detection packets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos cc53826cc9 net: ipv4: autoconf: Integrate with the ACD module
The autoconf module can now reuse generic address conflict detection,
which was added for all address types.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos 80339ac4ee net: dhcpv4: Add support for conflict detection
In case a conflict was detected on a DHCP-assigned address, send a
Decline message to the server and start over.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos 7352aaa841 net: config: Add support for IPv4 ACD
In case IPv4 conflict detection is enabled, monitor network events to
determine whether IPv4 address is ready to use or not, so that the
library returns only after the network setup is fully complete.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos c281db0f7e net: conn_mgr: Add support for ACD events
Connection manager needs to monitor ACD events as well to determine
whether a preferred IPv4 address is available.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos a89dd1a6f6 net: shell: Add ACD events to the event monitor
Include new ACD events in the shell event monitor.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos 0a95423421 net: ipv4: Implement IPv4 address conflict detection
Add support for IPv4 conflict detection, as specified in RFC 5227.
The new feature is optional and disabled by default.

Address conflict detection was implemented as a part of the IPv4
autoconf feature can be generalized to be available for all address
types.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Rodrigo Peixoto 453ab8a9a3 zbus: vded: msg_sub: Improve channel ref copy
The VDED was adding the channel information per clone. But it could be
done in the original buffer. This commit fixes that by adding the
channel information to the original buffer and not for each clone. As a
result, we have a more straightforward VDED execution with fewer copies.

Signed-off-by: Rodrigo Peixoto <rodrigopex@gmail.com>
2024-06-09 09:07:21 -05:00
Flavio Ceolin 73b755d817 pm: Add a symbol for device power state constraints
Add a symbol to enable device power state constraints this
saves resources when this feature is not needed.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-06-07 19:06:23 -04:00
Flavio Ceolin 02a14d75fc pm: Declare pm state constraints for a device
Declare power state constraints for a device in devicetree.
It allows a map between device instances and power states that disable
their power. This information is used by a new API
(pm_policy_device_power_lock_put/get) that automically set/release
pm state constraints.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-06-07 19:06:23 -04:00
Daniel DeGrasse 7981ea0056 fs: fat_fs: make IOCTL call to de-initialize disk in fatfs_unmount()
Make call to de-initialize disk in fatfs_unmount(). This will permit the
disk to be reinitialized when it is mounted with fatfs_mount().

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-06-07 18:16:01 +01:00
Daniel DeGrasse d18cbb60b2 drivers: disk: add DISK_IOCTL_CTRL_DEINIT command to supported IOCTLs
Add DISK_IOCTL_CTRL_DEINIT ioctl command to disk subsystem. When
disk_access_ioctl() is called with this command, the disk will be
de-initialized. After this IOCTL completes, the disk can safely be
reinitialized.

Fixes #60628

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-06-07 18:16:01 +01:00
Daniel DeGrasse fb2d5c338b drivers: disk: add DISK_IOCTL_CTRL_INIT macro to initialize a disk
Add DISK_IOCTL_CTRL_INIT IOCTL to initialize a disk. This IOCTL is
intended to replace disk_access_init() for new applications, but
disk_access_init() is kept for legacy compatibility. The INIT IOCTL is
added to better match the path that will be used for disk
de-initialization. Like the disk_access_init() calls,
DISK_IOCTL_CTRL_INIT calls are reference counted

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-06-07 18:16:01 +01:00
Daniel DeGrasse 3386a43a51 disk_access: reference count initialization calls for disks
Reference count initialization calls for disks. This changes the
behavior of the disk_access_init() function, such that disks will no
longer be initialized again if the first disk access init call
succeeds.

Disk access is reference counted in preparation for supporting disk
de-initialization, where a balanced number of disk de-initialization
calls with disk initialization calls will de-initialize the disk.

Also, remove code in disk drivers that was already checking against
duplicate disk_access_init() calls.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-06-07 18:16:01 +01:00
Krzysztof Chruściński 8f3989412f testsuite: ztest: ztress: Add missing static keywords
Add static to local timers definition.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-06-07 18:08:22 +01:00
Luca Burelli 1a2f6ae381 llext: refact: move ELF loading and linking to separate files
This commit moves ELF loading and linking code to separate files. This
is done to make the code more manageable and to make it easier to add
new features in the future.

No functional changes are introduced by this commit, except for a few
static functions now made public to allow this file split to occur.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-07 18:07:53 +01:00
Luca Burelli 9c5412f79e llext: refact: move memory code to llext_mem.c
Move all memory management code to a separate file, llext_mem.c, to
allow for better separation of concerns and to make the code more
readable.

No functional changes are introduced by this commit.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-07 18:07:53 +01:00
Luca Burelli 35ef089cb1 llext: move basic ELF checks to llext_load_elf_data()
This patch moves the initial checks performed on the ELF file, that were
split between llext_load() and do_llext_load(), to the newly defined
llext_load_elf_data() function.

This way:

- only one function deals with ELF internal data checks;
- do_llext_load() is reduced to a list of tasks;
- llext_load() only focuses on the extension management.

One totally misplaced line initializing the number of symbols has been
moved to llext_count_export_syms().

No functional change except that the `struct llext` allocation may be
performed unnecessarily if the ELF file is not valid.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-07 18:07:53 +01:00
Luca Burelli cefeae0048 llext: add llext heap management functions
Add llext_alloc(), llext_aligned_alloc() and llext_free() wrapper
functions to manage memory allocation and deallocation from the llext
heap. Also add a helper to free all memory regions allocated by an
extension.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-07 18:07:53 +01:00
Alberto Escolar Piedras 510e1ba6af Bluetooth: Controller: Treat nrf54l15bsim like a real platform
Use the compatible kconfig option so that for the simulated
nRF54L15 we build the same code as for the real platform.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Alberto Escolar Piedras a3218b0de5 Bluetooth: Controller: Fix BT_CTLR_DATA_LEN_UPDATE_SUPPORT selection
For the Nordic HW, the BT_CTLR_DATA_LEN_UPDATE_SUPPORT
does not require CCM HW enabled, hence support Data Length
Update if Encryption Support is disabled.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Alberto Escolar Piedras 35773882c2 Bluetooth: Controller: Use HAL to modify renamed registers in nRF54
In some nRF54 devices, DATAWHITEIV was renamed to
DATAWHITE,
and the CRCCNF SKIADDR field was renamed OFFSET.
The nrf HAL hid this change internally,
so let's use it so we don't need to ifdef these
in the Bluetooth Controller HAL code.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada f59c3fafe8 Bluetooth: Controller: Preliminary support for nRF54L15 SoC
Add preliminary support for nRF54L15 SoC. This commit does
not support Controller Random Number Generation and
Controller Cryptography (AES-128 encryption) commands, nor
does it support encrypted connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada 0bbbef3a8c Bluetooth: Controller: Use NRF_RTC and RADIO_SHORTS_TRX_END_DISABLE_Msk
Use NRF_RTC and NRF_RADIO_SHORTS_TRX_END_DISABLE_Msk instead
to prepare towards using configurable use of RTC and Radio
hardware defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada d6f2bc9669 Bluetooth: Controller: Add explicit LLCP error code check
Add unit tests to cover explicit LLCP error code check and
cover the same in the Controller implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada 78466c8f52 Bluetooth: Controller: Use BT_HCI_ERR_UNSPECIFIED as needed
A Host shall consider any error code that it does not
explicitly understand equivalent to the error code
Unspecified Error (0x1F).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada fe205a598e Bluetooth: Controller: Refactor BT_CTLR_LE_ENC implementation
Refactor reused function in BT_CTLR_LE_ENC feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada 2d49080cb8 Bluetooth: Controller: Fix BT_CTLR_LE_ENC conditional compilation
Fix BT_CTLR_LE_ENC conditional compilation when feature is
disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada a66baa1101 Bluetooth: Controller: Introduce BT_CTLR_CRYPTO_SUPPORT
Introduce BT_CTLR_CRYPTO_SUPPORT so that preliminary port to
support nRF54L15 SoC can be upstreamed without encryption
support.

ENTROPY_GENERATOR now selected when BT_CTLR_CRYPTO enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Vinayak Kariappa Chettimada 073e627e3b Bluetooth: Controller: Fix ENTROPY_NRF5_RNG conditional compile
Fix ENTROPY_NRF5_RNG conditional compile when not enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-06-07 18:07:48 +01:00
Fin Maaß e1246ccb65 mgmt: hawkbit: some Kconfig improvements
some hawkbit Kconfig improvements.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-06-07 18:06:45 +01:00
Siddharth Chandrasekaran 45085ba647 mgmt/osdp: cp: disallow unexpected SC responses
When CP has a secure channel active, it should never receive a
REPLY_CCRYPT or REPLY_RMAC_I. Since these responses change the SC state,
let's also make sure that they are accepted only when they are
expected: in response to commands CMD_CHLNG and CMD_SCRYPT respectively.

Reported-by: Eran Jacob <eran.jacob@otorio.com>
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2024-06-07 16:47:55 +03:00
Sean Madigan 0b327db097 Bluetooth: Add support for Path Loss Monitoring feature
This commit adds host support for the Path Loss Monitoring
feature see Bluetooth Core specification, Version 5.4,
Vol 6, Part B, Section 4.6.32.

Limited logic is required, just adding a wrapper around the
HCI command and callback for HCI event.

Add new zone - BT_CONN_LE_PATH_LOSS_ZONE_UNAVAILABLE, to
convert 0xFF path loss to a useful zone.

Add new Kconfigs and functionality to the bt shell.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2024-06-07 15:04:11 +02:00
Emil Gydesen 5c9032019c Bluetooth: CAP: Fix linker issue in cap_stream.c for x86
The existing code in the cap_stream.c that handled the
check before calling CAP initiator unicast functions
seemingly did not work for x86 targets such as native_sim
or native_posix.

Modified the check so that IS_ENABLED is used directly.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-07 13:01:13 +02:00
Pisit Sawangvonganan aca97a0bef fs: fcb: refactor fcb_get_len() for improved readability
Introduced temporary variables `buf0_xor` and `buf1_xor` to store
XOR results and added an explicit cast to `uint16_t` for
the `*len` variable.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-07 09:53:56 +02:00
Pisit Sawangvonganan 06177833d8 fs: fcb: correct FCB_MAX_LEN boundary condition
Correct the boundary condition in `fcb_put_len` function to
properly include `FCB_MAX_LEN` and change the #define to address
the potential flaw where `CHAR_MAX` might be treated as unsigned by
the compiler flag `-funsigned-char`, which would yield `FCB_MAX_LEN`
to 0x7fff instead of 0x3fff.

Fixes #73868

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-07 09:53:56 +02:00
Tom Burdick 87fc25afc1 sensing: Fix build warning on invalid array index
The assert was verifying that the current sensor address was greater
or equal than the start of the iterable section - 1 which isn't quite
right as the start is inclusive.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-06-07 09:52:09 +02:00
Jordan Yates dc5f27395f testsuite: add dependency to COVERAGE_GCOV_HEAP_SIZE
Add missing dependency on `COVERAGE_GCOV` to prevent the symbol from
appearing in every application.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-06 20:07:20 -04:00
Tom Burdick d95caa51a4 sys: Add a lockfree mpsc and spsc queues
Moves the rtio_ prefixed lockfree queues to sys alongside existing
mpsc/spsc pbuf, ringbuf, and similar queue-like data structures.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-06-06 00:42:29 -07:00
Balaji Srinivasan 16fc8f5295 task_wdt: Feed hardware watchdog only when its started
Previously the schedule_next_timeout() function was feeding the hardware
watchdog irrespective of whether or not it was started. This is now
fixed.

Signed-off-by: Balaji Srinivasan <balaji.srinivasan@nordicsemi.no>
2024-06-06 00:40:53 -07:00
Anas Nashif 584a99f6ab tracing: add missing calls for k_wakeup/k_thread_user_mode_enter
Add missing hooks for k_wakeup/k_thread_user_mode_enter to CTF backend.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-06-05 17:38:22 -05:00
Alberto Escolar Piedras c9491a818f Bluetooth: Controller: Correct power levels for bsim targets
The simulated targets support the same power levels as the
real targets. Let's correct the kconfig dependencies
accordingly.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-06-05 17:36:57 -05:00
Seppo Takalo d3081e2f30 net: lwm2m: On write, use server selected block size
When we receive CoAP packets, it is in input buffer
that is size of NET_IPV6_MTU.
So in reality, we can handle bigger Block-Wise writes
than CONFIG_LWM2M_COAP_BLOCK_SIZE.

So if parsing of CoAP packet has passed, continue
with the same block-size instead of going to default.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-05 14:43:14 +01:00
Yong Cong Sin 3cb2c04fc1 subsys/debug: relocate symtab Kconfig
Move the symtab Kcofig into the symtab folder.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 22:36:51 -04:00
Yong Cong Sin 9d9576b442 subsys/debug: relocate gdbstub stuff into its folder
Move the gdbstub files into the gdbstub folder, and relocated
its Kconfig as well.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 22:36:51 -04:00
Flavio Ceolin 1c2e988021 pm: device: De-couple device pm from system pm
PM_DEVICE is not attached to system managed device power management.
It is a very common use case targets with device runtime power
management that don't want system device power management enabled.

We introduce a new symbol (PM_DEVICE_SYSTEM_MANAGED) to explicit
control whether or not system device power management should be
globally enabled.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-06-04 19:13:53 -04:00
Flavio Ceolin c65be0cfb9 pm: Exclude device pm path when it is not needed
Remove device pm path when there is no is no power state in DT with
device pm enabled. This basically does the same thing that was done
by PM_DEVICE_RUNTIME_EXCLUSIVE.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-06-04 19:13:53 -04:00
Flavio Ceolin 2f99ff51cc pm: Disable device pm per power state
Make it possible to disble device power management individually per
power state.  This allows targets tuning which states should
(and which should not) trigger device power management.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-06-04 19:13:53 -04:00