Commit graph

599 commits

Author SHA1 Message Date
Jukka Rissanen
5a9a39caf3 net: mgmt: Convert the mgmt API to use 64-bit masks
Instead of using 32 bit enum values for event numbers, convert
the code to use 64 bit long bit fields. This means that the
user API is changed to use 64 bit event values instead of 32
bit event values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-18 10:54:44 +02:00
Tommi Kangas
941dcd31e7 shell: Make TX mutex timeout configurable
The 50 ms TX mutex timeouts introduced in commit b0a0feb cause
dropped messages when used with the shell log backend. This
commit makes time timeout configurable using the
CONFIG_SHELL_TX_TIMEOUT_MS Kconfig option and makes the
default timeout longer when shell log backend is enabled.

Link: #90215

Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
2025-06-17 16:05:20 +02:00
Benjamin Cabé
9ab0ea73a8 shell: Introduce structured help message
In order to enable better and more consistent help messages for shell
commands, this commit introduces a new SHELL_HELP macro that allows to
document a command's description and usage in a more structured way.

This will allow to get rid of inconsistent (and duplicated!) variations
of "Syntax: ...", "Syntax:\n ...", "Usage: ...", in the commands, and
formatting of the description+usage will be taken care of by the shell
when it detects the help message is using the "structured" format.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 09:55:21 +02:00
Benjamin Cabé
7bdeffb5a6 shell: fix margin handling after newlines in formatted help text
Lines following newlines in shell help text were not properly indented.
For example, in "abc def\ndef ghi\njkl mno", the lines "def ghi" and
"jkl mno" would appear without the expected left margin.

The issue was that after processing a newline and setting proper cursor
position, the function would fall through to z_shell_raw_fprintf() which

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 09:55:21 +02:00
Pisit Sawangvonganan
7abda99fe3 shell: mqtt: use ring_buf_reset to flush rx_rb
The `sh_mqtt_rx_rb_flush` function was intended to flush `rx_rb` when
get an error return from `mqtt_read_publish_payload_blocking`.
Instead of retrieving values from `rx_rb` one by one, calling
`ring_buf_reset` achieves the same result more efficiently.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-04-09 22:06:05 +02:00
Pisit Sawangvonganan
24dabdd5fb shell: mqtt: optimize module-scoped sh_mqtt variable access
Introduce a local pointer, `struct shell_mqtt *sh`, to minimize access
to the module-scoped `sh_mqtt` variable.
This allows `sh` to be stored in a CPU register, resulting in more
compact code and improved execution efficiency.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-04-09 22:06:05 +02:00
Tomasz Bursztyka
b4f9242a6a shell: kernel: Add a panic command
For testing purposes only. Testing the fatal error handler or
a coredump backend. Or just out of curiosity.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-03-29 07:44:11 -04:00
Robert Lubos
55e1c10894 net: mqtt: Add MQTT 5.0 support for DISCONNECT
Add support for DICONNECT message specified in MQTT 5.0.
As with MQTT 5.0, the disconnect can now also be initiated by the
broker, it was needed to add decoder support for the message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-03-26 16:19:42 +01:00
Triveni Danda
e7a65ac9b4 shell: Set default max argc count when WiFi shell is enabled
Set the default maximum argument count for the shell to 30
when the Wi-Fi shell is enabled, to ensure all Wi-Fi
commands work without failure.

Signed-off-by: Triveni Danda <triveni.danda@nordicsemi.no>
2025-03-14 14:40:57 +01:00
Michal Piekos
81bf6e746e shell: fixes shell dead code issue
Move z_transport_buffer_flush(sh) to the scope of the while loop.

Coverity-CID: 399568

Signed-off-by: Michal Piekos <michal.piekos@wp.pl>
2025-03-07 20:00:27 +01:00
Christopher Clingerman
db9dccdc8a shell: rtt: increase bypass buffer size
If the RTT shell backend is selected and the "down" buffer size
has been selected, the shell bypass functionality should instead
use the buffer size specified by the configuration.

Signed-off-by: Christopher Clingerman <christopher.clingerman@sensorfy.ai>
2025-02-14 17:07:52 +01:00
Jeremy Bettis
e1cfd098a2 shell: Fix Kconfig dependencies
PR #84651 introduced new shell commands that don't compile if
CONFIG_THREAD_MONITOR=n

