Commit graph

676 commits

Author SHA1 Message Date
Jamie McCrae 5c88d45544 treewide: mgmt: mcumgr: Change "ret" to "err" for SMP version 2
This is a stable API treewide change changing the newly introduced
"ret" response to "err" as it was overlooked that the shell_mgmt
group already used "ret" to return the exit code of the command
and this created a collision. Since SMP version 2 was only recently
introduced, there should not be any public implementations of it
as of yet, but the original function has been kept and marked as
deprecated.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-21 10:18:50 +02:00
Jamie McCrae 0001d01bfe mgmt: mcumgr: Allow additional cbor states for encoding
Allows selecting more than the default number of encoding states.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-21 10:12:06 +02:00
Jamie McCrae 8de70bc294 mgmt: mcumgr: transport: udp: Fix non-automatic start
Fixes a stray ifdef which causes a build failure if the automatic
UDP start Kconfig is not enabled.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-21 10:11:50 +02:00
Anas Nashif ccba6d4143 mcumgr: do noy rely on CRC being enable, imply CRC in Kconfig
CRC is now disabled by default, so use imply to enable it.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-18 08:52:16 +03:00
Jamie McCrae 4b9dddcd3a mgmt: mcumgr: grp: os_mgmt: Add force parameter to reset command
Adds the force parameter to the reset command which is now
provided to the callback hook (if enabled).

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-04 12:17:07 +02:00
Jamie McCrae 9023a8e14f mgmt: mcumgr: grp: stat_mgmt: Use zcbor decode bulk function
Uses the zcbor decode bulk function instead of manually parsing the
array in the function to reduce duplicated code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-04 10:44:29 +02:00
Jamie McCrae 8616e6ac01 mgmt: mcumgr: grp: os_mgmt: Use zcbor decode bulk function for echo
Uses the zcbor decode bulk function instead of manually parsing the
array in the function to reduce duplicated code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-08-04 10:44:29 +02:00
Jamie McCrae a0a9539d02 mgmt: mcumgr: grp: Fix error translation function indent
Fixes lines not being indented and looking like a single blob

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 12:49:36 +02:00
Jamie McCrae 588f6acbd5 mgmt: mcumgr: grp: img_mgmt: Fix not checking write bounds
Fixes an issue whereby the data packets were not checked to ensure
that the client has not attempted to write more data than the size
that was provided in the original upload packet.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 10:43:54 +02:00
Jamie McCrae 9422fc6e20 mgmt: mcumgr: grp: img_mgmt: Fix not checking image upload size
Fixes an issue whereby upload image size would not be checked in
the first packet of an upload, which would allow an image to be
uploaded until it reached the point of it being too large to
fit anymore.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 10:43:54 +02:00
Jamie McCrae 097c568c81 mgmt: mcumgr: grp: fs_mgmt: Fix wrong error checking
Fixes an issue with not properly checking error responses.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-31 10:43:28 +02:00
Juha Heiskanen d77a657526 mgmt: smp: MCUmgr Client support
MCUmgr client basic implementation for support Image and OS grpup
commands.

Image Group:
* Image state read/write
* Image Upload secondary slot
* Image Erase secondary slot

OS group:
* Reset
* Echo service, disabled by default

Opeartion's are blocked call and cant't call inside worker queue.
IMG and OS need to be SMP client object for transport.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-07-27 14:35:43 +02:00
Juha Heiskanen 5797e4241e mgmt: smp: SMP Client enabler
SMP client support for generate request and handling
response message.

Updated SMP transport for send request.

Added API for register SMP transport.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-07-27 14:35:43 +02:00
Jamie McCrae 8ecedf2dfb mgmt: mcumgr: grp: img_mgmt: Fix renamed define
Fixes an issue whereby a define was renamed in one place but not
another.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-27 11:16:04 +02:00
Jamie McCrae 7ca7f5a39c mgmt: mcumgr: Use MCUboot bootutil file instead of outdated copy
Uses the MCUboot bootutil image.h file directly instead of an
outdated copy which resides in the zephyr tree.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-26 14:32:20 +02:00
Girisha Dengi 75547dd522 soc: arm64: Add agilex5 soc folder and its configurations
Add Agilex5 soc folder, MMU table and its configurations for
Intel SoC FPGA Agilex5 platform for initial bring up.
Add ARM Cortex-a76 and Cortex-a55 HMP cluster type.

