Commit graph

658 commits

Author SHA1 Message Date
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
Jamie McCrae d0e421225a mgmt: mcumgr: callbacks: Fix not checking event ID properly
Fixes an issue whereby event ID was not checked properly, meaning
that OR'd events would not work as one would expect.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-09 17:36:04 -08:00
Gerson Fernando Budke 313049e325 mgmt: updatehub: Rework check integrity
The TinyCrypt is the current library used by UpdateHub to perform
SHA-256 integrity check. This refactor code and add support to
mbedTLS library. It changes default library to mbedTLS to use
hardware accelerator when available.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-09 15:24:10 +00:00
Jamie McCrae b64ea89ed5 mgmt: mcumgr: img_mgmt: Fix mismatched slot missing variable
Fixes an issue with a missing variable when
CONFIG_IMG_MGMT_REJECT_DIRECT_XIP_MISMATCHED_SLOT is enabled.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-24 16:58:11 +01:00
Dominik Ermel 671625cd0c mgmt/mcumgr: Add Kconfig option naming notes
The commit adds Kconfig option naming notes to Kconfig
files of MCUmgr subsystem.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-22 12:36:34 +01:00
Dominik Ermel c7378d0d84 mgmt/mcumgr: Move Kconfig options to proper Kconfig files
After Kconfig options got renamed, some of the no longer fit
to files they have been defined in.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-22 12:36:34 +01:00
Dominik Ermel db34adf9c3 mgmt/mcumgr: Standardise MCUmgr Kconfig names
Standardise Kconfig options for MCUmgr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-22 12:36:34 +01:00
Jamie McCrae 23ca3841db mcumgr: img_mgmt: Add SHA256 image upload hash check
Will check an uploaded image's hash against the hash that was
originally supplied before the upload began and return the result to
the client to know if the upload was successful or if there was an
error during upload. Requires CONFIG_IMG_ENABLE_IMAGE_CHECK be
enabled for functionality to be available.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-22 11:08:49 +01:00
Jamie McCrae b4b6346cdc mgmt: mcumgr: Make Bluetooth and UDP transport init automatic
This moves the UDP and Bluetooth initialisation for MCUmgr to be
performed automatically with the new hander registration feature.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-22 11:03:04 +01:00
Jamie McCrae 541fcb884d mgmt: mcumgr: Make handler registration functions static
Makes group registration functions for MCUmgr handlers static as
they are registered automatically at startup.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-22 11:03:04 +01:00
Jamie McCrae d7557102c0 mgmt: mcumgr: Add iterable section to register MCUmgr handlers
This replaces the requirement for applications to manually
register MCUmgr handlers by having an iterable section which
then automatically registers the handlers at boot time.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-22 11:03:04 +01:00
Jamie McCrae b4c2b57f1b mgmt: mcumgr: Make returning rc responses when status is OK legacy
This change changes the previous mcumgr behaviour of return result
codes when the status is 0 (OK) to being legacy behaviour, instead
it will skip the rc field for these responses. If there is only an
rc field with status 0 to return, then mcumgr will now instead just
return an empty map.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-20 11:57:22 +01:00
Jamie McCrae 95697b5fcf mgmt: mcumgr: Replace non-zephyr cmake functions with zephyr versions
This fixes an issue whilst investigating using iterable sections,
which cannot be used when the non-zephyr prefixed functions are
used. It also resolves a possible critical bug intoduced with the
MCUmgr rework whereby functions or elements seem to have silently
dropped.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-19 13:02:32 +01:00
Dominik Ermel 72db5c09c0 samples/smp_svr: Switch to ZCBOR_MAP_DECODE_KEY_DECODER
Swithc zcbor_map_decode_bulk to use ZCBOR_MAP_DECODE_KEY_DECODER
macros.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-13 11:42:02 +01:00
Dominik Ermel 550b6d518d mgmt/mcumgr: zcbor_bulk: Allow spaces in map keys
The CBOR encoding allows strings to have white spaces, and as string
may be used as key it should also be allowed to use space in key.
The commit provides ZCBOR_MAP_DECODE_KEY_DECODER macro, which is
intended to replace ZCBOR_MAP_DECODE_KEY_VAL macro, that allows
to use string keys with spaces in it.
Both macros are available for now.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-13 11:42:02 +01:00
Jamie McCrae 5d8c79f064 mgmt: mcumgr: transport: dummy: Fix issue with large packets
Fixes an issue with large packets being received, these packets are
chunked into 127-byte frames for the serial transport but this system
is not needed for the dummy transport as it has a fixed size buffer.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-07 13:53:02 +00:00
Jamie McCrae 656a910b1e mgmt: mcumgr: lib: cmd: os: Add device information handler
The device information handler can be used to retrieve information about
the configuration of the configured device such as board name, board
revision, firmware version and build date.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-07 13:53:02 +00:00
Dominik Ermel 6ae861f559 mgmt/mcumgr: Remove APP_LINK_WITH_MCUMGR Kconfig option
This option is not actually doing anything.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-05 17:22:51 +01:00
Dominik Ermel 9a48fdf62f mgmt/mcumgr: Remove redundant config headers
The shell_mgmt_config.h and stat_mgmt_config.h as they have been only
providing alternative identifiers for Kconfig options.
Now the Kconfig options are directly used in code and the headers
have been removed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-05 15:22:27 +01:00
Anas Nashif cffe98d9de crc: Make the build of crc function dependent on a Kconfig
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.

Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.

Partial fix for #50654

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-23 13:30:00 +01:00
Jamie McCrae 9831b320f2 mgmt: mcumgr: Fix missed variable rename
Fixes accesses a renamed variable when a specific Kconfig is
active that would cause a compile error.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-23 12:24:59 +01:00
Jamie McCrae 0922ec7d75 mgmt: mcumgr: Move zephyr basic group defines to standard files
Moves the zephyr group ID defines to the mgmt header file as it is
with other group IDs and moves the zephyr basic group command IDs
to the the same header-location style as other groups.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-22 12:42:48 +09:00
Jamie McCrae 4cf008cb45 mgmt: mcumngr: Remove old files missed in restructure
Removes some old files that should have been deleted in the recent
cleanup of MCUmgr.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-22 12:42:09 +09:00
Jamie McCrae cbd0d2d55a mgmt: mcumgr: Add fs_mgmt prefix to hash/checksum functions/files
This aligns the naming of files in fs_mgmt so that files and
functions relating to hash/checksum are prefixed with fs_mgmt.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-22 12:41:49 +09:00
Michał Barnaś 94458f88b9 ec_host_cmd: add eSPI peripheral for the host commands
This commit adds the support for host commands being transported
by the eSPI subsystem.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-11-18 10:11:40 +01:00
Michał Barnaś b91849c4bd ec_host_cmd: add missing fields and improve compatibility
Add missing fields in structure containing the arguments used by
the host commands handlers and change the order of parameters
in macro used for defining the handlers.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-11-18 10:11:40 +01:00
Michał Barnaś 369596dc95 ec_host_cmd: increase stack size, change thread priority and alignment
This commit increases the stack size for thread handling the host
commands requests. It was required due to the stack being
corrupted using earlier default size. The thread priority is now
configurable using the Kconfig.
It also adds alignment to the tx_buffer since the npcx MCU requires it
to work correctly and removes clearing the buffer before use due to
the hard time requirements. Tests checking if buffers are cleared
are also removed.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-11-18 10:11:40 +01:00
Michał Barnaś 959d3b87fb ec_host_cmd: move the host_cmd_periph.h to subdirectory
Move the header file to corresponding directory which refers to
submodule name instead of root of drivers directory.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-11-18 10:11:40 +01:00
Dominik Ermel 7048383362 doc: Move SMP transport documentation under doc/services
The commit moves MCUmgr SMP transport documentation from
subsys/mgmt/mcumgr/lib to doc/services/device_mgmt.
Documentation have been rewritten for that purpose.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-17 15:31:17 +01:00
Dominik Ermel 4328f165a8 mgmt/mcumgr: Reworking source code tree and API interface
The commit reworks mgmt/mcumgr subsystem source code to remove
lib subdirectory and make it a little bit more flat.
It also moves all API interface files, which are supposed to be
visible by applications using MCUMgr, to interface sub-directories,
and exposes them with full paths; for example to include general
MCUMgr support, group registration and so on, user would now include:
 <mgmt/mcumgr/mgmt/mgmt.h>