Add THREAD_MONITOR to new shell commands.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-02-06 21:14:01 +01:00
S Swetha
8f647ef46b [shell]: Add thread control features through shell
This commit extends the shell command functionality by
adding three new operations for thread management.
kernel thread suspend <thread_id>:
Suspends any thread based on its identifier.
kernel thread resume <thread_id>:
Resumes the thread that was previously suspended.
kernel thread kill <thread_id>:
Terminates any thread based on its identifier
These extended commands are useful for controlling
any threads through Zephyr Shell.

Signed-off-by: S Swetha <s.swetha@intel.com>
2025-02-04 11:56:22 +01:00
Daniel DeGrasse
598f343385 shell: handle reprint correctly when output crosses line boundary
When reprinting the shell command buffer with long user inputs, the
reprinted buffer may cross a line boundary, and require a newline to be
printed. For these cases, print the command buffer character by
character, inserting newlines as appropriate.

Fixes #82155

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2025-01-30 16:21:53 +01:00
Jakub Rzeszutko
b0a0febe58 shell: fix unsafe API calls and add configurable autoflush behavior
Fixes an issue where the shell API could block indefinitely when called
from threads other than the shell's processing thread, especially when
the transport (e.g. USB CDC ACM) was unavailable or inactive.

Replaced `k_mutex_lock` calls with an indefinite timeout (`K_FOREVER`)
by using a fixed timeout (`K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)`) in shell
API functions to prevent indefinite blocking.

Link: https://github.com/zephyrproject-rtos/zephyr/issues/84274

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2025-01-23 13:45:20 +01:00
Jakub Rzeszutko
8991b954bc shell: add Kconfig option for configurable autoflush behavior
Introduced a new Kconfig option `SHELL_PRINTF_AUTOFLUSH` to allow
configuring the autoflush behavior of shell printing functions.

Updated `Z_SHELL_FPRINTF_DEFINE` to use the
`CONFIG_SHELL_PRINTF_AUTOFLUSH` setting instead of hardcoding
the autoflush behavior to `true`.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2025-01-23 13:45:20 +01:00
Krzysztof Chruściński
8207a05304 shell: modules: kernel_service: deprecate log_level
Log_level command is a duplicate of 'log enable' command from
the logging command set (enabled by CONFIG_LOG_CMDS=y). Adding
warning about deprecation as 'log enable' is recommended since
it has more features (e.g. autocompletion).

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-01-17 09:08:26 +01:00
Pieter De Gendt
e7e6cb9def shell: shell_log_backend: Allow printing the thread ID or name
Add the LOG_OUTPUT_FLAG_THREAD to the default flags for the shell log
backend.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-01-16 22:36:50 +01:00
Jilay Pandya
f5a126e7ac shell: backends: shell_websocket remove deadcode
fix coverity issue about deadcode, there is no code path which would
lead to the code that is being deleted with this commit

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2025-01-16 14:51:10 +01:00
Krzysztof Chruściński
f0cdaace22 shell: modules: kernel_service: Fix log_level command
Add missing return when input logging source argument is not valid.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-01-16 14:46:33 +01:00
Robert Lubos
60f5337a7a shell: websocket: Fix build with websocket logger disabled
In case websocket logger is disabled, the websocket shell backend should
still build, fix that.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Robert Lubos
814aa381c4 shell: websocket: Fix duplicate logs over websocket shell backend
In case websocket logging is enabled, the websocket shell should not be
configured as a logger backend, otherwise logs are duplicated.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Robert Lubos
4e38abad67 shell: websocket: Fix registered log level
Wrong symbol was used for log level when registering logger instance for
websocket shell, causing misconfiguration and in result unexpected
crashes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Nicolas Pitre
46aa6717ff Revert "arch: deprecate _current"
Mostly a revert of commit b1def7145f ("arch: deprecate `_current`").

This commit was part of PR #80716 whose initial purpose was about providing
an architecture specific optimization for _current. The actual deprecation
was sneaked in later on without proper discussion.