Signed-off-by: Teik Heng Chong <teik.heng.chong@intel.com>
Signed-off-by: Girisha Dengi <girisha.dengi@intel.com>
2023-07-25 16:58:01 +00:00
Jamie McCrae ee5c9b2629 mgmt: mcumgr: grp: img_mgmt: Add image data written callback
Adds an optional callback upon image data being written, can be
used for syncing or timeout purposes.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-20 14:55:46 +00:00
Jamie McCrae 6c541e1af0 mgmt: mcumgr: Add event ID index callback function
Adds a function which gets the callback ID index of a given
event ID.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-20 14:55:46 +00:00
Jamie McCrae ecfbabd213 mgmt: mcumgr: Make SMP version 2 to legacy error lookup extensible
Replaces the manual lookup function with a lookup function which
is provided when registering MCUmgr handlers which can be used to
find the function to translate error codes, allowing out of tree
MCUmgr handlers to provide error translation handlers.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-20 10:35:14 +00:00
Dominik Ermel ebaa145818 mgmt/MCUmgr/img: Fix build issue with slot0_ns_partition
The commit fixes build issue when building for two application
images in board that does not have slot0_ns_partition.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-07-14 17:49:02 +02:00
Dominik Ermel cb4aa46faf mgmt/MCUmgr/img: Fix img_mgmt_get_other_slot
Fix conditional compilation within img_mgmt_get_other_slot,
where CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER has been
incorrectly checked and #endif incorrectly placed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-07-14 17:48:40 +02:00
Dawid Niedzwiecki c590c5c1ee mgmt: ec_host_cmd: add suppressing commands
Add a feature to suppress commands. The suppressed commands are not
logged on the command reception.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-14 09:38:20 +02:00
Dawid Niedzwiecki cf3b0381ae mgmt: ec_host_cmd: fix init of npxc shi backend
Make sure not to access not assigned pointer at the begining of the
initialization.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-13 09:21:08 +02:00
Dawid Niedzwiecki b04692b747 mgmt: ec_host_cmd: add user callback for a new command
Add a user possibility to set a callback for receiving a new function.
It allows instant performing some actions, that need to be done before
context switch.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Dawid Niedzwiecki b6a3254d8b mgmt: ec_host_cmd: verify a command before passing it to handler
Verify validity of a received command before passing it to the general
handler.

It allows performing some actions, right after receiving the command.
The context switch is not needed. Such feature may be needed for
overloaded system, where instant reboot is required.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Dawid Niedzwiecki 1b6d6fb135 mgmt: ec_host_cmd: add function to signal a new command
Add a function to signal a new host command by a backend.

Use a function instead of giving semaphore, because it allows more
actions on rx event, common for all backends.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Dawid Niedzwiecki 7a479eec0d mgmt: ec_host_cmd: save result of IN_PROGRESS command
Add a config to save the final result of a last host command that has
sent EC_HOST_CMD_IN_PROGRESS response. To get the final result use the
ec_host_cmd_send_in_progress_status function.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-12 09:26:42 +02:00
Mykola Kvach d0472aae7a soc: arm64: add Renesas Rcar Gen3 SoC support
Add files for supporting arm64 Renesas r8a77951 SoC.
Add config option CPU_CORTEX_A57.

Enable build of clock_control_r8a7795_cpg_mssr.c for
a new ARM64 SoC R8A77951.

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
2023-07-11 11:17:41 +02:00
Jamie McCrae c9a4764c10 mgmt: mcumgt: smp: Fix not checking returned status
Fixes not checking if a zcbor operation was successful.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-10 12:04:40 +02:00
Jamie McCrae fbacedaef8 mgmt: mcumgr: grp: shell_mgmt: Fix issue with unset variable
Fixes an issue where a variable was used without being correctly
set by other parts of the code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-07-10 09:26:19 +02:00
Dawid Niedzwiecki 40924edec2 mgmt: ec_host_cmd: fix checking command version
The sizeof is used in a wrong way which causes incorrect checking a
version of a command. Use NUM_BITS instead.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-07 09:22:13 +02:00
Dawid Niedzwiecki 521f0ba4f8 mgmt: ec_host_cmd: clear response buffer every command
The response buffer has to be cleared every command not to pass
unintended content e.g. response from a previous command, or stack
content.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-07 09:22:13 +02:00
Dawid Niedzwiecki f2d6e0f660 mgmt: ec_host_cmd: set max response every command
Update the response buffer size, passed to a command handler, every
command, since a backend could change it in runtime.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-07-07 09:22:13 +02:00
Matthias Breithaupt 04ce5b9e58 mgmt: hawkbit: remove NET_SOCKETS_POSIX_NAMES dependency
Currently, it is not possible to use hawkbit with code that requires
POSIX_API to be set due to the dependency on NET_SOCKETS_POSIX_NAMES.
Since a lot of other code has already been moved to `zsock_`, this
commit does the same for hawkbit.

Co-authored-by: rojedag <r.ojeda@vogl-electronic.com>
Signed-off-by: Matthias Breithaupt <m.breithaupt@vogl-electronic.com>
2023-06-28 06:32:45 +00:00
Dawid Niedzwiecki c8c149dce8 mgmt: ec_host_cmd: add logging system
Add a native way to log Host Command communication.