to additionally have control on File System group management
registration user would need:
 <mgmt/mcumgr/mgmt/grp/fs_mgmt.h>

All internal headers have been removed from interface.

CMAkeLists.txt get significant rework and various MCUMgr subsystems
have been divided into separate sub-libraries.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-17 15:31:17 +01:00
Dominik Ermel 7c2924f4bc mgmt/mcumgr: Move transport headers to transport subdir
The MCUmgr transport headers have been moved to
zephyr/mgmt/mcumgr/transport/

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-17 15:31:17 +01:00
Dominik Ermel dac058c058 mgmt/mcumgr: Fix documentation for hash_checksum_mgmt_list_cb
Incorrectly hash_checksum_mgmt_handler_fn has been referenced
in documentation for hash_checksum_mgmt_list_cb, causing
documentation generation error, because parameter list does
not match.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-10 15:48:39 +01:00
Dominik Ermel 7ed6775d02 mgmt/mcumgr: Fix MCUMGR_BUF_USER_DATA_SIZE selection for BT
Rounded up struct smp_bt_user_data takes 8 bytes; this fixes
static assert failing with message:
  CONFIG_MCUMGR_BUF_USER_DATA_SIZE not large enough to fit Bluetooth
  user data

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-10 13:30:12 +01:00
Jamie McCrae dbd2176655 mgmt: mcumgr: fs_mgmt: Update hash/checksum supported command
Updates the hash/checksum supported command to use the new command
structure.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 12:34:39 +01:00
Jamie McCrae c2b872b901 mgmt: mcumgr: os_mgmt: Switch to new event callback system
Switches to the new event callback system for the os_mgmt
functionality and removes the old code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 12:34:39 +01:00
Jamie McCrae 986ea39512 mgmt: mcumgr: img_mgmt: Switch to new event callback system
Switches to the new event callback system for the img_mgmt
functionality and removes the old code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 12:34:39 +01:00
Jamie McCrae 4e8fde15a3 mgmt: mcumgr: fs_mgmt: Switch to new event callback system
Switches to the new event callback system for the fs_mgmt
functionality and removes the old code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 12:34:39 +01:00
Jamie McCrae 042ed0539b mgmt: mcumgr: Add access denied error code
Adds an access denied error code that can be used to signal to the
mcumgr client that the requested access to a specific resource or
command/functionality has been denied.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 12:34:39 +01:00
Jamie McCrae 6f75c99b8b mgmt: mcumgr: Rework event callback system
Reworks the event callback system to use a linked list to allow for
chained handlers and support passing a status back to the handler to
indicate if the request should be rejected or allowed. This also
removes the old base callback functionality.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 12:34:39 +01:00
Jamie McCrae 77374b3857 mgmt: mcumgr: fs_mgmt: Allow querying supported hash/checksums
Adds a new mcumgr command for returning information on all supported
hash/checksum types that the firmware supports.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 11:10:03 +01:00
Jamie McCrae 2aca1242f7 mgmt: mcumgr: Fix Bluetooth transport issues
This fixes issues with the Bluetooth SMP transport whereby deadlocks
could arise from connection references being held in long-lasting
mcumgr command processing functions.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 11:08:52 +01:00
Jamie McCrae 7028d01544 mgmt: mcumgr: Update struct name in documentation
Replaces mgmt_hdr with smp_hdr in documentation to match changes in
code.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 11:08:26 +01:00
Jamie McCrae f0669f845c mgmt: mcumgr: Replace mgmt_ctxt struct with smp_streamer
This replaces an intermediatory structure with a different one which
allows command functions to access the full contents of the streamer
structure that would be otherwise unavailable. This is a foundation
for allowing asynchronous mcumgr messages from the server.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-10 11:08:26 +01:00
Jamie McCrae 693e4cda81 mgmt: mcumgr: img_mgmt: Remove packed attribute from some structs
Removes the packed attribute from the img_mgmt structs that do not
need it.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-08 22:38:20 +01:00
Jamie McCrae 461b2147d6 mgmt: mcumgr: Fix using wrong value for response packet size
Fixes an issue introduced with a recent change that wrongly uses the
source packet header size for the output instead of the supplied
size.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-03 15:39:17 +01:00
Dominik Ermel 95202ae3da mgmt/mcumgr: Unify function definition style
Move static and return type in line with definition.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-03 13:04:45 +01:00
Dominik Ermel 98831be2c4 mgmt/mcumgr: Rename mgmt_hdr to smp_hdr
mgmt_hdr has always been part of SMP protocol and the name is
a little bit misleading.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-03 13:04:45 +01:00
Dominik Ermel 73d1bf984a mgmt/mcumgr: Make mgmt_hdr definition internal
It is only needed to be known by SMP protocol processing
and in some cases by transport, for example reassembly.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-03 13:04:45 +01:00
Dominik Ermel bf8ec99860 mgmt/mcumgr: Remove mgmt_ntoh_hdr and mgmt_hton_hdr
These two-liners have been only used by SMP protocol processing,
and there is no reason to have them available as public functions.
Code from these functions have been moved directly where they
have been used and they have been removed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-03 13:04:45 +01:00
Dominik Ermel 5f025cf49c mgmt/mcumgr: Move and rename zephyr_ prefixed functions in OS group
zephyr_ prefix is now redundant as there are no other OSes supported.
The commit also moves functions, after renaming them, and makes
them static, as they no longer have to be shared between compilation
units.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-03 13:04:29 +01:00
Dominik Ermel 80958bbff9 mgmt/mcumgr/lib: Merge Zephyr specific code to fs_mgmt.c
It is no longer needed to have "system specific" API for FS management.
The commit removes fs_mgmt_impl.h and moves Zephyr specific
functions that implement the fs_mgmt_impl.h declared functions
into fs_mgmt.c

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-11-03 13:04:29 +01:00
Jamie McCrae 4c48b4f21a mgmt: mcumgr: img_mgmt: Fix bug with old image state being present
This fixes an issue whereby the image state of an upload is present
even after an image erase command, which would instruct a client to
continue uploading at an offset that has no preceeding data.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-03 13:03:53 +01:00
Carles Cufi 8e4d499fa0 treewide: Use CONFIG_*_ENDIAN instead of __BYTE_ORDER__
In order to avoid using multiple sources of truth for the platfom's
endianness, convert the in-tree code to use the (BIG|LITTLE)_ENDIAN
Kconfig variables exclusively, instead of the compiler's
__BYTE_ORDER__.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-10-28 19:23:46 +09:00
Dominik Ermel 9331591ab1 mgmt/mcumgr: Remove buf.c
buf.c have been providing net_buf pool allocator and dealocator
for SMP packets: mcumgr_buf_alloc and mcumgr_buf_free.
The functions have been moved to smp.c and renamed
smp_packet_alloc and smp_packet_free, respectively.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-26 12:42:40 +02:00
Dominik Ermel 12b1528df9 mgmt/mcumgr: Remove mgmt/mcumgr/buf.h
SMP buffer allocation functions have been moved to smp/smp.h,
and buf.h has been removed.
Definitions of cbor_nb_reader and cbor_nb_writer have also been moved.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-26 12:42:40 +02:00
Dominik Ermel 6fdf95fbce mgmt/mcumgr: Move and internalize cbor_nb_*_init functions
The commit moves functions used for initialization of CBOR encoding
and decoding to the only unit that is supposed to use them.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-26 12:42:40 +02:00
Jamie McCrae 7bab5c1b75 mgmt: mcumgr: transport: smp_bt: Fix deadlock on disconnect with data
This fixes an issue with the bluetooth transport whereby if a device
drops the connection prior to receiving all the output data it could
cause a deadlock.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-10-25 17:37:17 +02:00
Dominik Ermel 8e0464ef68 mgmt/mcumgr/lib: Remove zephyr_ and _impl_ from function names
The commit removes zephyr_ and _impl_ from function names in image
management group, and renames img_mgmt_impl.* source files to
img_mgmt_priv and merges img_mgmt_priv.h headers.
The zephyr_ and _impl_ have been removed because they no longer make
sense, as the mcugr is internal part of Zephyr, and removal makes
function names shorter.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-25 16:24:18 +02:00
Dominik Ermel 552217cd68 mgmt/mcumgr/lib: Remove stubbed logging calls from img group
The commit removes some leftover code from feature that has been
supposed to log image upload events with use of SMP, but has never
been actually implemented.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-25 16:24:18 +02:00
Dominik Ermel 7089f94be9 mgmt/mcumgr: Deprecate zephyr_ prefixed API
The zephyr_ prefixed functions have been marked __deprecated.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-18 12:05:42 +02:00
Dominik Ermel 79f105d778 mgmt/mcumgr: Drop zst_ prefix from smp_transport members
With dropping the zephyr_ prefix, the member prefix zst_ makes
no sense.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-18 12:05:42 +02:00
Dominik Ermel 71e498dbd2 mgmt/mcumgr: Rename zst pointers to smp_transport to smpt
Cosmetic change: the zst was short for zephyr_smp_transport,
now it is just smp_transport so smpt makes more sense.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-18 12:05:42 +02:00
Dominik Ermel a7e40b35f0 mgmt/mcumgr: Drop zephyr_ prefix from functions
The MCUMgr library is now part of Zephyr, so there is no point
to prefix SMP functions with Zephyr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-18 12:05:42 +02:00
Christopher Friedt dbe2c0d59e include: net: http: rename http_x.h http/x.h
Some minor housekeeping prior to adding an http server
implementation. There are already a number of http headers
and that number will likely increase with subsequent work.
Moving them into a common directory cleans up the
`include/net` directory a bit.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2022-10-12 09:02:21 -04:00
Dominik Ermel 3d367ae8b4 mgmt/mcumgr: Remove MGMT_MAX_MTU from mgmt.h
Not used anywhere, MTU depends on transport.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-12 18:48:25 +09:00
Gerard Marull-Paretas 3976ccd5f7 include: add missing sys/printk.h include
Some files were using the printk API without including sys/printk.h

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Gerard Marull-Paretas 6a0f554ffa include: add missing kernel.h include
Some files make use of Kernel APIs without including kernel.h, fix this
problem.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Jamie McCrae cfd657fcec mgmt: mcumgr: Add fs_mgmt log output workaround on file write
If a file write was attempted with a file that does not exist, over
the shell/UART when logging was enabled, it would output a fs_unlink
error, this works around the issue by checking if the file exists and
needs truncating before performing that action. It also imrproves
flash endurance slightly by performing a truncate operation instead
of a delete, but will fall back to a delete if the truncation
operation fails. This issue can be also be mitigated by altering
logging settings or adjusting the SMP thread priority.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-10-11 11:15:02 +02:00
Dominik Ermel c759eb0a93 mgmt/mcumgr: Remove net_buf_pool_get call from zephyr_smp_alloc_rsp
It was pointless and nothing has been done with a result.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-11 11:14:22 +02:00
Dominik Ermel 49ac66ae99 mgmt/mcumgr: Drop smp_streamer.tx_rsp_cb
No longer needed, since smp_streamer has smpt pointer to
zephyr_smp_transport, it can directly call smpt->zst_output.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-06 16:37:23 +02:00
Dominik Ermel b64f61115e mgmt/mcumgr: Remove mgmt_streamer structure
There are no more functions directly using the type, so it
has been removed and its contents have been moved to
smp_streamer.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-06 16:37:23 +02:00
Dominik Ermel 7f67b6759c mgmt/mcumgr: Remove declaration of mgmt_streamer_trim_front
The commit removes declaration of functions
mgmt_streamer_trim_front and mgmt_streamer_init_reader
as they no longer have definitions.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-06 16:37:23 +02:00
Dominik Ermel 84345a4ec0 mgmt/mcumgr: Drop empty parameter from img_mgmt_flash_check_empty
The commit drops empty parameter from img_mgmt_flash_check_empty
and img_mgmt_flash_check_empty_inner and uses the return code
instead.
Both functions now use negative errno codes instead of MGMT_ERR_
type codes.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-10-06 16:36:37 +02:00
Jamie McCrae b58d4356a1 mgmt: mcumgr: img_mgmt: Prevent re-upload of duplicate image data
This adds a hash check when the CONFIG_IMG_ENABLE_IMAGE_CHECK Kconfig
option is enabled that will check the underlying image hash to see if
it is the same as the one provided by the mcumgr client, and if so,
will prevent erasure/uploading the same image data.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-10-06 16:35:31 +02:00
Jamie McCrae 486b4db2cd mgmt: mcumgr: Remove Kconfig values that were deprecated in zephyr 3.1
Removes deprecated Kconfig values that have been replaced.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-10-06 16:34:58 +02:00
Jamie McCrae ff3fd335b2 mgmt: mcumgr: Add dummy shell buffer size Kconfig to shell_mgmt
This adds the dummy shell buffer size to the shell_mgmt
configuration to allow ease of changing it.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-10-06 16:33:41 +02:00
Dominik Ermel 16cdb40df7 mgmt/mcumgr: Remove mcumgr_util.h header
The header provides declarations for no longer used/existing
functions.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-27 16:39:22 +02:00
Dominik Ermel e4d0bf0e64 mgmt/mcumgr: Fix image erase returning improper error code on error
The img_mgmt_erase could return MGMT_ERR_EOK even when
img_mgmt_impl_erase_slot failed.