The Zephyr core always used _current before and that was fine. It is quite
prevalent as well and the alternative is proving rather verbose.
Furthermore, as a concept, the "current thread" is not something that is
necessarily architecture specific. Therefore the primary abstraction
should not carry the arch_ prefix.

Hence this revert.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-01-10 07:49:08 +01:00
Matt Rodgers
549e5de277 net: websocket: pass HTTP upgrade request context to user callback
Passing HTTP upgrade request context to the user callback allows the
user to decide whether to accept or reject the websocket connection
based on the HTTP headers in the request. The primary reason for this is
to enable authentication of the websocket connection (e.g. via cookies
or Authorization header).

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2025-01-08 21:02:02 +01:00
Pisit Sawangvonganan
b44250ae46 shell: modules: kernel: streamline code
This commit includes cleanups to `kernel_service`:
- `shell_tdata_dump()`:
  Adjust formatting to align with `.clang-format`.
- `shell_stack_dump()`:
  Update to pass `sh` directly instead of `user_data` since
  it is already assigned.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Pisit Sawangvonganan
8fedee30ee shell: modules: devmem: use shell_strtoul in cmd_dump
Switch from using direct `strtoul` calls to `shell_strtoul`.
This change leverages the extensive error handling provided
by `shell_strtoul`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Pisit Sawangvonganan
27cbe0553c shell: modules: date: omit NULL initialization of endptr
As `strtol` guarantee to set `endptr`, the initial `NULL` can be omitted.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Pisit Sawangvonganan
09f13a31e9 shell: utils: omit NULL initialization of endptr
As `strtoul`, `strtoll`, and `strtol` guarantee to set `endptr`,
the initial `NULL` can be omitted.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-12-13 11:35:28 +01:00
Krzysztof Chruściński
c7f400c9aa shell: backends: Do not use RTT backend with immediate logging
RTT backend can only be called from thread context and immediate
logging might lead to interrupt context use. Previously this limitation
was implied in different way and commit (c88a9ef27) got reverted.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-11 21:30:19 +01:00
Krzysztof Chruściński
ca4f2d94f8 Revert "segger: rtt: disable unsupported shell/log features"
This reverts commit c88a9ef272.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-11 21:30:19 +01:00
Yishai Jaffe
59c7d5715b shell: add function to get device by name or label
Added shell_device_get_binding() that wraps device_get_binding() plus
device_get_by_dt_nodelabel() so that a shell can easily get a device by
its full name or label.

Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
2024-12-11 07:58:50 +01:00
Yong Cong Sin
b1def7145f arch: deprecate _current
`_current` is now functionally equals to `arch_curr_thread()`, remove
its usage in-tree and deprecate it instead of removing it outright,
as it has been with us since forever.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-11-23 20:12:24 -05:00
Jakub Rzeszutko
1aaf08f7f1 lib: shell: replace strtol with strtoul in cmd_load for address parsing
Addresses in cmd_load() should always be unsigned. Previously, strtol()
was used, which is limited to signed long values, causing issues with
addresses >= 0x80000000. This commit replaces strtol() with strtoul(),
ensuring proper handling of the full 32-bit address space.

Fixes #81343

Signed-off-by: Aaron Fontaine <aaron.fontaine@dojofive.com>
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2024-11-21 09:17:08 +01:00
Jukka Rissanen
074b5f2ca0 shell: backend: websocket: Fix socket service creation
The NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC() macro was changed
earlier but the compilation error was missed. Fixing the macro
call.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-10-25 12:50:54 -05:00
Fin Maaß
03a5f417d1 net: sockets: socket_service: remove k_work related code
remove k_work related code and change
the argument of the callback to `struct net_socket_service_event`.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-10-23 11:32:21 +02:00
Krzysztof Chruściński
05dd68a377 shell: Allow custom shell log backend implementation
Shell is capable of acting as the logging backend and multiplex
logging messages with shell content. It expects that logging
messages goes through the logging backend. However, there is an
option that logs go only to the custom logging frontend. In
that case this default approach does not work and logging
frontend cannot be easily integrated with the shell (due to
its custom nature). Add Kconfig option SHELL_LOG_BACKEND_OOB
which prevent compilation of the default shell log backend.
When enabled, application can provide frontend specific
implementation to integrate shell with the logging.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-17 10:48:25 -04:00
Kristoffer Rist Skøien
c73c5d985e shell: Added assert
Assert to check columns. Averts a potential divide by zero

Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no>
2024-10-16 10:00:17 +02:00
Chris Friedt
f4e07d15d6 sys: util: define bits per byte, nibble, and nibbles per byte
Collect some common bit-widths redefined in various locations
and put them under sys/util.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-15 19:05:06 +01:00
Jukka Rissanen
7510e2d940 shell: backend: Create a websocket transport backend
This creates a websocket based shell backend that is used to
implement a websocket console that can be connected using a browser.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-10-15 04:11:03 -04:00
Kevin ORourke
3399e0614a shell: backend: telnet: Don't assert if connection closed
The code in shell_ops.c that calls telnet_write will assert if it
returns non-zero. For a telnet shell it's normal that the
network might disconnect unexepectedly, so that should not
trigger an assert.

