Commit graph

19212 commits

Author SHA1 Message Date
Aleksandar Stanoev
db9bcdc05e bluetooth: host: Add support for LE Connection Subrating
Adds support for LE Connection Subrating as defined in Core 5.4
Vol 6, Part B, Section 5.1.19.
As this is primarily a controller feature, the host support is mostly
a wrapper around the relevant HCI commands.

Note that subrating provides a new method to update the connection's
peripheral latency and supervision timeout alongside subrating parameters.

Signed-off-by: Aleksandar Stanoev <aleksandar.stanoev@nordicsemi.no>
2024-08-05 10:16:27 +02:00
Aleksandar Stanoev
c417bd224e bluetooth: Add Kconfig for LE Connection Subrating
Add separate Kconfig to be used by the host LE Subrating implementation.

Signed-off-by: Aleksandar Stanoev <aleksandar.stanoev@nordicsemi.no>
2024-08-05 10:16:27 +02:00
Tom Burdick
71bf36387c rtio: Enable submit/consume semaphores by default
The default behavior for thread pending of completions should use
semaphores rather than yield/wait looping when multithreading is
available.

Disable by default only when multithreading isn't available.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-08-05 10:16:12 +02:00
Robert Lubos
5f43388308 net: coap: Parse more flag in coap_get_block2_option()
Parse the more flag in coap_get_block2_option(), so that the function
can be used not only with requests but also with replies (where the more
flag should not be ignored).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-08-02 22:12:47 -05:00
Robert Lubos
3902a990e5 net: coap: Fix underlying type for block number
The block number in block1/2 options can be encoded on up to 20 bits
according to RFC 7959, therefore the underlying type used in helper
functions to retrieve the block number should be large enough to hold
the result. Therefore, replace the container for block number with
uint32_t instead of uint8_t.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-08-02 22:12:47 -05:00
Thales Bacelar
d6429431d6 logging: Trigger logging thread when we start to drop messages
Wake up logging thread when we start to drop messages.

Signed-off-by: Thales Bacelar <thalesbacelar@duck.com>
2024-08-02 18:45:59 -05:00
Armin Brauns
d7da085948 bluetooth: make monitor timestamps roll over less
With e.g. a 216MHz core clock, the 32-bit cycle counter overflows after
just 20 seconds. The 32-bit monitor timestamp (100us resolution) overflows
after around five days regardless of what we do, but we should try our best
to reach that.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-08-02 13:41:32 +02:00
Mark Holden
e6b683d310 coredump: Guard new kconfig for only supported arch
Add new config, ARCH_SUPPORTS_COREDUMP_THREADS, and
only enable it for ARM CORTEX M where the gdb server
can support it.

Signed-off-by: Mark Holden <mholden@meta.com>
2024-08-02 03:32:09 -04:00
Mark Holden
c35f6d1cac coredump: Add test for threads core dump config
Add z_test which uses new configs to capture multiple
threads in a core dump and with all of the context
necessary to debug the threads.

Signed-off-by: Mark Holden <mholden@meta.com>
2024-08-02 03:32:09 -04:00
Mark Holden
45684a598d coredump: Add config for capturing thread data in core dump
Update core dump file format to support a new section which contains
metadata about threads necessary for debugging.

Define configs to capture that metadata and include it in the dumps
when enabled.

Update documentation to reflect the changes.

Signed-off-by: Mark Holden <mholden@meta.com>
2024-08-02 03:32:09 -04:00
Fabio Baltieri
f3a6454f93 pm: refactor pm_device_driver_init
Refactor pm_device_driver_init code to keep the normal execution path
inline and the early exit branches at a single indentation, this is
commonly done throughout the code base.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-08-02 03:31:17 -04:00
Anders T. Akre
26cd98e483 modem: ubx: fix incoming byte processing
`ret` holds the amount of bytes received from the modem. However during
processing of the bytes its value is overwritten by the return value of
`modem_ubx_process_received_byte`, in practice discarding all but the
first byte read.

To prevent this, store the length in a separate variable.

Signed-off-by: Anders T. Akre <anders@akre.io>
2024-08-02 03:29:18 -04:00
Jonathan Rico
1c6510312d Bluetooth: L2CAP: Set NULL callback for PDUs
It was not being set, and thus if the user_data contained garbage from
before, then conn.c would attempt to call that garbage.

Static channels don't have this issue, as every "SDU" fits into one PDU.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Co-authored-by: Huajiang Zheng <nxf88597@lsv051208.swis.nl-cdc01.nxp.com>
2024-08-01 16:49:37 +01:00
Jonathan Rico
8d7c1bc7bc Bluetooth: remove forgotten TODO
It's already done.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-01 16:49:37 +01:00
Jonathan Rico
ea9449979b Bluetooth: L2CAP: Mark user_data as owned by the stack
Storing stuff in user_data? That's a paddlin'