Fixes #50522

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-22 15:32:04 +00:00
Jamie McCrae 1489104ddb mgmt: mcumgr: img_mgmt: Fix slot3 if check
Fixes an issue with img_mgmt whereby the if check for a slot3
partition is using the wrong case for the partition name.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-21 18:18:18 +02:00
Jamie McCrae 50738819f4 mgmt: mcumgr: Move wrongly placed header file
Moves a .h file added outside of the zephyr include folder to be
within the zephyr include folder.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-20 15:01:47 +02:00
Andrzej Puzdrowski 8d4d827a94 mgmt/mcumgr: include bootutil_public.h in im_mgmt
This header provides original BOOT_MAX_ALIGN definition.
This definition is used indirectly by the code this
patch modifies.
Let's use it instead of copy from mcuboot.h

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-09-19 18:36:37 +02:00
Dominik Ermel 4b01c733bb mgmt/mcumgr: Make img_mgmt_erase construct only good response
Constructing error response makes no sense as smp_build_err_rsp
will rewrite it.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-19 18:30:57 +02:00
Dominik Ermel c19aac161e mgmt/mcumgr: Remove mgmt_write_rsp_status function
It is no longer used.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-19 18:30:16 +02:00
Dominik Ermel 1cd03dee96 mgmt/mcumgr: Fix CONFIG_MGMT_VERBOSE_ERR_RESPONSE
The options should enable verbose responses in error responses
to SMP command processing, but has been broen when the code
has been ported to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-19 18:30:16 +02:00
Yong Cong Sin 15b3150ac2 mgmt/hawkbit: Print hrefs only if there's an update
If the is no update from the server, the _links will be NULL.
Check if it is NULL before trying to LOG these strings.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-09-19 15:43:04 +02:00
Jamie McCrae 52e2493842 mgmt: mcumgr: fs_mgmt: hash/checksum: Fix size errors
There are warnings when building fs_mgmt with hash/checksum
functionality enabled due to array access and a wrong variable type
being used.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-19 10:50:42 +00:00
Dominik Ermel f46f8511ce mgmt: mcumgr: Remove zcbor_size_ definitions
zcbor supports native zcbor_size_ functions for some time now,
so there is no need to have local zcbor_size_ definitions.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-14 09:40:30 +00:00
Jamie McCrae c56b45c3e8 mgmt: mcumgr: Fix output packet to frame issue on serial transport
Fixes an issue with outgoing mcumgr frames that are larger than the
transport MTU size whereby they would wrongly be split up into multiple
frames with multiple start frame headers, which affected SMP over
console transports.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-09 19:47:12 +00:00
Dominik Ermel 798d6c7ffc mgmt/mcumgr: Drop zst from zephyr_smp_transport_out_fn
Never used and not needed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-09 18:25:44 +00:00
Dominik Ermel 7cc729558f mgmt/mcumgr: Move SMP transport to own sub-dir
The lib/transport directory has been moved up, directly under the
subsys/mgmt/mcumgr, and all transport files have been moved to
that directory.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-09 16:37:48 +00:00
Jamie McCrae ce7e0f4425 mgmt: mcumgr: Fix wrongly using pointer of pointer in free function
Fixes an issue introduced when the mcumgr code was simplified whereby
the newer compressed free function call wrongly passes a pointer to a
pointer instead of the pointer itself.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-09 09:53:43 +00:00
Jamie McCrae 59cbe81ec3 mgmt: mcumgr: smp_bt: Fix missing notification connection unref
Fixes an issue with the connection reference not being decremented
at the end of the outgoing notification function resulting in an
ever-increasing connection count.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-09 09:53:43 +00:00
Pieter De Gendt 34ee707d4a mgmt: mcumgr: Fix unused function warning
The static function img_mgmt_flash_check_empty is only used if
CONFIG_IMG_ERASE_PROGRESSIVELY isn't set.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2022-09-08 15:31:36 +00:00
Jamie McCrae 1da4adfe20 mgmt: mcumgr: Replace #if with #ifdef for CONFIG_ checks
Replaces #if with #ifdef when checking Kconfig defines

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-08 15:29:21 +00:00
Jamie McCrae edd1a5ff6f mgmt: mcumgr: os_mgmt: Make reboot conditional on CONFIG_REBOOT
This prevents the os_mgmt reboot command being available if
CONFIG_REBOOT is not selected.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-08 15:29:21 +00:00
Jamie McCrae 7992256df5 mgmt: mcumgr: Add dummy SMP backend
This adds a dummy SMP backend which can be used for unit testing or
virtual interface purposes.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-09-08 15:29:21 +00:00
Jamie McCrae e394899256 mgmt: mcumgr: Add runtime taskstat tick usage
Adds the runtime tick count of threads to mcumgr's taskstat response,
if CONFIG_SCHED_THREAD_USAGE is enabled, which reports the number of
execution cycles that each thread has been running for.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-06 16:19:37 +02:00
Jamie McCrae 92074e00a8 mgmt: mcumgr: Fix Bluetooth notification issue
Fixes an issue with Bluetooth notification sending whereby it does
not wait for buffers to become available and can error out if
unable to get a buffer once.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-06 16:19:15 +02:00
Jamie McCrae 698c4b0243 mgmt: mcumgr: Use dedicated work queue for SMP
Fixes an issues where the system work queue can become a source of
contention and cause a deadlock by moving MCUMGR SMP processing to its
own dedicated work queue.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-06 16:19:15 +02:00
Jamie McCrae 4bd39c21c7 mgmt: mcumgr: Move zephyr_grp to lib/cmd folder
Moves the zephyr_grp commands to the same directory as the other
mgmt command handlers.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-06 16:18:50 +02:00
Dominik Ermel 4a702ea21e mgmt/mcumgr: Move mgmt Kconfig file under mgmt sub-dir
The Kconfig for MCUMgr management source code (service registration,
group registration, and so on) has been moved to the sub-dir with
the code.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 12:49:27 +02:00
Jamie McCrae 3a79fddfc2 mgmt: mcumgr: Make signed thread priorities enabled by default
By default, thread priorities in mcumgr task stat responses are
unsigned, whilst in zephyr, thread priorities are signed. This means
that clients get obscenely large numbers for priorities that make no
sense. The fork of mcumgr has been in zephyr long enough now that
this should be changed to use signed thread priorities by default
instead of sticking with the old mcumgr default.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-06 12:48:25 +02:00
Dominik Ermel 6b760b3702 mgmt/mcumgr: Remove internal functions form Zephyr header
The commit removes declarations of:
 zephyr_smp_rx_req, zephyr_smp_alloc_rsp, zephyr_smp_free_buf
