Commit graph

21541 commits

Author SHA1 Message Date
Bas van Loon
85f6409043 net: if: Add net_if_ipv4_get_gw as helper function.
Most set functions have a get function as well, add the missing
function to get the set gateway IPv4 address.

Signed-off-by: Bas van Loon <basvanloon@betronic.nl>
2024-07-27 20:51:21 +03:00
Aleksander Wasaznik
e37140b219 Bluetooth: Host: Remove work cancel before submit
Refactor. The deferred work is rescheduled just after it's canceled.
This is hopefully equivalent to just the reschedule, so the cancel can
be removed.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-07-27 20:50:21 +03:00
Pisit Sawangvonganan
d5cd47fbb2 shell: introduce shell_xxx_impl wrapper functions for output macros
Refactor shell output macros to minimize caller overhead by eliminating
direct `color` parameter passing:
- Introduce wrapper functions: `shell_info_impl`, `shell_print_impl`,
  `shell_warn_impl`, `shell_error_impl`.
- Replace `shell_fprintf` in macros with these new wrappers.
- Update `shell_hexdump_line` to use the new wrappers,
  minimizing caller overhead.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-27 20:50:12 +03:00
Andrey Dodonov
0e699eb251 net: lib: dhcpv4: parse multiple DNS servers received from DHCP
If we receive multiple DNS servers via DHCP only the first one is used,
regardless of CONFIG_DNS_RESOLVER_MAX_SERVERS constant.
Parse DHCP option and save addresses that fit

Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
2024-07-27 20:49:57 +03:00
Pieter De Gendt
ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03:00
Emil Gydesen
7ed8bb5020 Bluetooth: BAP: Add PAST Kconfig dependency for BASS
The broadcast assistant will only be able to send
BT_BAP_BASS_PA_REQ_SYNC_PAST if
CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER is enabled.

Similarly the scan delegator will only set
past_supported = true if
CONFIG_BT_PER_ADV_SYNC_TRANSFER_RECEIVER is enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-27 20:47:26 +03:00
Emil Gydesen
8be6db67fc Bluetooth: ISO/BAP: Refactor BIS bitfield
Refactors teh BIS bitfield values used for ISO
and BAP.

Previously BIT(1) meant BIS index 1, which was a Zephyr choice
in the early days of ISO, as the BT Core spec did not use
a bitfield for BIS indexes.

Later the BASS specification came along and defined that
BIT(0) meant BIS index 1, which meant that we had to shift BIS
bitfields between BAP and ISO.

This commit refactors the ISO layer to use BIT(0) for Index 1 now,
which means that there is no longer a need for conversion
between the BAP and ISO layers, and that we can use a value
range defined by a BT Core spec (BASS).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-27 15:19:46 +03:00
Jonathan Rico
147ee3daaf Bluetooth: host: Send host num completes as early as possible
The Softdevice Controller now sends the disconnect event only after
receiving all Host Num Completes for the packets it sent to the host.
This is done for security reasons.

In our current reassembly logic, it does not really matter when we
withhold the num complete.

Before this patch, it's the first fragment that is withheld, and after
the patch it will be the last fragment that is withheld until the host
is done processing.

The flow control properties are maintained, just in a different way.

Co-authored-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-27 15:18:51 +03:00
Jonathan Rico
32212bfb63 Bluetooth: host: extract sending of host num complete
The functionality is moved in preparation of the next commit which will
re-use this function from somewhere else.

Also add (default-on) asserts that we are able to allocate and send the
command. If that is not the case, we will leak buffers from the PoV of
the controller, leading to a stall in data transfer.

Depending on the error, we could probably recover using a disconnection.
For now, do the safe thing and stop the whole stack.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-27 15:18:51 +03:00
Sean Madigan
4284f99870 bluetooth: host: hci_core: Safer checking of conn complete events
The spec only guarantees the connection complete event parameters
are valid if the status is BT_HCI_ERR_SUCCESS. When the status is
not BT_HCI_ERR_SUCCESS, the host shall ignore the other parameters.

See Vol 4, Part E, 4.5 Command error handling:
"""
If an error occurs for a command for which an HCI_Command_Complete event
is returned, the Return Parameters field may only contain some of the
return parameters specified for the command.
...
The above also applies to commands that have associated command specific
completion events with a Status parameter in their completion event, with
the exceptions shown in Table 4.1, Event Valid parameters
...
Event                           | Valid parameters
------------------------------------------------------------
LE_Connection_Complete          | none
LE_Enhanced_Connection_Complete | none
"""

Refactor `le_legacy_conn_complete`, `le_enh_conn_complete_v2` and
`le_enh_conn_complete` to check and handle the status before handling
any other parameters.

