Commit graph

658 commits

Author SHA1 Message Date
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
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