from include/zephyr/mgmt/mcumgr/smp.h, as these are MCUMgr internal
functions used in SMP processing and should be not exposed
from header file that provides interface for SMP transports.
The declarations have been moved to smp_internal.h, which is
visible within MCUMgr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 12:36:08 +02:00
Marc Lasch 42858bebb7 mgmt/mcumgr: Fix format specifier
Use c99 format specifier macros to remove build warnings when building
for `native_posix[_64]`.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2022-09-06 10:00:25 +02:00
Dominik Ermel 0d956d2d31 subsys/mgmt/hawkbit: Switch from FLASH_AREA_ to FIXED_PARTITION_
The commit switches flash area access from FLASH_AREA_ macros
to FIXED_PARTITION_ macros and to usage of DTS node labels,
to identify partitions, instead of label property.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 09:56:37 +02:00
Dominik Ermel b8533a7bee mgmt: updatehub: Switch from FLASH_AREA_ to FIXED_PARTITION_
The commit switches flash area access from FLASH_AREA_ macros
to FIXED_PARTITION_ macros and to usage of DTS node labels,
to identify partitions, instead of label property.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 09:56:37 +02:00
Dominik Ermel 572e527bd1 mgmt/mcumgr/lib: Switch to FIXED_PARTITION_* macros
The commit switches mcumgr from FLASH_AREA_* macros to
FIXED_PARTITION_* macros.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 09:56:37 +02:00
Dominik Ermel 8af9d3b960 mgmt/mcumgr: Move FS conditional block to FS CMakeLists.txt
The conditional block linking mbedTLS for checksum calculation
in FS commands have been moved to CMakeLists.txt responsible
for compiling these commands.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-05 14:44:05 +00:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Fabio Utzig 5a3c459c00 mgmt: mcumgr: fix includes to avoid redefinition
Fix include order to avoid redefinition of `ARRAY_SIZE`, because
`sys/util.h` and `zcbor_common.h` both define it, but `sys/util.h` does
not protect against redefinition.