An issue was seen where SDC returned event with status
`BT_HCI_ERR_UNKNOWN_CONN_ID`, but because adv_handle and sync_handle
were not invalid the event was not handled.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2024-07-27 15:18:32 +03:00
Pisit Sawangvonganan
b34349eed9 net: utils: improve hex digit character checking in net_bytes_from_str
Several refactors and improvements for `net_bytes_from_str` as follows:
- Replaced manual hex digit checks with `isxdigit()`.
- Changed variable `i` from unsigned int to size_t for consistency with
  the `strlen()` return type.
- Added `src_len` to store the result of `strlen(src)` to avoid
  multiple calls to `strlen` in the `for-loop`.
- Ensured casting to `unsigned char` before passing to `isxdigit()` to
  prevent undefined behavior.
- Explicitly cast the result of `strtol()` to `uint8_t` to match
  the buffer type.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-27 15:16:42 +03:00
Robert Lubos
bfe958a7f1 net: sockets: tls: Fix poll update event check
In case POLLIN is set, and no new application data has been detected,
the ztls_poll_update_ctx() should only return -EAGAIN if no other events
are available for the socket. Otherwise, the function may end up
busy-looping, in case for example POLLOUT is also monitored for the
socket.

Current check verifying that was wrong, as it caused to function to
return -EAGAIN even if some other events could've been reported for the
socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-27 15:13:17 +03:00
Emil Gydesen
f338bf6fae Bluetooth: Host: Discard advertising data if not explicit scanning
If the application is not explicitly scanning, then there is not
really any need to parse advertising reports nor send them to the
application.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-27 15:12:39 +03:00
Vinayak Kariappa Chettimada
04e3d0081b Bluetooth: Controller: Fix Advertising PDU memory allocation
Fix Advertising PDU memory allocation for redundant Periodic
Advertising related PDU allocations. The buffer count
related to Periodic Advertising was included twice.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-07-27 15:09:39 +03:00
Maochen Wang
bf42164084 net: wifi: Fix the nm type check error
Fix the NM iface type check error, should use (1 << WIFI_TYPE_STA),
instead of WIFI_TYPE_STA. Same for WIFI_TYPE_SAP.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-07-27 15:09:20 +03:00
Rubin Gerritsen
2967bd847f Bluetooth: HCI: Expose bt_hci_conn_lookup_handle()
When implementing vendor specific HCI APIs and events,
we want to be able to convert between host objects,
handles and back again.

Exposing this API makes that possible

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-27 15:09:00 +03:00
Rubin Gerritsen
e28207d61b Bluetooth: HCI: Expose bt_hci_per_adv_sync_lookup_handle()
When implementing vendor specific HCI APIs and events,
we want to be able to convert between host objects,
handles and back again.

Exposing this API makes that possible.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-27 15:09:00 +03:00
Rubin Gerritsen
5b14748616 Bluetooth: HCI: Expose bt_hci_adv_lookup_handle()
When implementing vendor specific HCI APIs and events,
we want to be able to convert between host objects,
handles and back again.

Exposing this API makes that possible.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-27 15:09:00 +03:00
Dmitrii Golovanov
c59412b1bf ztest: shell: Fix compilation error for NEWLIB_LIBC
Fix compilation error implicit declaration of function 'free'
in case of `CONFIG_NEWLIB_LIBC`.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-07-27 15:08:14 +03:00
Fin Maaß
1f38d9dfef net: shell: iface: add infos from eth phy
add information about the ethernet
phy and the current link speed to the
net iface command.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-07-27 15:07:26 +03:00
Fin Maaß
2fb983a427 net: l2: ethernet: add way to access phy
add a way to access the ethernet phy
device via the ethernet device.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-07-27 15:07:26 +03:00
Johann Fischer
28b2051bda usb: device_next: add support for configuration string descriptor
Change USBD_CONFIGURATION_DEFINE macro to take the address of a string
descriptor node as an argument. This is a breaking change for macro
users, but quite convenient and easy to implement.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-07-27 15:06:09 +03:00
Johann Fischer
1540ba19d7 usb: device_next: remove unnecessary usbd_device_unlock()
Remove unnecessary usbd_device_unlock() in usbd_add_configuration().

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-07-27 15:06:09 +03:00
Emil Gydesen
34f4d2d496 Bluetooth: TBS: Add missing endian handling in TBS
TBS had 2 cases where 16-bit values were not properly
converted to LE before being sent over air.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-27 10:48:09 +03:00
Pisit Sawangvonganan
1100393b79 net: lwm2m: optimize socket_loop by using local variables
Changes include:
- Introducing a local `ctx` variable to replace multiple
  `sock_ctx[i]` references.
- Using a local `revents` variable to simplify repeated
  `sock_fds[i].revents` checks.