Use Zephyr logging system to do it. Use debug and normal levels.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-06-26 16:13:42 +02:00
Dawid Niedzwiecki 159f56d57e mgmt: ec_host_cmd: use one command to send response
Use one common function to send Host Command response. It allows
handling all response types within one function.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-06-26 16:13:42 +02:00
Marek Pieta 6bbd6d3794 mcumgr: img_mgmt: Fix unused "status" variable warning
Changes aligns ifdefs to fix compilation warnings related to unused
"status" variable.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2023-06-26 12:31:05 +00:00
Jamie McCrae 6877ad413f mgmt: mcumgr: smp: Allow preventing command execution via hook
Adds status checking to the command status hook which allows an
application to inspect a request and, optionally, reject it.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-21 13:24:12 +02:00
Jamie McCrae 0b6077443d mgmt: mcumgr: grp: img_mgmt: Add optional mutex lock support
Adds an optional Kconfig that adds mutex locks to image management
group functions, this prevents collision between multiple threads
and/or transports.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-21 13:24:01 +02:00
Jamie McCrae 3e71797ba2 mgmt: mcumgr: grp: img_mgmt: Fix missing define
Fixes a missing define which causes a build failure.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-20 15:14:19 +02:00
Daniel Leung cacefd4c33 mgmt: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Jamie McCrae 1edc8cc762 mgmt: mcumgr: grp: img_mgmt: Fix using signed values
Fixes wrongly using signed values for slot and image number when
listing images.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-14 13:47:08 -04:00
Jamie McCrae 5f9737f482 mgmt: mcumgr: fs_mgmt: Fix duplicate bool ok variables
Fixes wrongly declaring duplicate local variables that already
exist and hiding the previous variables definitions.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-13 07:10:43 -04:00
Jamie McCrae 942fc8517f mgmt: mcumgr: grp: fs_mgmt: Fix unchecked return value
Fixes a coverity issue whereby a return value was not checked.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-05 07:06:37 -04:00
Dawid Niedzwiecki 53525bb9c5 mgmt: ec_host_cmd: add support for IN_PROGRESS status
The IN_PROGRESS status is a specital status that can be sent during
handling a host command. Synchronous backends don't support it, so
an additional check is required.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-26 13:51:30 -04:00
Dawid Niedzwiecki 66d8e27c34 mgmt: ec_host_cmd: add a function to send response
A function to send Host Command response is needed for commands that
that sends IN_PROGRESS status or doesn't return e.g. perform reboot.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-26 13:51:30 -04:00
Dawid Niedzwiecki a2b9c56ee5 mgmt: ec_host_cmd: fix checking usage of handler buffer
The usage of RX handler buffer was checked incorrectly.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-26 13:51:30 -04:00
Jamie McCrae d2eed56f4f mgmt: mcumgr: grp: os_mgmt: Fix issue and add xtensa
Fixes an issue with a missing else as part of a condition and adds
xtensa.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-26 15:05:29 +02:00
Jamie McCrae c052a9f4eb mgmt: mcumgr: Disable legacy Kconfigs if legacy mode is disabled
It does not make sense to control configuration of legacy
options if legacy mode is diabled.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-26 15:05:29 +02:00
Jamie McCrae 7225ba0788 mgmt: mcumgr: grp: os_mgmt: Change select to imply for reboot
OS management's reset is optional, therefore only imply reset
instead of selecting it, so it can optionally disabled if not
needed.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-26 15:05:29 +02:00
Jamie McCrae aff663dd2f mgmt: mcumgr: smp: Expand ver to version and limit version
Expands a bitfield name from nh_ver to nh_version so it is more
obvious what it is. Also changes the version that goes into the
response to indicate what the maximum supported version of the
protocol is for a device

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-26 15:05:29 +02:00
Jamie McCrae 7e23e73bc1 mgmt: mcumgr: transport: udp: Rework transport
This reworks the UDP transport to resolve some issues with object
interactions and streamlines the code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-26 10:22:42 +02:00
Dominik Ermel 9cc6a7f060 mgmt/MCUmgr/grp/img: Fix possible missing failure check
No reason to continue zcbor encoding of slot information for image
list when already failed at encoding version.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-26 10:21:53 +02:00
Dominik Ermel 2f53e7af43 mgmt/MCUmgr/grp/img: DirectXIP flag pending slot as permanent
Image list should also flag pending slot as permanent.
This follows the image list for swap configuration where slot
confirmed for next boot is marked as permanent.
The difference is that in DirectXIP mode it is still possible
to erase slot marked as pending and permanent, before restart
happens.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-26 10:21:28 +02:00
Dominik Ermel 1847540663 mgmt/MCUmgr/grp/img: Remove leftover header img_mgmt_impl.h
The header has been replaced with img_mgmt_priv.h.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-26 10:21:05 +02:00
Jamie McCrae 0cce365c4f mgmt: mcumgr: fs_mgmt: Add other access hooks and minor fixes
Adds callback checks to other fs_mgmt group file access functions
which allows for file access control, and moves where the callback
is triggered for uploads and downloads to prevent getting the
callback multiple times for the same file. The callback struct has
been modified so applications using the previous signature will
need to be updated.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-26 10:20:39 +02:00
Jamie McCrae 56f66334b0 mgmt: mcumgr: grp: fs_mgmt: Fix cmake selection
Fixes an issue whereby mbedtls will not be included if tinycrypt
is included in the build.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-23 18:00:53 +02:00
Jamie McCrae 2e4c3f1da9 mgmt: mcumgr: grp: fs_mgmt: Change insecure warning
Changes the warning from being text in Kconfig for filesystem
management as a whole to being a cmake warning which is displayed
if the user has not enabled file access hooks with a link to the
documentation on how to set them up.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-23 16:36:38 +02:00
Jamie McCrae 1d6ee8da5f mgmt: mcumgr: Change from mcumgr to MCUmgr
Fixes the name of the system.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-23 16:36:38 +02:00
Dawid Niedzwiecki aa0c0727b4 mgmt: ec_host_cmd: add config to create a dedicated thread
Add a config to decide if a new dedicated thread for Host Command is
created during initialization.