Signed-off-by: Fabio Utzig <utzig@tumenibits.com>
2022-09-02 15:13:10 +00:00
Jamie McCrae 0cbd888831 mgmt: mcumgr: Add optional slot number to erase command
Allows selecting which slot will be erased, will default back to
slot 1 as it would do in previous versions if the optional parameter
is not provided

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-02 10:56:58 +00:00
Jamie McCrae 767d32f54c mgmt: mcumgr: Fix ARRAY_SIZE build warning
Fixes a build warning due to include file ordering

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-02 19:11:02 +09:00
Jamie McCrae 41ecd5998f mcumgr: shell: Change command exit code from rc to ret
This prevents the shell command response code conflicting with the
mcumgr response code, which are 2 distinct variable types

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-01 14:05:14 +02:00
Jamie McCrae 4ef4944673 mgmt: mcumgr: Fix race condition with task status
Fixes a race condition when listing task status using mcumgr whereby
if a thread status changes, it could cause unpredictable output for
the command.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-01 13:20:44 +02:00
Jamie McCrae c72eb5f02c mgmt: mcumgr: Reduce unnecessary pointers and objects
Reduces the level of indirection for functions by calling the zephyr
functions directly as support for multiple operating systems is no
longer required with mcumgr being forked and placed into the zephyr
tree. Saves 60 bytes flash when compiling smp_svr on an ARM Cortex
M4 board.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-01 13:20:11 +02:00
Jamie McCrae 3839398964 mgmt: mcumgr: Move to slist for group management
Switches to using Zephyr's single linked list implementation for
group management objects instead of duplicating functionality for
mcumgr only.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-01 13:19:41 +02:00
Jamie McCrae 03730e71fd mgmt: mcumgr: Make img_mgmt structures packed
Resolves an issue with processors that do not support unaligned memory
access when using img_mgmt functions, e.g. ARM Cortex M0, by marking
structures as packed.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-09-01 13:19:21 +02:00
Jamie McCrae fc64b77ab1 mgmt: mcumgr: Split up transport Kconfig into separate files
Makes each mcumgr transport have a separate Kconfig file for ease of
maintenance

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-08-26 21:34:38 -04:00
Gerard Marull-Paretas a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Yong Cong Sin dd9d6bbb44 subsys/mgmt/hawkbit: Set ai_socktype if IPV4/IPV6
Follows the implementation of updatehub and set the
`ai_socktype` only if IPV4/IPV6

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-18 11:33:38 +00:00
Yong Cong Sin 2ed88e998a subsys/mgmt/hawkbit: Init the hints struct to a known value
Initialize the `hints` struct to a known value so that it won't
cause undetermined behavior when used in `getaddrinfo()`.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-18 11:33:38 +00:00
Dominik Ermel dd79b9c11a subsys/mgmt/hawkbit: Clean up flash map usage
The commit cleans up how flash map labels and definitions are
used.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-08-08 15:03:34 +02:00
Kumar Gala f2bcc794cd mgmt: osdp: Move to DTS for uart device
Move from using Kconfig OSDP_UART_DEV_NAME to a devicetree
chosen property ("zephyr,osdp-uart").  This is similar to a number
of other functions like "zephyr,shell-uart" or "zephyr,bt-uart".

Changed the integration platform for the osdp samples to
stm32_min_dev_black as it already has zephyr,osdp-uart set.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-23 09:25:23 -05:00
Yudong Zhang 73c4d70614 mgmt: hawkbit: fix call to bin2hex
Fixes: f2affbd973 ("os: lib: bin2hex: fix memory overwrite")
Signed-off-by: Yudong Zhang <mtwget@gmail.com>
2022-07-11 10:30:05 +02:00
Yudong Zhang 0c4d614824 mgmt: updatehub: fix call to bin2hex
We noticed that in the master branch, updatehub fails to start.
That is because of the behaviour change in bin2hex caused by
commit f2affbd ("os: lib: bin2hex: fix memory overwrite").

Fixes: f2affbd973 ("os: lib: bin2hex: fix memory overwrite")
Signed-off-by: Yudong Zhang <mtwget@gmail.com>
2022-07-11 10:30:05 +02:00
Kumar Gala a204d16bfb ec_host_cmd: Convert to DEVICE_DT_GET
We are working on phasing out use of the devicetree 'label'
property.  We can use DEVICE_DT_GET and drop use of DT_LABEL.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-06 11:12:32 +02:00
Berend Ozceri 394d5f7656 mgmt: smp: Allow building with POSIX API in UDP transport
If the POSIX API is selected via the POSIX_API option, don't also select
the conflicting NET_SOCKETS_POSIX_NAMES and use the POSIX headers instead.

Signed-off-by: Berend Ozceri <berend@recogni.com>
2022-07-04 14:22:13 +00:00
Krzysztof Chruscinski 041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Dominik Ermel f9d69c34c9 mgmt/mcumgr/lib: Remove dead code from img_mgmt_upload
The img_mgmt_impl_erase_if_needed was only called when
CONFIG_IMG_ERASE_PROGRESSIVELY is y, and it does nothing anyway;
because the function always returns 0, and does nothing,
neither the function no result processing, from a call to the
function, is needed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-21 13:42:24 +02:00
Dominik Ermel 0a5525358c mgmt/mcumgr/lib: Add BUSY error code
The commit reserves adds MGMT_ERR_EBUSY (10) error code and adds
documentaiton for it.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-21 11:55:19 +02:00
Dominik Ermel 185630e387 mgmt/mcumgr/lib: Correct comment alignment
Some of comments have not been aligned to tabs.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-21 11:55:19 +02:00
Dominik Ermel d261c3b891 mgmt/mcumgr/lib: Remove flash_area_open_ex
The function is no longer needed with fix provided by commit
aa5d20aaef (storage/flash_map: Return -ENODEV from flash_area_open).

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-21 11:48:23 +02:00
Dominik Ermel 4aea359f27 mgmt/mcumgr/lib: Remove unused state variables from image management
Image management state, struct img_mgmt_state, has been defining
sector_id and sector_end variables, supposed to be used by
progressive erase feature, that have no use in code.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-21 11:48:04 +02:00
Dominik Ermel 8b7b81d0f2 mgmt/mcumgr/lib: Fix overriding returned error code
The img_mgmt_upload has been overriding return codes of several
utility function calls with MGMT_ERR_EUNKNOWN, even though
these utility functions would be returning MGMT_ERR_* type codes
already, overshadowing real reason of failure.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-21 11:47:43 +02:00
Dominik Ermel 1243bf6d15 mgmt/mcumgr/lib: Change image, size and offset types
The commit changes types of image, size and offset elements of
img_mgmt_upload_req structure from unsigned long long to size_t.