We have been debugging issue after issue because ownership of this
"user" data is not clearly defined. Now it is. L2CAP owns the user_data
field entirely, as soon as `send()` is called.

Also add a warning and retval using CHECKIF.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-01 16:49:37 +01:00
Jonathan Rico
5c6cd27723 Bluetooth: allow compiling host with CONFIG_NO_RUNTIME_CHECKS
Werror fails the build on that function.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-01 16:49:37 +01:00
Jonathan Rico
d02a13d726 Bluetooth: host: add more info to conn.c log
Print user_data and callback pointers.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-01 16:49:37 +01:00
Fabio Baltieri
e466efaf74 libc, console: declare __stdout_hook_install in libc-hooks.h
Declare __stdout_hook_install in libc-hooks.h and use it in the console
drivers rather than redeclare it every time.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-08-01 16:49:08 +01:00
Armin Brauns
cd7a6a4d55 coredump: use memmove instead of memcpy
With CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_LINKER_RAM, buffer_output() is
called on the entire RAM memory area. This includes the stack for the
coredump thread, which is where tmp_buf is stored. Eventually, it will copy
(parts of) tmp_buf into tmp_buf itself, which invokes Undefined Behaviour
in memcpy():

> The memory areas must not overlap.  Use memmove(3) if the memory areas do
> overlap.
- memcpy(3)

With picolibc, this is detected in __memcpy_chk() and causes a fault in
__chk_fail().

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-08-01 16:43:41 +02:00
Armin Brauns
12435442d2 coredump: significantly increase efficiency for small write block sizes
With FLASH_WRITE_SIZE==1, this would do a separate flash write for every
single byte.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-08-01 16:40:26 +02:00
Jakub Zymelka
bb5b98f16c ipc: icmsg: Align to NO MULTITHREADING
Adapting icmsg to work without the MULTITHREADING functionality.
Dependencies for kernel work_queue, mutexes and other functions
related to running multithreaded applications have been 'ifdefed'.

Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
2024-08-01 13:31:53 +02:00
Jukka Rissanen
20a69f6dbf net: wifi: Add iterable_sections header file
This is related to change in commit dacb3dbfeb
("iterable_sections: move to specific header")

Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-08-01 12:36:00 +02:00
Seppo Takalo
e86bdf952d net: lwm2m: Always emit DISCONNECTED event
When LwM2M engine is requested to stop,
emit the disconnected event unconditionally.
There is really no reason to skip the event
on network error, or if we have never been registered.

Fixes #76422

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-01 12:35:53 +02:00
Fabio Baltieri
60df679366 debug: thread_analyzer: fix incorrect k_thread_foreach_unlocked argument
Fix the second k_thread_foreach_unlocked argument, it's supposed to be
an instance of ta_cb_user_data as that's what's it casted back to in
thread_analyze_cb. Current code results in an exception and crash for
single core applications.

This is a regression introduced in 1b6e0f6479.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-08-01 12:35:45 +02:00
Daniel Leung
d2b072078d debug: thread_analyzer: fix casting pointer to int warning
In thread_analyzer_auto(), it casts one function argument
directly into unsigned int. However, on 64-bit platforms,
the compiler complains about casting from pointer of
different size (-Wpointer-to-int-cast). So cast it first to
uintptr_t before casting it into unsigned int.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-08-01 12:35:34 +02:00
Kamil Piszczek
f9a5699bd8 Bluetooth: DIS: integrate app version into FW revision characteristic
Integrated the application version feature of the build system with
the default configuration of the Bluetooth DIS module and its Firmware
Revision characteristic.

The firmware revision string now defaults to APP_VERSION_TWEAK_STRING
if the application version feature is used in a project. This specific
version format is used to unify version formatting with other parts of
Zephyr like the MCUboot module and its versioning Kconfig:
CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2024-08-01 09:13:39 +01:00
Matt Rodgers
47fbb8512f net: coap_client: allow application to add block2 option to requests
Allow an application to add a Block2 option to an initial request for a
resource. For any subsequent requests as part of a blockwise transfer,
drop the application-added Block2 option since the coap_client must
append a Block2 option with updated NUM and SZX fields based on the
server response.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-08-01 09:13:32 +01:00
Henrik Brix Andersen
9af6ae50f4 usb: device_next: add usbd_device_set_bcd_device()
Add usbd_device_set_bcd_device() for setting the bcdDevice device
descriptor value.