- Consolidating conditional checks for socket events
  (ZSOCK_POLLERR, ZSOCK_POLLNVAL, and ZSOCK_POLLHUP) as they are
  individual bit definitions, allowing them to be checked simultaneously.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-27 10:47:58 +03:00
Gaofeng Zhang
a5781547d6 net: ipv4: Fix tx_pkts slab leak in send_ipv4_fragment
In the send_ipv4_fragment function, if net_pkt_get_data returns
fail, a tx_pkts slab leak will occur. If leak exceeds the
maximum number CONFIG_NET_PKT_TX_COUNT of tx_pkts slab, tx_ptks
will be used up, and the related modules(dhcp, ping and so on)
of net cannot alloc tx_pkt slab, and will sleep and can not
return successfully until available slab.
dhcp work or ping work cannot be executed beacause can't alloc
memory, and ping command cannot return, console also fails to
input commands, and the console hang problem occurs.

Signed-off-by: Gaofeng Zhang <gaofeng.zhang@nxp.com>
2024-07-27 10:45:14 +03:00
Konrad Derda
c2747acbff net: ipv6: routing: move checking for an own source address
When IPv6 packet is received, there is a check of the packet's source
address to verify that it is not interface's non-tentative address.

This commit moves this check to the later stages of processing as
packets that can be routed are dropped in the early stage otherwise.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Konrad Derda
b41b7d5da8 net: ipv6: routing: do not loop back already routed packets
If the packet was routed between interfaces by IPv6 module it should
not be looped back but has to be passed to the destination interface
instead.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Konrad Derda
807daf3788 net: ipv6: routing: do not use an original source address for NS
When a packet's transmission is prepared and Neighbor Solicitation is
sent its souce address is always the same as of a packet awaiting -
also for packets routed from an other interface.

Quote from the RFC:
If the source address of the packet prompting the solicitation is the
same as one of the addresses assigned to the outgoing interface, that
address SHOULD be placed in the IP Source Address of the outgoing
solicitation.  Otherwise, any one of the addresses assigned to the
interface should be used.

This commit fixes the behavior.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Konrad Derda
79f7b400cb net: ipv6: routing: match destination address to a given interface
Before packet is routed there is a check verifying if the destination
address is not the device's one. However, the check should be limited
to the packet's original interface. Otherwise, packet cannot be routed
if it is destined for an other interface of the device.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Seppo Takalo
6addba5698 net: lwm2m: Verify X509 hostname when URI contains valid name
Enable hostname verification in DTLS handshake when server URI contains
valid hostname.
When URI is given just as IP address, don't fill up the
ctx->desthosname or enable hostname verification.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-07-27 10:44:27 +03:00
Bjarki Arge Andreasen
280fbec58e net: lib: sockets: socketpairs: Update socketpair mem alloc
The memory allocation for socketpairs is not conformant to the new
MEM_POOL_ADD_SIZE_ mechanism for allocating heap memory.

Specifically CONFIG_NET_SOCKETPAIR_HEAP can not be selected unless
the user has specified CONFIG_HEAP_MEM_POOL_SIZE. We should be
using MEM_POOL_ADD_SIZE_ to add to the heap if the user wants to
use it for socketpair allocation.

Additionally increase the size of pre-allocated sockets to 8 from 1
to support larger devices by default, taking into consideration the
required socketpairs and buffer sizes when using
WIFI_NM_WPA_SUPPLICANT.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2024-07-27 10:43:32 +03:00
Robert Lubos
35fe353ad6 net: lib: coap_client: Replace send_mutex with more generic lock
Introduce a more generic mutex for protecting coap_client structure.

This allows to avoid a certain race condition when sending consecutive
CoAP requests. The case was, that when a CoAP receive thread notified
the application that a complete response was received, and the
application wanted to send another request from the application thread,
the consecutive call to coap_client_req() might've failed if the
application thread has higher priority than the CoAP receive thread
because of the request context cleanup is done after calling the
application callback.
Having a mutex, which is locked while processing the response, and when
attempting to send a new request allows to synchronize threads as
expected.

As this new mutex seemed redundant with the more specialized send_mutex
already present in the coap_client, the latter was removed (i. e.
transmission is also protected with the new mutex).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-27 10:43:15 +03:00
Robert Lubos
2555612265 net: lib: coap_client: Add static keyword where missing
Make sure internal functions are static. Remove unused function.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-27 10:43:15 +03:00
Fabian Pflug
ca53d2bf80 net: l2: ieee802154: mgmt: allow beacon payload
The standard does allow for a optional beacon payload, which gets lost
during scan, that could be interesting for the application to access
in the NET_EVENT_IEEE802154_SCAN_RESULT callback.

See section 7.3.1.6 in IEEE Std 802.15.4 for more information about
the beacon payload field. And section 7.3.1 and figure 7-5 about general
beacon frame format.