This commit also fixes comments and conditional statements, where
these identifiers have been compared against -1, although they have
been clearly defined as unsigned.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-21 11:47:10 +02:00
Gerard Marull-Paretas e207b39404 mgmt: osdp: remove redundant <zephyr/zephyr.h> includes
Files including <zephyr/kernel.h> do not have to include
<zephyr/zephyr.h>, a shim to <zephyr/kernel.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-06-15 09:13:11 +02:00
Dominik Ermel f52085dc54 mgmt/mcumgr/lib: Fix loop when image write fails
The img_mgmt_upload was getting into loop with requesting
offset 0 from mcumgr, when requested to re-try upload after
write fails.
Because it is not really possible to recover from write fail,
at least currently, the commit changes code to reset upload
state in a case of write error and return an error code.
Now, when write fails, an error will be returned and upload
process will be stopped and reset; upload re-try will behave
as a new upload has been requested.

Fixes #44219

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-10 09:48:31 +02:00
Dominik Ermel 3d8960ffe3 mgmt/mcumgr/lib: Remove redundant offset check
The offset is checked, for correctness, before the function
img_mgmt_impl_write_image_data is called, so it is redundant to
do the same check within it.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-10 09:48:31 +02:00
Dominik Ermel 0c290864d7 mgmt/mcumgr/lib: Remove no longer needed mgmt_streamer_trim_front
Special function for supporting various types of buffers,
via provided callbacks, is no longer needed when net_buf is the
only type of transport buffer used by mcumgr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-07 18:54:11 +02:00
Dominik Ermel 3528c1ee30 mgmt/mcumgr: Replace zephyr_smp_trim_front with net_buf_pull
The additional logic of zephyr_smp_trim_front is no longer needed
and net_buf_pul can be directly used to trim front of net_buf
response when fragmenting.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-07 18:54:11 +02:00
Yong Cong Sin ae587f8e50 subsys/mgmt/hawkbit: format for readability
Formatted the code so that it is easier to read.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-06-07 11:52:10 +02:00
Dominik Ermel 37dd4fb775 mgmt/mcumgr/lib: Fix parasitic use of heap by image management
The commit fixes issue where image management would switch to using
heap, whether developer wanted or not, when CONFIG_HEAP_MEM_POOL
gets value greater than zero.
Now when heap is enabled the user can select whether image management
will keep on using static variable, taking static RAM, or will use
heap to allocate the flash image context only when needed.
For this purpose CONFIG_IMG_MGMT_USE_HEAP_FOR_FLASH_IMG_CONTEXT
has been added, which is available when CONFIG_HEAP_MEM_POOL is enabled.

Fixes #44214

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-06 12:05:29 +02:00
Dominik Ermel e15523d198 mgmt/mcumgr/lib: Use flash_img_bytes_written to check context
The commit replaces direct access to flash_img_context, for the
purpose of checking how much data has been written, with call
to the flash_img_bytes_written.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-05 14:47:35 +02:00
Keith Packard b7313f85fe subsys/img_mgmt: Add zephyr/toolchain.h for STRINGIFY [v2]
Somehow two files in subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src ended up
using STRINGIFY but nothing in their include path ended up pulling in
zephyr/toolchain/common.h. Include that via zephyr/toolchain.h.

v2:
	Use non-internal zephyr/toolchain.h header

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-05-27 15:34:34 -07:00
Dominik Ermel 38e554846a mgmt/mcumgr/lib: Improve CONFIG_IMG_MGMT_VERBOSE_ERR description
The description suggested logging information while it never
was the case: it was about adding additional "rsn":value pair
to an SMP response.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-05-27 15:21:24 -07:00
Fabio Baltieri e24314f10f include: add more missing zephyr/ prefixes
Adds few missing zephyr/ prefixes to leftover #include statements that
either got added recently or were using double quote format.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-05-27 15:20:27 -07:00
Dominik Ermel 19259ab7db mgmt/mcumgr/lib: Fix image list command crashing when no device
It is possible, in case of two application images, to have no access
to one of devices of the secondary image.
When asserts are enabled, such situation causes crash even though the
image list command can handle it with no problem.
The commit removes the assert and adds additional swap type:
IMG_MGMT_SWAP_TYPE_UNKNOWN to indicate situations where it was
not possible to obtain swap type from boot_util.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-05-26 13:08:35 -07:00
Dominik Ermel 1bd5665b89 mgmt/mcumgr/lib: Fix usage of MGMT_ERR_ENOMEM
The commit replaces MGMT_ERR_ENOMEM with MGMT_ERR_EMSGSIZE where it
was used to indicate that SMP response does not fit in response
buffer.

Fixes #44535

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-05-25 13:56:03 -07:00
Dominik Ermel 550f1b096d mgmt/mcumgr/lib: Fix OS taskstat passing incorrect value
The commit fixes incorrect value being passed as used stack
information and also prevents compilation error when
CONFIG_INIT_STACKS is n.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-05-25 16:09:12 +02:00
Damian Krolik 7e02e8c9f4 mcumgr: fix invalid condition for calling img_mgmt_dfu_stopped
In other places, img_mgmt_dfu_stopped() is called when
a failure occurs and the DFU cannot be continued. In this
place, however, the function is called on success which
does not seem to be correct.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2022-05-25 14:21:19 +02:00
Matthias Wauer ba14fc4745 mgmt: img_mgmt: fix typo in variable name
The correct variable name is 'action'

Signed-off-by: Matthias Wauer <matthiaswauer@gmail.com>
2022-05-16 16:56:18 +02:00
Dominik Ermel 578cb132ff mgmt/mcumgr/lib: Make version string work with CONFIG_NEWLIB_LIBC
By default the newlib does not compile with %hhu processing,
to avoid turning on additional options for newlib compilation
this commit changes formatting string to use %hu instead.
The commit fixes problem with malformed version string being
returned, by smp_svr, when CONFIG_NEWLIB_LIBC=y is set together
with CONFIG_NEWLIB_LIBC_NANO=y.