If not, the ec_host_cmd_task has to be called by another thread to
handle host commands.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-23 16:19:53 +02:00
Jamie McCrae ea6d326ab4 mgmt: mcumgr: grp: img_mgmt: Remove unused file
Removes a file that provided unimplemented and unused functions.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-22 12:25:05 +02:00
Jamie McCrae fbd5415ca2 mgmt: mcumgr: grp: fs_mgmt: Fix not checking offset
Fixes an issue whereby the user supplied offset was not checked if
it was provided or not.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-22 12:24:48 +02:00
Jamie McCrae c95b8ff831 mgmt: mcumgr: grp: img_mgmt: Remove useless hash variable
Removes a hash variable that was set then never used.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-22 12:21:41 +02:00
Gerard Marull-Paretas 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: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Jamie McCrae a476eeb8ec mgmt: mcumgr: grp: os_mgmt: Use new error for invalid format
Uses the new error system to report an error if the user provides
an invalid format for the OS info command.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-18 13:31:19 +02:00
Dawid Niedzwiecki 7efc8938eb mgmt: ec_host_cmd: update checking the handler buffer
The general handler may provide buffers for a backend. Use ranges to
check if the provided buffer is used, because the backend may shift the
beginning of the buffer to make space for preamble.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-18 09:46:37 +02:00
Dawid Niedzwiecki 0a17aa8605 mgmt: ec_host_cmd: add autoinit config
Add a separate config to enable autoinitialization of the host command
subsystem, called by the chosen backend.

It allows setting the chosen backend without autoinit.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-18 09:46:37 +02:00
Dawid Niedzwiecki 4064a41ce2 mgmt: ec_host_cmd: follow clang format
Edit some source files to follow the clang format.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-18 09:46:37 +02:00
Dawid Niedzwiecki 3d8a5c7e5c mgmt: ec_host_cmd: make host command structure available
The application code may need inside information about the host command
e.g. the thread id. Add a function that returns the main host command
structure which contains such data.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-18 09:46:37 +02:00
Dominik Ermel ac38411e2e mgmt/MCUmgr/grp/img: Rework image list to support DirectXIP
Image list will only report active flag for active image and pending
flag for other slot, but only if image in that slot has higher
version than currently running image.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-17 09:47:54 +02:00
Jamie McCrae f59b857f6a mgmt: mcumgr: smp: Convert functions to function pointer array
Converts the list of functions for registering an MCUmgr SMP
transport from function arguments to a single list which contains
the function pointers.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-15 10:23:35 +02:00
Jamie McCrae 6f5b974949 mgmt: mcumgr: Add command result codes (ret)
Adds a new map to responses that command handlers can use to
return result codes of functions themselves, unrelated to SMP
error codes. This is achieved by adding an optional "ret" map
which contains a 16-bit "group" and 16-bit "rc" error code,
this map will not be included if the "ret rc" is 0 (which
implies success).

In order to allow this, a new version of the protocol has been
which can be indicated for use by setting a bit in the header.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-15 09:27:16 +02:00
Dawid Niedzwiecki 65bd27246f mgmt: ec_host_cmd: fix node chosen strings
Update the backend device node chosen strings.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-05-15 09:16:53 +02:00
Dominik Ermel a763454c0b mgmt/mcumgr/grp/img: No MCUboot flags setting in DirectXIP
It is no longer possible to select image for test or confirm
when MCUboot has been configured for DirectXIP.
MCUboot flags, in image trailer, are now ignored in DirectXIP
mode allowing to use entire slot for image upload.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-12 10:00:23 +02:00
Dominik Ermel 0a5c4aba52 mgmt/mcumgr/grp/img: No upload for MCUboot in single app mode
Image management is now disabled by default if MCUboot
is configured for single application mode.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-12 10:00:23 +02:00
Dominik Ermel 87efe30b3a mgmt/mcumgr: Use boot_set_next to set image for test or confirm
The commit adds img_mgmt_set_next_boot_slot function which uses
boot_set_next, from MCUboot/bootutil, to set application slot
for next boot.
The img_mgmt_set_next_boot_slot is intended to replace
img_mgmt_state_confirm and img_mgmt_state_set_pending.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-12 10:00:23 +02:00
Dominik Ermel 2244974dd6 mgmt/mcumgr: Add img_mgmt_active_slot() and img_mgmt_active_image()
The commit adds img_mgmt_active_slot() which allows to get
active (running) slot for given application image.
Added img_mgmt_active_image() allows to get number of image running
on current MCU core.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-05-12 10:00:23 +02:00
Georges Oates_Larsen 716c19f7ef net: conn_mgr: Reorganize files
Since conn_mgr is a subsystem rather than a library, relocate it
directly into subsys/net rather than subsys/net/lib/

Rename header files to better match their function.

Remove net_ prefix from conn_mgr types, API, and files, since it is
unnecessary.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2023-05-11 12:15:44 +02:00
Jamie McCrae aaed91ec4f mgmt: mcumgr: grp: img_mgmt: Only verify image if hash is valid
Prevents verifying the image has been uploaded successfully using
the hash provided at the start of the upload if the hash is not
the correct length of an SHA256 hash.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-05-09 14:29:05 +02:00
Marek Pieta 8df81737e0 mcumgr: img_mgmt: Let image version comparison use build number
Change allows using build number in image version comparison.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2023-05-08 09:59:19 +02:00
Marek Pieta ce18ed05d1 mcumgr: img_mgmt: Fix check for upgrade-only
Change fixes check for upgrade-only to ensure that the the new image
version is greater than version of the currently running image.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2023-05-08 09:59:12 +02:00
Nikolay Agishev 0d8292ab6b ARC: Add HS4x support
Minimal HSDK4xD support