Signed-off-by: Fabian Pflug <fabian.pflug@grandcentrix.net>
2024-07-27 10:42:45 +03:00
Fabio Baltieri
ef14c9b867 lib: os: add a header for printk hook functions
Add a zephyr/printk.h header for the __printk_hook functions, these are
currently manually declared by all console drivers for no good reason.

Move the documentation into the header and also unify the way that
console drivers call the function.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-07-27 10:41:01 +03:00
Muhammad Munir
04011dafe0 net: lib: dhcpv4: added router id in response options
When running dhcp, it was not assigning gateway/router
address to the client devices. It is fixed in this PR.

Signed-off-by: Muhammad Munir <muhammad.munir@zintechnologies.com>
2024-07-27 10:40:17 +03:00
Jukka Rissanen
cf552905f4 net: context: Check null pointer in V6ONLY getsockopt
Make sure we are not accessing NULL pointer when checking
if the IPv4 mapping to IPv6 is enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-07-27 10:39:40 +03:00
Lyle Zhu
f987057eb3 Bluetooth: BR: SM: Fix ltk derive issue
The BR SMP fixed channel BR/EDR Security Manager
(CID 0x0007) cannot be set in L2CAP Information
Response. It is caused by the invalid fix channel
definition used.

Move macro `BT_L2CAP_BR_CHANNEL_DEFINE` to
`l2cap_br_interface.h`, that the macro can be
accessed in smp.c. And remove duplicated
header file include `#include "classic/l2cap_
br_interface.h"` from smp.c.

Define fixed channel, BR/EDR Security Manager
(CID 0x0007), by using `BT_L2CAP_BR_CHANNEL_DEFINE`.

Fix the smp L2CAP channel of BR cannot be found
issue. Use `bt_l2cap_br_lookup_tx_cid` to get
the BR SMP L2CAP channel instead of using
`bt_l2cap_le_lookup_tx_cid`.

Fix the invalid SMP L2CAP channel used when
the BR smp failed.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-07-27 10:39:17 +03:00
Rubin Gerritsen
e23345b4d1 Bluetooth: Host: Fix compiling PAwR Sync without PAST RX
The function `bt_hci_le_past_received_v2()` is not compiled
in for this configuration, so the reference needs to be removed.

Fixes #76268.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-27 10:37:56 +03:00
Rubin Gerritsen
c3dd1e8a74 Bluetooth: Host: Fix bt_disable() for IPC giving HCI Reset timeout
Some HCI drivers issue HCI reset when disabling, like the IPC HCI
driver. We need to keep the RX thread running to allow receiving
the command complete.

This commit postpones aborting the RX thread until this is done.
The issue happens started occuring after commit
d0e75ab87c4b53d66008c941c38709a2fca9dbea.

Fixes #76202.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-07-25 09:14:39 +02:00
Joakim Andersson
276850ca02 testsuite: Remove reference to deprecated ztest API
Remove reference to deprecated ztest_test_suite function from API
description.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2024-07-23 09:14:04 +02:00
Flavio Ceolin
f9de58efb9 pm: Do not select deprecated symbol
PM_DEVICE_RUNTIME_EXCLUSIVE was deprecated and its behavior
is achived with PM_DEVICE_SYSTEM_MANAGED=n.

Fixes #76037

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-07-22 03:28:54 -04:00
Luis Ubieda
7d9ff8bcb4 rtio: workq: Initialize Work item before using it
As the items come from the memory slab, their initialization state
can't be guaranteed. This is causing some devices triggering an assert
in p4wq where the item's thread is not null (not zero).

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-13 10:27:58 -04:00
Jonathan Rico
792ae68165 Bluetooth: host: Use correct user_data size for hci_rx_pool
`struct acl_data` is used even when Host flow control is not enabled.
It is written to through the `acl(buf)` accessor in `conn.c:hci_acl()`.

Hopefully no netbufs were harmed by that :/

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-13 10:25:31 -04:00
Pisit Sawangvonganan
10f495e0fd net: lib: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/lib` directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-12 09:33:20 -04:00
Pisit Sawangvonganan
d2af60687e net: l2: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/l2` directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-12 09:33:20 -04:00
Pisit Sawangvonganan
d1781da2ba net: lwm2m: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/lib/lwm2m` directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-12 09:33:20 -04:00
Johann Fischer
108c52c244 usb: device_next: fix typo in property name
Use rx-fifo-size to set RX ringbuffer size.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-07-12 09:13:13 -04:00
Emil Gydesen
1751a7f190 Bluetooth: TBS: Add missing documentation in tbs.h
Add missing documentation for some defintions in tbs.h
Moved some internal definitions to tbs_internal.h

Removed invalid TBS technology BT_TBS_TECHNOLOGY_IP that
doesn't exist.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-12 06:24:39 -04:00