Fixes #67637

Link: https://github.com/zephyrproject-rtos/zephyr/issues/67637

Signed-off-by: Kevin ORourke <kevin.orourke@ferroamp.se>
2024-10-10 20:23:18 -04:00
Jordan Yates
4953389b1e net: socket_service: remove work_q parameter
Remove the `work_q` parameter from `NET_SOCKET_SERVICE_SYNC_DEFINE` and
`NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC` as this feature was dropped
during review but the removal was not 100% complete.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-10-09 13:48:54 +02:00
Jakub Rzeszutko
5bb721264b shell: add generic RX buffer flush function
Added a generic function `z_shell_backend_rx_buffer_flush` to clear
the RX buffer when resuming the shell. The function repeatedly calls
the backend's `read` API until the buffer is empty or a maximum of
1000 iterations is reached. This prevents unintended command
execution after `shell_start`.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
2024-10-09 13:48:41 +02:00
Pisit Sawangvonganan
af4527e131 style: subsys: adjust return usage in void functions
For code clarity, this commit adjusts the use of `return` statements
in functions with a void return type as follows:
- Transform `return foo();` into separate statements:
  `foo();`
  `return;`
- Remove unnecessary `return` statements when
  they don't affect control flow.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-20 11:06:55 +02:00
Yong Cong Sin
ae20c08822 shell: kernel_service: heap: add required header
Add the "kernel_shell.h" header which is required but missing,
causing build error.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-19 03:52:59 -04:00
Yong Cong Sin
aa9446ca6b shell: modules: kernel: cleanup thread list subcmd
Parts related to the thread runtime stats are somewhat
standalone, refactor it out instead of having two #ifdef
and two places.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-17 20:12:33 -04:00
Yong Cong Sin
83212147b2 shell: kernel_service: reorg the commands
Split the `kernel_service.c` into multiple subcommand files,
each file would register with the main `kernel` cmd based on
the dependencies in Kconfig/CMakeLists.txt.

This greatly reduces the number of precompiler directives.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-09-17 20:12:33 -04:00
Keith Packard
94043dbefe subsys/shell: cmd_date_set uses gmtime_r, a POSIX function
Define _POSIX_C_SOURCE for this file to make sure gmtime_r is visible.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Pisit Sawangvonganan
d207edb1cf shell: rename shell_xxx_impl wrapper functions to shell_fprintf_xxx
Since the `_impl` naming convention is intended for internal use only,
renaming these functions to the `shell_fprintf_xxx` variant is
more suitable for calls outside the module:
- `shell_info_impl` to `shell_fprintf_info`
- `shell_print_impl` to `shell_fprintf_normal`
- `shell_warn_impl` to `shell_fprintf_warn`
- `shell_error_impl` to `shell_fprintf_error`

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-09 13:55:31 -04:00
Henrik Brix Andersen
159f7dbbb1 lib: net_buf: rename header file from zephyr/net/buf.h to zephyr/net_buf.h
Move the network buffer header file from zephyr/net/buf.h to
zephyr/net_buf.h as the implementation now lives outside of the networking
subsystem.

Add (deprecated) zephyr/net/buf.h header to maintain compatibility with old
file path.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-09-07 11:19:05 -05:00