Signed-off-by: Nikolay Agishev <agishev@synopsys.com>
2023-05-02 16:54:24 +02:00
Dominik Ermel 00f1639e38 mgmt/mcumgr: Fix image erase returning MGMT_ERR_EMSGSIZE
In case when CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR=n then
the image erase command would incorrectly return MGMT_ERR_EMSGSIZE,
even though no such error occurred.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-04-26 18:15:40 +02:00
Dominik Ermel 783f8666fc mgmt/mcumgr: Add zcbor_map_decode_bulk_reset utility function
The function should be used to reset map decoding state
between calls to zcbor_map_decode_bulk, while using the same map
for different buffers.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-04-24 13:28:49 +02:00
Dominik Ermel 4878eebebb mgmt/mcumgr: Add missing initialization of internal state
There was missing initialization for found member of
zcbor_map_decode_key_val structure.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-04-24 13:28:49 +02:00
Dominik Ermel a48e6b926c mgmt/mcumgr: Fix failure to confirm active image not reported
Due to broken logic in img_mgmt_state_confirm failure to confirm
was not reported to caller.
If hooks were enabled confirmation event would be passed regardless
whether it has been successful.

Fixes #56617

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-04-24 13:28:09 +02:00
Jamie McCrae c8a0e8c598 mgmt: mcumgr: grp: img_mgmt: Remove dummy header
The dummy header was an opt-in feature to allow testing without a
real image but since we support testing on Qemu in CI which
supports flash partitions, there isn't a need for this option. Not
being deprecated as Kconfig would only have been used as part of
CI, not user applications.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-21 16:33:30 +02:00
Dawid Niedzwiecki 7f7e48e66e mgmt: ec_host_cmd: create chosen string per backend
Create strings to set the chosen node per backend. It is done for
better clarity.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-04-21 16:29:59 +02:00
Dawid Niedzwiecki 1d62002bba mgmt: ec_host_cmd: update configs naming
Just use better namings for the buffer sizes configs.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-04-21 16:29:59 +02:00
Dominik Ermel d4ab079cd9 mgmt/mcumgr: Add zcbor_map_decode_bulk_key_found utility function
Function allows to check whether given key has been found
during map decoding with zcbor_map_decode_bulk.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-04-21 16:28:34 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Andrei Emeltchenko 37575def5f mgmt: Fix comparing usigned < 0
Fix type from size_t to ssize_t.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-04-13 11:05:47 -04:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Jiapeng Li 9d47a3f6d9 mgmt: mcumgr: grp: fs_mgmt: set .upload flag in file_access_data
minor fix, set .upload true if uploading

Signed-off-by: Jiapeng Li <mail@jiapeng.me>
2023-04-12 14:25:14 +02:00
Siddharth Chandrasekaran cd116b22b5 mgmt/osdp: Clear secure channel base key from stack
Secure Channel Base Key (SCBK) is a secret key used to derive the session
keys used to encrypt and decrypt OSDP packets. Secure coding practice
requires us to clear such sensitive data from stack once we are done
needing it. This patch addresses this issue.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-04-07 13:26:36 +02:00
Siddharth Chandrasekaran 814433d433 mgmt/osdp: Make sure we decrypt atleast one block
OSDP secure channel message blocks are terminated with a 0x80. This means
that even for zero length messages, we would have at least one block of
encrypted data to decrypt (since message blocks are rounded up to the next
16 byte boundary). The current length assertion checks for 16 byte
alignment but a malicious peer could send a specially crafted packet with
zero length blocks. Fix this issue by adding check for length == 0 case.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-04-07 13:26:36 +02:00
Siddharth Chandrasekaran 0effd82b7a mgmt/osdp: discard secure channel if KEYSET is ACKed in plaintext
HID readers are responding to a KEYSET command with an ACK in plaintext
instead of using the current session keys to acknowledge this command
(which is the reasonable thing to do as the command itself was received
encrypted with the old key). Since the spec doesn't say anything about
this, both methods are technically correct.

Make changes to CP so it allows ACKs in plaintext for KEYSET command in
particular and make the PD implementation do this too as it makes the code
look cleaner there (perhaps HID did it for the same reasons :D).

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-04-07 13:26:36 +02:00
Siddharth Chandrasekaran a1edd3e74d mgmt/osdp: phy: Allow non-conformant, 0 length, encrypted data blocks
If command or reply has no data, PD "should" use secure message types
SCS_15 or SCS_16. But some PD seem to not implement this correctly. We
will be tolerant towards those faulty implementations.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-04-07 13:26:36 +02:00
Siddharth Chandrasekaran 1648e86f4b mgmt/osdp: Rework secure channel key management
OSDP command KEYSET is used to set the secure channel base key for all
connected PDs. This key is then used to derive the session keys for each
secure channel session. When the app wants to set the this key, it has
to issue a command and then both the CP/PD has to be notified of this
change so they can store this key in a non-volatile medium for future
operations across power cycles.

The current implementation of OSDP had limited support for key
management. This patch adds all the bells and whistles needed to handle
keyset command/event in the CP/PD application.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-04-07 13:26:36 +02:00
Siddharth Chandrasekaran 431cac80f4 mgmt/osdp: sc: Restructure loop to avoid a bunch of -1s
Hoisting a `length--` helps simplify a lot of code which has ad-hoc -1s
in a  bunch of places. Also, fix some formatting issues and remove
unnecessary log lines.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-04-07 13:26:36 +02:00
Dawid Niedzwiecki 4ef47888ef ec_host_cmd: add UART backend
Add a new backend for Host Commands that uses UART. The backend bases
asynchronous UART API.