Fixes #45261

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-05-15 21:33:05 +02:00
Dominik Ermel 0c051d0dd6 mgmt/mcumgr/lib: Fix astray dot in image version
Removed the dot.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-05-15 21:33:05 +02:00
Jamie McCrae 9e6b5cdca8 mgmt: mcumgr: lib: img: Add image header to callback
This allows an application to inspect a mcumgr img upload command to
provide additional information for acceptance or rejection of it, and
makes the previous private version compare function public so that
application code can call it.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-05-11 20:32:52 +02:00
Jamie McCrae 6a85b1b0d3 mgmt: mcumgr: lib: fs: Add file read/write access callback
This allows an application to inspect a mcumgr file access command and
either allow it or deny it with a result code.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-05-11 17:10:55 +02:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Dominik Ermel ef199e92df mgmt/mcumgr/lib: doc: Minor fixes to zcbor_bulk documentation
Little polishing here and there.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-19 11:35:16 +02:00
Dominik Ermel fb4afe2112 mgmt/mcumgr/lib: Remove mcumgr_util
With replacement of (u)ll_to_s with snprintf the util is no longer
needed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-19 11:34:40 +02:00
Dominik Ermel 3445c29979 mgmt/mcumgr/lib: Use snprintf instead of ll_to_s in OS group
The commit replaces usage of ll_to_s with snprintf.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-19 11:34:40 +02:00
Dominik Ermel 4a12570ef8 mgmt/mcumgr/lib: Allow image management list broken version str
The commit adds change to image management list where "<???>"
will be returned as version string in case when version to string
conversion fails.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-19 11:34:40 +02:00
Dominik Ermel 692a4a7e63 mgmt/mcumgr/lib: Replace ull_to_s with snprintf in img_mgmt_ver_str
The ull_to_s, which is used to covert ints to string, has been
replaced with snprintf.
Above also fixes a bug where ull_to_s has been given INT_MAX as allowed
output string, while it should be given maiximum allowed buffer size.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-19 11:34:40 +02:00
Dominik Ermel ca60b75613 mgmt/mcumgr/lib: Remove mgmt_streamer_reset_buf
Commit removes mgmt_streamer_reset_buf from mcumgr lib,
and supporting Zephyr function zephyr_smp_reset_buf.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-19 11:32:56 +02:00
Jamie McCrae d67a364ace mgmt: mcumgr: lib: os: Add reset callback
This allows an application to inspect a mcumgr os reset command and
either allow it or deny it with a result code.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-04-13 14:05:57 -07:00
Dominik Ermel 4e03e34138 mgmt/mcumgr/lib: Add missing inclusion of toolchain.h
The zcbor_bulk_priv.h uses STRINGIFY for some of definitions
and, due to lack of inclusion of the toolchain.h, that was causing
compilation errors when NEWLIB would be selected.

Fixes #44811.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-13 13:28:16 -07:00
Jamie McCrae 756a8f7a9b mgmt: mcumgr: fs: Add hash/checksum (with CRC32/SHA256) handler
This adds a hash/checksum mcumgr handler to the file management commands
which can be used to get a hask or checksum of a file, and includes
handler implementations for IEEE CRC32 and SHA256.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-04-12 12:05:30 +02:00
Jamie McCrae 105f8b65e9 mgmt: mcumgr: fs: Add file status handler
This adds a command handler to the file management mcumgr system to get
the status of a file without needing to return file data (currently
reporting the file size).

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-04-12 12:05:30 +02:00
Dominik Ermel 1b92fba8e7 mgmt/mcumgr/lib: endian.h is no longer needed.
Removed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-12 11:42:28 +02:00
Dominik Ermel e7205683bd mgmt/mcumgr/lib: Replace htons/ntohs with Zephyr functions
The commit replaces htons and ntohs calls, with sys_be16_to_cpu
and sys_to_cpu_be16.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-12 11:42:28 +02:00
Dominik Ermel 8aa7791c53 mgmt/mcumgr/lib: Improve smp_process_request_packet documentation
The commit clarifies smp_process_request_packet behaviour.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-11 12:13:33 +02:00
Dominik Ermel aff57a0a42 mgmt/mcumgr/lib: Cleanup of img_mgmt_priv.h
Fixed define and removed unneded definitions.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-11 12:12:03 +02:00
Dominik Ermel bc276b1a68 mgmt/mcumgr/lib: Correct zephyr_grp log module name
The zephyr_grp log module name was incorrectly named
MGMT_SETTINGS and module registration has been using module name
mgmt_zephyr_basic, which is also incorrect.
Both have been changed to mcumgr_zephyr_grp.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-11 12:11:27 +02:00
Dominik Ermel f79698a37c mgmt/mcumgr/lib: Separate Kconfig for zephyr specific commands
Kconfig options for Zephyr specific group have been moved
to zpehyr_grp/Kconfig.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-11 12:11:27 +02:00
Dominik Ermel a1449521aa mgmt/mcumgr: Kconfig: Gather transport options under own menus
The commit adds transport dedicated menu and gathers all transport
options under that menu; each transport gets its own menu, witch
gathers options specific for that transport

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-11 12:10:39 +02:00
Dominik Ermel b6db591a17 mgmt/mcumgr/lib: Add MCUMGR Parameters command to OS group
Adds new command that allows to retrieve MCUMGR parameters.
Currently the command returns MCUMGR buffer size and count.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-11 12:10:20 +02:00
Dominik Ermel 33c0995e03 mgmt/mcumgr/lib: Fix zcbor_map_decode bulk
Fixed problem with uninitialized conditional variable.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 17:43:50 +02:00
Jamie McCrae 0ea3600e5c mgmt: mcumgr: lib: Fix non-visible struct build warnings
Fixes build warnings relating to visibility of 2 structs in mcumgr

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-04-08 15:49:36 +02:00
Dominik Ermel f36b6d8552 mgmt/mcumgr/lib: Deprecate CONFIG_IMG_MGMT_UL_CHUNK_SIZE
The IMG_MGMT_UL_CHUNK_SIZE is no longer used to control size of
intermediate buffer used for application image chunk processing,
instead directly request trasport buffer is used.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 756c34659b mgmt/mcumgr/lib: Deprecate CONFIG_OS_MGMT_ECHO_LENGTH
The echo sentence is now directly copied from request transport
buffer to response buffer, without use of intermediate buffer.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 057f7a2ffd mgmt/mcumgr/lib: Deprecate FS_MGMT_UL_CHUNK_SIZE
Now the chunk of uploaded file is directly read from the transport
buffer, net_buf, and is no longer copied into intermediate buffer
so the real size of chunk is actually how much the sender could
fit into MCUMGR_BUF_SIZE, less the other fields.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 7d27f8dd58 mgmt/mcumgr: Remove dependency on TinyCBOR
Mcumgr now wholy uses zcbor for decoding/encoding SMP
requests/responses.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 05b4142637 mgmt/mcumgr/lib: Remove cborattr from mcumgr
No longer used by mcumgr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 265382931f mgmt/mcumgr/lib: Remove mgmt_err_from_cbor function
No longer needed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel a3793cbfa7 mgmt/mcumgr: Move Zephyr specific group to zcbor
Replacing TinyCBOR with zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 18f0db5bd0 mgmt/mcumgr/lib: Move FS command group request processing to zcbor
The commit moves processing of SMP requests from TinyCBOR to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 9f1a8cbbb4 mgmt/mcumgr/lib: Move IMG mgmt group request processing to zcbor
The TinyCBOR, in processing SMP requests, have been replaced
with zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 40462946a9 mgmt/mcumgr/lib: Add utility zcbor_map_decode_bulk
The commit adds private, for internal mcumgr use only, utility
function for bulk processing of CBOR map entries.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel ebc62e9bf9 mgmt/mcumgr/lib: Move SHELL mgmt request processing to zcbor
The commit replaces TinyCBOR for request processing within
SHELL command group.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 784d929761 mgmt/mcumgr/lib: Move STAT group request processing to zcbor
The STAT command group request processing has been moved from
TinyCBOR to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel df028e7ee6 mgmt/mcumgr/lib: Switch OS group request processing to zcbor
The commit switches OS group commands to use zcbor instead
of TinyCBOR for processing SMP requests.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 4f9f694398 mgmt/mcumgr/lib: Remove TinyCBOR state objects from mgmt_ctxt
Removes no longer needed elements of struct mgmt_ctxt.
Removes mgmt_ctxt_init, mgmt_streamer_init_reader and init_reader
from struct mgmt_streamer_cfg as they are no longer needed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 9675d94119 mgmt/mcumgr/lib: Switch smp_process_request_packet to net_buf
Drops usage of mgmt_streamer.reader in favour of direct access
to net_buf.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 6bddb0305a mgmt/mcumgr: Switch cbor_nb_reader to zcbor
The commit removes cbor_decoder_reader from cbo_nb_reader and
adds zcbor state variable to the structure.
All the code that has been supporting the cbor_decder_reader
has been removed and/or replaced with zcbor/net_buf specific.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel d0445aa4a9 mgmt/mcumgr/lib: Replace cbor_decoder_reader with cbor_nb_reader
Replaces TinyCBOR cbor_decoder_reader with cbor_nb_reader in
SMP processing code.
The SMP source code has been relying on internal elements of the
cbor_decoder_reader and had to be rewritten to use net_buf
structures, that are part of cbor_nb_reader, instead.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 1c9395f3b9 mgmt/mcumgr/lib: Replace calls to mgmt_streamer_init_writer
The calls have been replaced with direct invocations of
cbor_nb_writer_init.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel bff015feff mgmt/mcumgr/lib: Remove cbor_encoder_writer from usage
With transition to zcbor, the cbor_encoder_writer structure of
TinyCBOR is no longer used.
This commit replaces the structure with cbor_nb_writer, which
gathers zcbor processing structure with netbuf into one object.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 7cac9ef413 mgmt/mcumgr/lib: Use zcbor in OS command group responses
The commit switches processing of OS command group responses
to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel f9a7ba38b1 mgmt/mcumgr/lib: Encode IMAGE command group responses with zcbor
The commit moves encoding of IMAGE command group responses to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 2c66849401 mgmt/mcumgr/lib: Encode FS command group responses with zcbor
The commit moves encoding of FS command group responses to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel 8cb52b26c1 mgmt/mcumgr/lib: Encode SHELL command group responses with zcbor
The commit moves SHELL command group responses encoding to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel e9b2c6ade2 mgmt/mcumgr/lib: Encode STAT command group responses with zcbor
The commit moves STAT command group responses encoding to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel a8e0b249fe mgmt/mcumgr/lib: Move common code for responses to zcbor
Common SMP response processing code gets switched to zcbor.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Dominik Ermel c883c45752 mgmt/mcumgr: Add zcbor support for sending responses
The commit modifies cbor_nb_writer to handle zcbor.
Proper initialization code has been added to cbor_nb_writer_init.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-08 13:49:55 +02:00
Yong Cong Sin 9d10127b87 subsys/mgmt/hawkbit: Kconfig: Add HAWKBIT_DDI_SECURITY to choice
Add a name for the choice of authentication modes so that it
can be default to a certain type in project's Kconfig.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-04-06 04:51:07 -04:00
Dominik Ermel f44a222275 mgmt/mcumgr: Split Kconfig into smaller Kconfigs
The commit splits the main mcumgr Kconfigs into primary Kconfig
that collect general mcumgr options for Zephyr (Zephyr specific
commands, transports, and so on), into lib/Kconfig
that collects library options and command groups' Kconfigs.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-31 14:36:38 -05:00
Yong Cong Sin 313c49ec21 subsys/mgmt/hawkbit: Check the hash of stored firmware
Previously, the hash of the firmware is checked while we are
downloading the firmware. This isn't ideal as the validity of
the firmware written into the flash is not verified and can be
corrupted. Furthermore, checking while downloading will have an
negative impact to the download speed as the CPU need to do
more work during the data transfer.