The default bcdDevice is set to the version of Zephyr being used, which may
or may not be what a downstream USB device wants it to be.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-08-01 09:11:44 +01:00
Henrik Brix Andersen
196c9635d8 usb: device_next: rename usbd_device_set_bcd()
Rename usbd_device_set_bcd() to usbd_device_set_bcd_usb() to make room for
other BCD encoded values being set.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-08-01 09:11:44 +01:00
Fabio Baltieri
600217c52f usb: device_next: hid: move few pointer to a config struct
Some of the fields currently in hid_device_data are constant.

Move them to a const config struct to save some RAM and drop the rest of
the data static initializers to runtime to save some flash as well.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-08-01 09:11:17 +01:00
Gerard Marull-Paretas
5a095d42a7 bluetooth: controller: nordic: provide dummy DEBUG_SETUP
So that clients do not have to understand in which situation it is not
defined.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2024-08-01 08:56:56 +01:00
Gerard Marull-Paretas
baad622063 bluetooth: controller: nordic: simplify board guarding
Since HWMv1, we also have CONFIG_$BOARD Kconfig symbols defined, ie, no
SoC/core/variant needed.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2024-08-01 08:56:56 +01:00
Pisit Sawangvonganan
6211de87c0 net: mqtt: improve decoder buffer handling
Improve buffer handling logic to use local variables extensively.

This change reduces the number of pointer dereferences, which leads
to more efficient runtime and helps reduce the code size.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-31 13:08:28 +02:00
Pisit Sawangvonganan
45282a41c1 net: mqtt: improve encoder buffer handling
Improve buffer handling logic to use local variables extensively.

This change reduces the number of pointer dereferences, which leads
to more efficient runtime and helps reduce the code size.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-31 13:08:28 +02:00
Robert Lubos
349bf81e00 net: tcp: Keep track of recv window size change since last ACK
Windows TCP stack has a peculiar behavior - when running iperf, it will
fill out the RX window almost entirely, but will not set PSH flag on
packets. In result, our stack would delay the ACK and thus window
update, affecting throughputs heavily.

In order to avoid that, keep track of the most recent window size
reported to the peer, and reduce it when receiving new data. In case the
RX window, as seen from the peer perspective, drops below certain
threshold, and the real RX window is currently empty, send an ACK
immediately when updating window, so that peer can continue
with sending data.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-31 12:56:52 +02:00
Rubin Gerritsen
a4e43d013c Bluetooth: Samples: Use string printing functions for error codes
When developing Bluetooth applications, you typically run into some errors.
If you are an experienced Bluetooth developer, you would typically know
how to translate the error codes into string representations.
Others might not.

This commit to adds string printing of error codes for all
samples to make them more user-friendly.

Several formatting alternatives were considered. The chosen alternative
balances code readability and FLASH size (with and without string
printing).

Example output from the peripheral_hids sample when the
peer rejects pairing:

```
Bluetooth initialized
Bluetooth authentication callbacks registered.
Advertising successfully started
Connected 5E:67:02:D3:1C:DB (random)
Security failed: 5E:67:02:D3:1C:DB (random) \
level 1 err 6 BT_SECURITY_ERR_PAIR_NOT_ALLOWED
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason 0x13 BT_HCI_ERR_REMOTE_USER_TERM_CONN
```

Other alternatives that were considered:

- Use of parantheses:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err BT_SECURITY_ERR_PAIR_NOT_ALLOWED(6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
BT_HCI_ERR_REMOTE_USER_TERM_CONN(0x13)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err (6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason (0x13)
```

- Spaces and parantheses:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err BT_SECURITY_ERR_PAIR_NOT_ALLOWED (6)
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason BT_HCI_ERR_REMOTE_USER_TERM_CONN (0x13)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err  (6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason  (0x13)
```

- Parantheses around everything:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err (BT_SECURITY_ERR_PAIR_NOT_ALLOWED(6))
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason (BT_HCI_ERR_REMOTE_USER_TERM_CONN(0x13))
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err ((6))
Disconnected from 5E:67:02:D3:1C:DB (random), reason ((0x13))
```

- Error code first, then string representation:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err 6 (BT_SECURITY_ERR_PAIR_NOT_ALLOWED)
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
0x13 (BT_HCI_ERR_REMOTE_USER_TERM_CONN)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err 6 ()
Disconnected from 5E:67:02:D3:1C:DB (random), reason 0x13 ()
```

- Apostrophes around error printing:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err "BT_SECURITY_ERR_PAIR_NOT_ALLOWED (6)"
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
"BT_HCI_ERR_REMOTE_USER_TERM_CONN (0x13)"
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err " (6)"
Disconnected from 5E:67:02:D3:1C:DB (random), reason " (0x13)"
```

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-31 12:56:11 +02:00
Fabio Baltieri
61129d8fd2 input: longpress, keymap: use an explicit callback name
Use an explicit callback name so that multiple instances of this do not
result in a:

redefinition of '_input_callback__longpress_cb'

error. This used to work when it was using unique generated wrappers,
but now it needs an index in the callback name.

Use it in one of the API tests as well, just in case.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-07-31 12:55:11 +02:00
Fabio Baltieri
716fa268f4 input: add a user_data pointer to the callback
Add a void *user_data pointer to the input callback structure. This is
useful for driver to get back the driver data structure and avoid
defining wrapper functions.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-07-31 12:55:11 +02:00
Vinayak Kariappa Chettimada
8bf604ee10 Bluetooth: Controller: Fix missing BT_CTLR_BROADCAST_ISO_ENC
Fix missing BT_CTLR_BROADCAST_ISO_ENC conditional compile.

Relates to commit 2d49080cb8 ("Bluetooth: Controller: Fix
BT_CTLR_LE_ENC conditional compilation").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-07-31 12:55:04 +02:00
Jukka Rissanen
03885d1cbf net: if: No need to join mcast groups if interface IPv6 is disabled
If IPv6 is not enabled for a given network interface, then there
is no need to try to join IPv6 multicast groups as it will just
cause an error print which is pointless in this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-07-31 12:40:32 +02:00
Konrad Derda
4e7bf281a1 net: ipv6: routing: decide whether to set interface's LL address
While routing between interfaces source Link-Local L2 address is set
for a packet. However, it should not be done for some of the interfaces.

This commit adds helper function to check this condition in runtime.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-31 12:40:16 +02:00
Konrad Derda
0ac5ab4a4e net: ipv6: routing: do not add route to original iface without ND
When packet is routed between interfaces new routing entry is added
to the table. This should not be done for interfaces that do not
support Neighbor Discovery protocol as they are not keep potential
neighbors in the common table.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-31 12:40:16 +02:00
Gerhard Jörges
e55278a87b net: lib: http_server: add static fs resource
adds filesystem as a resource for the http_server which serves static
(gzipped) files from a filesystem to the client.

Signed-off-by: Gerhard Jörges <joerges@metratec.com>
2024-07-31 10:08:16 +02:00
Fabian Pflug
31e91794de net: l2: ieee802154: mgmt: allow beacons without association bit
The Association permit bit shall be set to zero if the coordinator does
not accept association requests.
Not accepting association request ist not a reason to filter the
beacons from this coordinator during network scan. It is still a
network, just one you cannot associate with.

Signed-off-by: Fabian Pflug <fabian.pflug@grandcentrix.net>
2024-07-31 10:08:03 +02:00
Matt Rodgers
44d39e2028 net: coap_client: limit payload size during block transfer to block size
Limit the coap payload size passed up to the application callback to the
block size, when a block transfer is in progress and the current payload
is not the final block.

If the current payload is not part of a block transfer, or is the final
block of a transfer, then the full payload can be passed to the
application to avoid having to make another request over the network for
data that has already been received.

This avoids a problem raised in issue #76089, where a payload longer
than CONFIG_COAP_CLIENT_MESSAGE_SIZE causes the same data to be passed
to the application callback twice (once in the large packet, and once in
the next block which must have an offset that is a multiple of the block
size).

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-07-31 10:07:45 +02:00
Matt Rodgers
93f871e2d1 net: coap_client: handle truncation of received data
Use the MSG_TRUNC flag to check the total length of UDP packets
receieved by the coap_client, and hence check if the receive buffer
contains the whole message, or if it is truncated.

If the message is truncated, then use a blockwise transfer to fetch the
rest of the data.

This is related to issue #76089.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-07-31 10:07:45 +02:00
Pisit Sawangvonganan
16386d7b5f net: shell: use shell_xxx_impl in PR ... PR_WARNING macros
Due to the introduction of `shell_xxx_impl` wrapper functions in
PR #75340, we can minimize caller overhead by eliminating direct
`color` parameter passing.

This is achieved by using `shell_print_impl`, `shell_error_impl`,
`shell_info_impl` and `shell_warn_impl` instead of `shell_fprintf`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-31 10:07:29 +02:00
Pieter De Gendt
ac983f633e net: lib: http: Use Kconfig constants
Replace Kconfig values with UINT32_MAX

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-30 18:31:11 +01:00
Rubin Gerritsen
39a70be4a0 Bluetooth: Only enable data length extensions when needed
We should disable the feature when it is not needed to
save flash and RAM.
There is no point in enabling data length extensions
when the maximum packet size used is always smaller or equal
to 27 bytes. Then data length updates would only use
parameters (octets=27, time=T) where T is some supported value
which would not improve throughput or power consumption.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-30 18:30:22 +01:00
Pieter De Gendt
92019b1dac emul: Support UART device emulation
Add support to the existing UART emulated bus, to have a client device
emulator.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-30 18:28:17 +01:00