The UART backend is mainly used by FPMCU.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-04-07 13:05:59 +02:00
Dawid Niedzwiecki 7490adcd2a ec_host_cmd: update Kconfig help message
The help messages for max request/response SHI sizes were adjusted only
for NPCX, update it.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-04-07 13:05:59 +02:00
Pieter De Gendt 6b532ff43e treewide: Update clock control API usage
Replace all (clock_control_subsys_t *) casts with (clock_control_subsys_t)

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-05 10:55:46 +02:00
Jamie McCrae e00cf28001 mgmt: mcumgr: grp: fs_mgmt: Improve upload and download performance
This vastly increases the performance of file transfers using the
fs_mgmt group over MCUmgr by allowing the file handle to remain open
between commands instead of having to open, feek, read/write then
close the file handle for each invocation.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-04-04 11:51:43 +02:00
Dominik Ermel fcef8bb781 mgmt/mcumgr/img_mgmt: Fix upgrade accepting equal version
As name suggest upgrade only should allow image upgrades onlu, but due
to greater or eqal sign used in version comparison, upgrade actually
also accepted current version.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-29 11:31:19 +02:00
Jamie McCrae 0cf14d5ae9 mgmt: mcumgr: transport: shell: Add optional input expiration
Adds an optional feature that can be used to time out a partially
received MCUmgr packet over the shell interface. Prior to this
change, if a header was received, then the whole shell would be
unavailable until the module is rebooted or additional full MCUmgr
packet was sent.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-29 11:30:55 +02:00
Joel Guittet b6df4ec388 hawkbit: check mcuboot header version
Checking mcuboot header version prior to use the content of the header
structure.

Signed-off-by: Joel Guittet <joelguittet@gmail.com>
2023-03-21 09:35:26 +01:00
Joel Guittet a3d7fdafd6 hawkbit: fix memory issue with mcuboot_img_header size
Fix a memory issue when calling boot_read_bank_header the length should be
the size of `struct mcuboot_img_header`.
Fixes #54459.

Signed-off-by: Joel Guittet <joelguittet@gmail.com>
2023-03-21 09:35:26 +01:00
Jamie McCrae 533e312359 mgmt: updatehub: Change Kconfig select to depends on
Changes Kconfig symbols to depend on symbols rather than selecting
them, this avoids a cmake dependency loop.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-03 10:49:32 +01:00
Jamie McCrae 31201a7f61 mgmt: hawkbit: Change Kconfig select to depends on
Changes Kconfig symbols to depend on symbols rather than selecting
them, this avoids a cmake dependency loop.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-03 10:49:32 +01:00
Dawid Niedzwiecki 2d0a784c41 subsys/mgmt/ec_host_cmd: rework Host Command support
Rework the Host Command support. It includes:
-change API to backend
-change a way of defining rx and tx buffers
-fix synchronization between the handler and backend layer
-simplify the HC handler

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-02-28 10:42:23 +01:00
Dawid Niedzwiecki b2674a4b34 subsys/mgmt/ec_host_cmd: rename peripheral to backend
Follow naming pattern in the subsystems(logging or shell) and name
the layer between generic handler and peripheral driver "backend".

The name doesn't suit that well to the SHI backend, because there isn't
SHI API itself and the SHI interface is used only for the host
communication. So the backend code includes the peripheral driver itself.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-02-28 10:42:23 +01:00
Dawid Niedzwiecki e734adfb78 subsys/mgmt/ec_host_cmd: update directory structure
The Host Commands can be used with different transport layers e.g. SHI
or eSPI. The code that provides the peripheral API and allows sending
and receiving Host Commands via different transport layers is not
actually drivers of a peripheral, so move it to the
subsys/mgmt/ec_host_cmd folder.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2023-02-28 10:42:23 +01:00
Siddharth Chandrasekaran 011e784844 mgmt/osdp: More error handling and other cleanups
cp_build_command returns the length of the built packet and early
returns for errors. This means there is no need to keep track of return
code in a separate variable -- if we reached the end, we succeeded.

Along with this change, some more changes to enhance maintainability and
readability are also done.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-02-20 11:29:23 +01:00
Siddharth Chandrasekaran 20f806de4e mgmt/osdp: cp: Rework CP state management
With changes to the phy layer and the way we build and dispatch
commands, we can now simplify some parts of CP state machine. This patch
builds on previous patches to reduce some state transitions and fixes
some bugs in those paths.

