In preparation for remote shell support, move hexdump printing to
the shell_utils.c file. Main shell.c file is not compiled for remote
shell client.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Do not compile shell_help() implementation if CONFIG_SHELL_HELP=n.
In that case, empty inline function is implemented in the shell
header and it may fail to compile.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
When input buffer is written, notify the shell. It will wake the
shell thread which will process the input buffer.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Core spec defines the range of adv intervals for extended advertising to
0x0020 to 0xFFFFFF, but the code currently only allows up to 0x4000.
This change enables the full range of intervals for extended advertising
Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
The checks validating RA, NS and NA packets content on input were not
correct - packets should be dropped in case any of those checks failed,
however current logic was invalid, causing other checks to be ignored as
long as the ICMPv6 code was correct (i. e. 0).
Apart from fixing the logic, split the single convoluted if condition
into separate if checks for better readability.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Replace EALREADY return values of the functions that modify or set USB
device attributes to EBUSY. EBUSY seems to be more appropriate for the
case when a user tries to change the attributes of an operational
device.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Remove the logic that silently clamps the MTU to valid ranges and
instead return an error if the configured MTU is below the minimum
required size.
The MTU is now always set to the maximum value that the configuration
can support, rather than conditionally using a default only when
set to 0.
Change log level from WRN to ERR for the minimum MTU check since
this now represents a fatal configuration error.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
ISO connections basically have 2 connection states:
1 for the `bt_iso_chan`, and one for the underlying
`bt_conn`. Due to how hci_disconn_complete_prio works,
these may be out of sync while disconnecting, and
bt_iso_chan_send could return 0 after we have received
a disconnect event from the controller. In this case
the number of pending SDUs in the host for the ISO
channel could be non-0, which could cause issues.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The first issue is that the query offset was not properly updated.
The second issue is more complex and relates to the use of message
compression in domain names
(https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.4). The
pointers can be nested (i.e. a first pointer pointing to a label with
another pointer)
For example: _http._tcp.local can be represented via:
'_http' + (pointer to a '_tcp' label + (pointer to a 'local' label).
This was not properly implemented, only single-pointers were supported.
Signed-off-by: Sebastiaan Merckx <sebastiaan.merckx@verhaert.com>
Add NULL checks for iface and addr in IPv4/IPv6 maddr add/rm
to prevent potential dereferences.
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
Make the Coordinated Set Size, Set Member Lock and Set Member Rank
characteristic optional by adding three new Kconfig options
BT_CSIP_SET_MEMBER_SIZE_SUPPORT, BT_CSIP_SET_MEMBER_LOCK_SUPPORT and
BT_CSIP_SET_MEMBER_RANK_SUPPORT. Also updates the existing examples
and tests to compile correctly.
Signed-off-by: Maximilian Zimmermann <gitmz@posteo.de>
Reorder some of the large and complex shell command
functions, to make each function simpler to follow.
This also makes the code pass the Sonarcloud complexity
rule.
This also contain a few other various fixes and updates.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Instead of defining the same arguments in all 3 CAP files,
we declare them in audio.h and initiate them in either
the initiator or commander, depending on their use.
The reason for this change, is that the CAP Handover API
require several of the parameter to be globally/statically
allocated, and cannot just rely on stack allocated parameters.
By doing this, we can use the same argument among the
CAP shell modules, while keeping the memory usage down.
This has the additional postive effect that we do not allocate
some of these arrays, which can be quite larger, on the stack.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Implement the shell command for handing over broadcast to
unicast. The command supports various configurations.
It is currently limited to cases with
- 1 connection and multiple streams
- Multiple connections and 1 stream
- Equal amount of streams and connections
Cases with e.g. 3 connections and 2 streams,
or vice versa, are not support given the complexity
of these cases.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Display raw packet socket statistics (recv, sent, drop, bytes) in the
"net stats" shell command output. This follows the same display format
as the existing UDP and TCP statistics sections.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:opus-4.6
Add statistics tracking for raw/packet sockets (AF_PACKET), following
the same pattern as existing UDP and TCP statistics. This tracks packet
counts (sent, received, dropped) and byte counts for raw socket traffic.
The new CONFIG_NET_STATISTICS_RAW Kconfig option is enabled by default
when CONFIG_NET_SOCKETS_PACKET is active. Statistics are updated in the
AF_PACKET send path (net_context.c) and the packet socket delivery path
(connection.c).
Includes NET_MGMT user API support, periodic output, and Prometheus
metrics integration.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:opus-4.6
The two cached handles did not provide anything useful
and can be removed, thus freeing up some memory.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Instead of allocating a generic uuid and copying the BASS UUID
to it for each discovery, we can just use declare and use it
as a constant as it won't change.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Fix insufficient buffer length validation in bt_sdp_parse_attribute().
The original check only verified space for the type byte and attribute
ID, but did not account for the type variable itself that is read from
the buffer immediately after the check.
This could lead to a buffer over-read if the buffer contains exactly
sizeof(uint8_t) + sizeof(attr->id) bytes but not enough for the
additional type field.
Add sizeof(type) to the length check to ensure all required data is
present before parsing.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
MISRA-C requires essentially boolean type in control flow.
Convert all if/while conditions using err or ret
as implicit booleans to explicit comparisons:
- if (err) -> if (err != 0)
- Same rules applied to while statements and ret variable
Assisted-by: GitHub Copilot
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Without this we can have scenarios where PSA Crypto headers are not
found under certain configurations.
Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
Move the AVRCP cover art initialization from bt_avrcp_init() to
bt_avrcp_tg_register_cb(). This ensures that cover art is initialized
only when the target callback is registered, aligning with the
initialization flow of other AVRCP target features.
Additionally, add a check in bt_avrcp_tg_cover_art_init() to prevent
re-initialization if the PSM is already set, returning success if
cover art is already initialized.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
The bt_bap_unicast_client_discover and
bt_bap_broadcast_assistant_discover functions now require security
to have already been done before any operations are done.
The BAP require a specific security level and properties,
and checking the security earlier will prevent any unncessary
operations if the expected security requirement cannot be met.
Additionally, ensuring that there is an appropriate pairing with
the provided connection, ensures that we can rely on CONFIG_BT_MAX_PAIR
for soem arrays in the future.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Newer version of libmctp allocates a buffer to reassembly messages that
has `MCTP_MAX_MESSAGE_SIZE` size. By default, this size is 64Kb, which
may be too big for Zephyr applications.
This patch adds CONFIG_MCTP_MAX_MESSAGE_SIZE - default 1024 - to allow
Zephyr applications to tune the value used by libmctp.
Also update CONFIG_MCTP_HEAP_SIZE to note it needs to be big enough to
hold CONFIG_MCTP_MAX_MESSAGE_SIZE, on top of other allocations.
Assisted-by: GitHubCopilot:claude-sonnet-4.6
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Newer version on libmctp has a different signature for
`mctp_set_alloc_ops`:
mctp_set_alloc_ops(alloc, free, msg_alloc, msg_free)
This patch updates mctp_memory.c to provide the new wrappers for
msg_alloc and msg_free and use new signature for `mctp_set_alloc_ops`.
While at it, remove old usages of `mctp_set_alloc_ops` that existed in
the samples: `mctp_memory.c` should take care of everything.
Finally, libmctp doesn't deallocate packets sent to its RX bus: it's now
for the caller to do so. So this patch also adds the corresponding
`mctp_pktbuf_free` calls.
Assisted-by: GitHubCopilot:claude-sonnet-4.6
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Move the `depends on POLL` Kconfig depenedency to `select POLL`. Mixing
`select` and `depends on` with the same symbol is the primary cause of
Kconfig dependency loops, and every other `POLL` "dependency" uses
`select`.
Signed-off-by: Jordan Yates <jordan@embeint.com>
set iface in data during build. So we don't have to set it later in
the iface init. Due to the fact that we already set the id of the data
structure during build, it is already in the data section of the linker
and not the bss section, so that it doesn't increase the size of the
binary. At the same time we save some code and instructions to set the
iface in the data structure during init.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
The cdc_ncm_send() function ignores the return value from
usbd_ep_enqueue(). If the enqueue fails, the code proceeds to block
forever on k_sem_take() waiting for a completion callback that will
never arrive, causing a deadlock.
This was discovered by comparing the CDC-NCM implementation with
CDC-ECM, which correctly checks the return value:
ret = usbd_ep_enqueue(c_data, buf);
if (ret) {
LOG_ERR("Failed to enqueue net_buf for 0x%02x", ep);
net_buf_unref(buf);
return ret;
}
The NCM driver was missing this error handling, leading to potential
hangs if usbd_ep_enqueue() fails for any reason (e.g., endpoint not
ready, USB disconnected, buffer issues).
Fix by checking the return value and properly cleaning up (freeing
the buffer) before returning the error code to the caller.
Signed-off-by: Jay Beavers <jay@tolttechnologies.com>
Definining the functions counterpart for cabled ethernet to operate on
the list of interfaces and differentiate them from the 802.11 based ones
Signed-off-by: Andrea Gilardoni <a.gilardoni@arduino.cc>
There are situations where internal DNS resolver will reject the packet,
and in this case, query index is not calculated.
This may break forwarding mechanism;
If DNS packet forwarding is enabled, and internal validation fails, some
checks are done and an attempt to calculate query index is performed, so
the packet can be forwarded and used.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Remove in-tree support for the optional CANopenNode module. This will be
provided as an external module instead, as there are no bindings from
Zephyr towards this module.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Make the qos parameter of the BAP can CAP APIs const,
as they are now only used as one-time parameters, and not stored.
This also means that any uses of this can place the qos
parameter in the stack, rather than static memory.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The pointer represent the qos configuration
for a stream based on the ASE or broadcast configuration,
and serves as a read-only value. Changing it to `const` makes
this more clear.
Some minor changes were done to existing code to help
support this change.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
In some cases the stream->qos pointer pointed to the
qos argument, and sometimes it pointed to the ep->qos.
Now all qos arguments are copied to ep->qos, and
stream->qos always points to stream->ep.qos.
Some modules had some refactoring done to properly store
the QoS. The unicast client had some additional checks
done or redone, and some now-unused code removed.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Remove the hardcoded setsockopt(TLS_HOSTNAME, "localhost") which
prevents server-side peer certificate verification from working: the
hostname check compares "localhost" against the client cert's CN/SAN,
which will never match a real client certificate.
Signed-off-by: Steven Friedman <friedman@ionq.co>
Standardize error handling for bt_conn_get_info()
across the Bluetooth shell.
- Use a local 'err' variable instead of inline calls
- Check for (err != 0) consistently
- Include error code in all error messages
- Improve log messages for better debugging context
This ensures consistent behavior and more
informative diagnostics when retrieving connection
information fails.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Use shell_error() instead of shell_print() when
bt_conn_get_info() fails and include the returned
error code in the log.
This makes failures easier to diagnose.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Coverity (CID 525133) reported that the return
value of bt_conn_get_info() was not checked in
disconnected(), which could lead to use of
uninitialized data.
Fix this by validating the return value before
using the connection info structure.
If retrieving the information fails, fall back to
using the generic connection type to preserve the
existing behavior.
This prevents undefined behavior while maintaining
the original logic.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Coverity (CID 333394) reported that the return
value of bt_conn_get_info() was not checked in
remote_info_available(), which could lead to use
of uninitialized data.
Fix this by checking the return value and aborting
early in case of error, ensuring that the
connection info structure is valid before use.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
net_virtual_set_name already makes sure,
that the string ends with 0, therefore
we can directly provide the constant string.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
because these 2 bools are after a uint16_t, that itself is after
a pointer, there should be space for 16 bit, so we can have the
bools regular instead of bit-fields.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>