This PR removes the previous verify-hash-while-download
implementation and use the flash_img_check API instead.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-31 10:28:22 +02:00
Yong Cong Sin 77d829e31e subsys/mgmt/hawkbit: Improve hawkbit_probe readability
After the firmware is downloaded in hawkbit_probe, a series of
operations are done by using the fact that the conditions of
an if-else statement will be ran until a match.

This patches separate these condition into individual
if-condition for better readability

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-31 10:28:22 +02:00
Dominik Ermel 30fcf494be mgmt/mcumgr: Fix possible buffer overflow in BT tranport
The commit add checks whether frame received from BT transport
will really fit into allocated net_buf form mcumgr.

Fixes: #44271

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-29 10:19:09 +02:00
Dominik Ermel e20f72f7cb kconfig: Remove unneeded ${ZEPHYR_BASE} from template import
The commit removes, from various Kconfigs, ${ZEPHYR_BASE} in
sourcing of logging template.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-24 18:07:28 -04:00
Dominik Ermel e1d57d19f2 mgmt/mcumgr/lib: Add missing mcumgr_img_mgmt log Kconfig options
Due to lack of proper Kconfig options for the logging module,
default were always applied.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-23 18:40:53 +01:00
Dominik Ermel 7de1061f5c mgmt/mcumgr/lib: Fix LOG_MODULE_NAME for image group
Was mcumgr_flash_mgmt, replaced with mcumgr_img_mgmt.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-23 18:40:53 +01:00
Dominik Ermel 14877fd6a6 mgmt/mcumgr/lib: Use stack allocated shell buffer
The commit moves shell command buffer to stack and changes
initialization to just just put null at the beginning, before calling
a function that will fill in the buffer, and at the end, after the call.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-23 14:04:31 +01:00
Dominik Ermel 7dea9134a9 mgmt/mcumgr/lib: Unify source code for SHELL mgmt group
Moves Zephyr specific code to common source file and removes
no longer needed interface headers.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-23 14:04:31 +01:00
Dominik Ermel a47fff2d02 mgmt/mcumgr/lib: Fix unneeded stats gathering when container failed
The commit makes stats collection conditional so in case when
CBOR container encoding fails the stats collecting function
will not be called.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-22 14:49:35 +01:00
Jamie McCrae 6d7d414204 mgmt: mcumgr: lib: smp: Fix checking variable before set
Fixes a twister test issue whereby handler_found and valid_hdr variables
are checked prior to being set.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2022-03-22 08:32:03 -04:00
Dominik Ermel 5a4f5abc4d mgmt/mcumgr/lib: Fix CONFIG_IMG_MGMT_VERBOSE_ERR
The IMG_MGMT_VERBOSE_ERR Kconfig option has not been really working
since the SMP response that it would setup was reset in case of
error, so in any instance that it would actually be used.

Fixes #32545

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-22 11:40:19 +01:00
Dominik Ermel 41cc3f04a0 mgmt/mcumgr/lib: Add support for "rsn" in error SMP responses
The commit adds support for passing "rsn" explanation strings,
for "rc" code, in error SMP responses.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-22 11:40:19 +01:00
Dominik Ermel cbd48e1294 mgmt/mcumgr/lib: FS mgmt replace zephyr_fs_mgmt_truncate
The zephyr_fs_mgmt_truncate has been replaced with fs_unlink
since there is no point to specially check for file existence
before just removing it.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-22 11:38:53 +01:00
Dominik Ermel a0d379a646 mgmt/mcumgr/lib: Fix return paths code style
Functions fs_mgmt_impl_read and fs_mgmt_impl_write have been missing
proper returns.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-22 11:38:53 +01:00
Dominik Ermel 02f355c541 mgmt/mcumgr/lib: FS management reduce duplicated "rc" setting code
The fs_mgmt_file_upload_rsp has been renamed fs_mgmt_file_rsp
and is used everywhere where "rc" code and "off" is placed into
response, instead of duplicating code that does the task.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-22 11:38:53 +01:00