While at it, also implement an exponential back-off for PD offline after
a timeout. This is useful when there is a transient PD timeout but the
PD itself is not totally dead.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-02-20 11:29:23 +01:00
Siddharth Chandrasekaran d92c2e4ba1 mgmt/osdp: pd: Rework state machine to handle multiple packets
After the check_packet() split from decode_packet() for handling multiple
packets in the RX buffer, PD state machine needed to me modified to
start handling it correctly. While at it, simplify the states as PD does
not have as much state anyways.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-02-20 11:29:23 +01:00
Siddharth Chandrasekaran 062a45ef35 mgmt/osdp: cp: Split build_packet and send_command
The method send_command was building the packet and also sending it.
This is a problem because even command build failures are reported as
command send failures; although the former can be mitigated by changing
kconfig parameters depending on use cases.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-02-20 11:29:23 +01:00
Siddharth Chandrasekaran ec53f2f6a8 mgmt/osdp: phy: Move packet checks out of decode_packet
To handle multiple packets in RX buffer, we need to perform checks on
the buffer first and determine the length of one packet and extact only
that many bytes from the RX buffer instead of pulling everything at
once and failing if there are bytes from the next packet in the buffer.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-02-20 11:29:23 +01:00
Siddharth Chandrasekaran b0cf5163d8 mgmt/osdp: cp: Move set PD online status to a method
When a PD is set online, we need to do other actions along with it. To
make this easier in future, move cp_set_state(pd, OSDP_CP_STATE_ONLINE)
to it's own method cp_set_online(pd).

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-02-20 11:29:23 +01:00
Jamie McCrae 1b4b979f87 mgmt: mcumgr: Change select to depends on in Kconfigs
Select in Kconfig causes many issues with dependency loops, this
resolves the issue by replacing most select with depends on for
MCUmgr, including updates to the sample smp_svr application and
tests.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-02-20 11:27:43 +01:00
Siddharth Chandrasekaran ac9510230b mgmt/osdp: Use memcpy instead of raw loops in many places
This patch replaces many instances where raw loops were used to copy bytes
with memcpy calls.

No functional change intended.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran 4386dc355b mgmt/osdp: pd: Fix device capabilities report
Do not check or send the first entry in the pd->cp[] device capability
table which is for function code 0 which is not a defined function code.

Signed-off-by: David Vucich <dave@alcatraz.ai>
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran 39bf1264e9 mgmt/osdp: pd: Fix error reply code for CMD_KEYSET
By default, on errors, pd_decode_command replies with osdp_NAK with
sub-error code set to OSDP_PD_NAK_CMD_LEN (achieved using the ret ==
OSDP_PD_ERR_GENERIC check before return). This is works for all packet
framing errors; but when a more specific error code needs to be sent, ret
has to be set to something other than OSDP_PD_ERR_GENERIC (a suitable error
code happens to be OSDP_PD_ERR_REPLY) to prevent the tail check from
overwriting the error info.

In CMD_KEYSET, we fill a more specific error code but do not set the ret to
OSDP_PD_ERR_REPLY. It causes this error to be reported as a framing
error hence loosing some extended info about the error. Fix this issue by
reordering the checks a bit.

Fixes: 7f4d2c741b "mgmt/osdp: Add support for Secure Channel"
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran 7f70d5e0e0 mgmt/osdp: Remove unused STR() macro
Initially, subsys/mgmt had its own STR() macro for string pasting which was
replaced with the zephry provided STRINGIFY(). The definition of this macro
seems to have lingered on so remove it.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran 514ccabc44 mgmt/osdp: phy: Catch out-of-order SC packets and fail
During handshake, only certain types of secure block types (<= SCS_14)
are allowed. A rouge CP/PD can try to bypass the handshake by directly
sending a secure block type ahead of the sequence and gain a secure
channel. Fix this by adding a check in packet decode time.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran a233dea285 mgmt/osdp: phy: Rework MARK byte handling
OSDP specification section 5.7 states that a transmitting device has to
drive the transmission line to a marking state for a period of one char
in the current baud rate. This can be achieved by sending 0xFF. Since
this is not mentioned in the packet structure definition, many commercial
implementations of OSDP out in the wild do not send/expect this byte.

To work with such non-conforming devices, we will try to be as flexible
as possible in the PD: send mark byte only if the other side sent one. In
case of CP, we have no option but to send the mark byte to be as close
to the specification as possible. If a particular use case needs the CP
to not send it, we will provide a Kconfig option to disable it.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran d44bdb50f0 mgmt/osdp: pd: Add support for key press and card read events
Now that we have the necessary infrastructure to collect events from PD
apps, we can use them to translate it to OSDP packet sequence for card
reads and key press events.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran c9e64e0dd9 mgmt/osdp: pd: Add capability checks on incoming commands
OSDP compliant devices communicate their capabilities and discover what
their peer can and cannot do. Right now, PD advertises these capabilities
and expects CP to honor them. Although this is not known to cause any
issues, it is not desirable to allow such accesses.

Add a check of incoming commands to to validate that the corresponding
capability was enabled and advertised.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Siddharth Chandrasekaran a369bf7f08 mgmt/osdp: Rename cmd_data as ephemeral_data
Since cmd_data member is used by both commands and events to store the
contents of current transaction, rename it to ephemeral_data which
better reflects the purpose of the variable.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-27 20:28:34 +09:00
Jamie McCrae 4516e7161c mgmt: mcumgr: transport: smp_bt: Fix wrongly enabling Bluetooth
Bluetooth does not need to be enabled to register services,
therefore the newly introduced automatic bluetooth SMP transport
registration system can be simplified by returning enabling of
bluetooth back to the application.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-26 12:36:16 +00:00
Gerson Fernando Budke eb9460ce5e mgmt: updatehub: Add no memory check at cmd_info
The updatehub shell cmd_info allocate memory but not checks function
return. This add missing checks and proper error handle.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-23 10:24:07 +00:00
Gerson Fernando Budke 647c48c574 mgmt: updatehub: Add userspace syscalls
The current updatehub version forces user application to run in kernel
mode. This add necessary api syscalls to isolate userspace from kernel.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-23 10:24:07 +00:00
Gerson Fernando Budke 000257dad0 mgmt: updatehub: Move updatehub.h to header directory
This moves updatehub.h file from subsys to public header include
folder.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-23 10:24:07 +00:00
Gerson Fernando Budke 22e0a1faa6 mgmt: updatehub: Preparation to move public api
This prepares updatehub.h file to be moved to the public header
directory.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-23 10:24:07 +00:00
Jamie McCrae df0fa6d965 mgmt: mcumgr: Add logging output
Adds logging to mcumgr commands for debug and error reporting

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-20 11:57:59 +01:00
Dominik Ermel 718be64e14 mgmt/mcumgr: Don't add unused slots in img_mgmt_flash_area_id
The img_mgmt_flash_area_id would add processing of
slot2_partition and slot3_partition if they only exist, even if
not used at all.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-01-17 21:49:46 +00:00
Jamie McCrae 571273b78c mgmt: mcumgr: Change transport select to depends on
This changes some of the MCUmgr transport CMake select statements
to depends on, this is to align with other in-tree symbols that
do not pull in whole subsystems and instead only allow selection
if those subsystems are already enabled.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-16 10:04:45 +01:00
Guillaume Lager e67e6d5af6 mcuboot: Remove public dependency on bootutil
BOOT_MAGIC_SZ and BOOT_MAX_ALIGN were used in the header without
including bootutil/bootutil_public.h. This change remove the need of
the inclusion by making the dependency private.
Fixes #52095

Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
2023-01-12 19:08:23 +01:00
Gerson Fernando Budke ff6b526a14 mgmt: updatehub: Add storage abstraction
This add storage abstraction to allow switch between different flash
APIs. This remove the erase command at updatehub core and move it to
storage init phase.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-12 12:11:31 +01:00
Gerson Fernando Budke eb39f1f12e mgmt: updatehub: Clean-up mcuboot & system dependencies
Currently MCUboot and system reset are invoked directly in the sample
applicatiion. This introduce 2 new methods to isolate system from
application.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-12 12:11:31 +01:00
Gerson Fernando Budke 689d7cb085 mgmt: updatehub: Clean-up firmware headers
Move header includes to source file. Currently firmware source files
have a hardcode partition identificator. This moves identificators
to updatehub core.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-12 12:11:31 +01:00
Gerson Fernando Budke f3159e3885 mgmt: updatehub: Clean-up device headers
Move headers from header includes to source file.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-12 12:11:31 +01:00
Siddharth Chandrasekaran 73809472f8 mgmt/osdp: Add support for event delivery and notifications
The CP app sends PD a "command" and the PD responds to it. Some times,
the PD has something that it wants to tell the PD which it does so in
response to POLL command. Both CP and PD apps need a way to exchange
these info over the OSDP bus. To archive this we will introduce what are
called "events" that allow the PD app to enqueue and CP app to get
notified.

This is analogous to the incumbent "commands" abstraction where, the CP
app enqueues a command and the PD app gets notified of it.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-12 12:04:11 +01:00
Siddharth Chandrasekaran c7fec71193 mgmt/osdp: Add length checks for commands and replies
For all commands and replies, the buffer length needed to build or the
length of data needed to decode needs to be checked and asserted. Right now
we do this by ad-hoc if-s. Add macros that do this at a common location.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-12 12:04:11 +01:00
Siddharth Chandrasekaran f4e3f2b828 mgmt/osdp: Add inline methods for flag checks
The raw, flags check has become a bit excessive and has begun to affect
code readability. Provide inline functions for those accesses that are
frequent. Also, get rid of `struct osdp_cp` as it can be fully represented
by `struct osdp` itself.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-12 12:04:11 +01:00
Siddharth Chandrasekaran b31e708c03 mgmt/osdp: Rename pd offset as index
CP has an array of PDs and pd->offset was the position of the PD in CP's
list. Since offset has many meanings, rename it to pd->idx.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-12 12:04:11 +01:00
Siddharth Chandrasekaran 059abd8d8b mgmt/osdp: Flush RX buffer before sending data
Partial packets in the RX buffers cause the subsequent packet to be
treated as malformed. The RX buffer can have partial data if the sender
is too slow in sending the packet of if there is an interruption in
transmission mid-way.

To avoid any issues due to such partials, flush the uart channel before
sending the command/response.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-12 12:04:11 +01:00
Siddharth Chandrasekaran a1f3c7631f mgmt/osdp: Cleanup log messages and return codes
The log lines in CP and PD had a prefix such as "CP: " and "PD: " that
does not add too much value as a given device an either be CP or PD
only. This patch removes those and enhances some other log lines while
at it.

It also adds a enum for return values throughout the module to improve
code quality.

Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
2023-01-12 12:04:11 +01:00
Michał Barnaś 3ae105e76b ec_host_cmd: add NPCX SHI peripheral for the host commands
This commit adds the support for host commands being transported
by the Serial Host Interface on the NPCX SoC.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-01-11 09:38:45 +01:00
Jamie McCrae b8ef838069 mgmt: mcumgr: Select console if using UART transport
This prevents a configuration error by selecting the console if
the UART MCUmgr transport is used, which is actually a dependency
for this transport.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-10 13:49:17 +01:00