Skip to content

Commit

Permalink
mgmt: smp: MCUMGR Client support
Browse files Browse the repository at this point in the history
MCUMGR client basic implemtation for support Image and OS grpup
commands.

Image Group:
* Image state read/write
* Image Upload secondary slot
* Image Erase secondary slot
OS group:
* Echo service
* Reset

Opeartion's are blocked call and cant't call inside worker queue.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
  • Loading branch information
Juha Heiskanen committed Apr 19, 2023
1 parent e4fb11a commit f6ee3f5
Show file tree
Hide file tree
Showing 4 changed files with 974 additions and 0 deletions.
212 changes: 212 additions & 0 deletions include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef H_MGMT_MCUMGR_CLIENT_
#define H_MGMT_MCUMGR_CLIENT_

#include <inttypes.h>

#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief MCUMGR Image Group response types.
*/
enum mcumgr_image_rsp_t {
/** Image state write or read response */
MGMT_IMAGE_STATE_RSP = 0,

/** Image Upload response*/
MGMT_IMAGE_UPLOAD_RSP,

/** Secondary image erase response */
MGMT_IMAGE_ERASE_RSP
};

/**
* @brief MCUMGR OS Group response types.
*/
enum mcumgr_os_rsp_t {
/** OS response */
MGMT_OS_ECHO_RSP = 0,

/** Image Upload response*/
MGMT_OS_RESET_RSP
};

/**
* @brief Image list data.
*/
struct mcumgr_image_data {
int slot_num;
int img_num;
char hash[33];
char version[16];
bool bootable;
bool pending;
bool confirmed;
bool active;
bool permanent;
};

/**
* @brief MCUMGR Image list response.
*/
struct mcumgr_image_state {
int image_list_length;
struct mcumgr_image_data *image_list;
};

/**
* @brief MCUMGR OS Echo response.
*/
struct mcumgr_os_echo_rsp {
const char *echo_res;
size_t echo_rsp_len;
};


/**
* @brief MCUMGR Image group response structure.
*/
struct mcumgr_client_image_gr_rsp {
/** Response type */
enum mcumgr_image_rsp_t cmd;
/** Response status */
int status;
union {
struct mcumgr_image_state image_state;
size_t image_uppload_offset;
};
};

/**
* @brief MCUMGR OS group response structure.
*/
struct mcumgr_client_os_gr_rsp {
/** Response type */
enum mcumgr_os_rsp_t cmd;
/** Response status */
int status;
union {
struct mcumgr_os_echo_rsp echo;
};
};

/**
* @brief MCUMGR client IMAGE group response callback.
*
* @param resp Pointer to response structure
*/
typedef void (*mgmt_client_gr_image_fn)(struct mcumgr_client_image_gr_rsp *resp);

/**
* @brief MCUMGR client OS group response callback.
*
* @param resp Pointer to response structure
*/
typedef void (*mgmt_client_gr_os_fn)(struct mcumgr_client_os_gr_rsp *resp);

/**
* @brief Register Image group response callback function.
*
*
* @param image_fn Response callback.
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/
int mcumgr_client_image_callback_register(mgmt_client_gr_image_fn image_fn);

/**
* @brief Register OS group response callback function.
*
*
* @param os_fn Response callback.
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/
int mcumgr_client_os_callback_register(mgmt_client_gr_os_fn os_fn);

/**
* @brief Init started Image Upload Process
*
*
* @param image_size Size of image in bytes.
*
* @param image_num Image Num.
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/
int mcumgr_client_image_upload_init(size_t image_size, int image_num);

/**
* @brief Upload part of image
*
*
* @param data Pointer to data.
*
* @param length Lenght of data.

Check warning on line 151 in include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TYPO_SPELLING

include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h:151 'Lenght' may be misspelled - perhaps 'Length'?
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/
int mcumgr_client_image_upload(const uint8_t *data, size_t length);

/**
* @brief Image state set for Image Confirm and test
*
* @param hash Pointer to Hash (Needed for test).

Check warning on line 160 in include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h:160 please, no space before tabs
*
* @param hash_len length of Hash (Needed for test).
*
* @param confirm Set false for test and true for confirmation.
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/

int mcumgr_client_image_state_write(char *hash, size_t hash_len, bool confirm);
/**
* @brief Read Image list
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/
int mcumgr_client_image_state_read(void);

/**
* @brief Erase selected Image Slot
*
* @param slot Slot number

Check warning on line 180 in include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h:180 please, no space before tabs
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/

int mcumgr_client_image_erase(uint32_t slot);
/**
* @brief SMP Send OS Echo message
*
* @param echo_string Echo string

Check warning on line 189 in include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h:189 please, no space before tabs
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/
int mcumgr_client_os_echo(const char *echo_string);

/**
* @brief SMP OS Reset command
*
* @return 0 on success, #mcumgr_err_t code on failure.
*/
int mcumgr_client_os_reset(void);

/**
* @brief Print image list information.
*
*/
void mcumgr_client_image_list_print(void);

#ifdef __cplusplus
}
#endif

#endif /* H_MGMT_MCUMGR_CLIENT_ */
6 changes: 6 additions & 0 deletions subsys/mgmt/mcumgr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ config MCUMGR_SMP_LEGACY_RC_BEHAVIOUR
If a command only returns a result code, this will mean that the
response will be empty with the new behaviour enabled, as opposed to
the old behaviour where the rc field will be present in the response.
config MCUMGR_CLIENT
bool "MCUMGR client"
select SMP_CLIENT
help
Add support for SMP Image Upload, Image state Write, Read, Erase and OS group Echo and
Reset service.

config SMP_CLIENT
bool "SMP Client"
Expand Down
4 changes: 4 additions & 0 deletions subsys/mgmt/mcumgr/smp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
# Protocol API is only exposed to MCUmgr internals.
zephyr_library(mgmt_mcumgr_protocol)
zephyr_library_sources(src/smp.c)
zephyr_library_sources_ifdef(CONFIG_MCUMGR_CLIENT src/mcumgr_client.c)
zephyr_library_sources_ifdef(CONFIG_SMP_CLIENT src/client.c)

zephyr_library_include_directories(include)
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/grp/img_mgmt/include)

0 comments on commit f6ee3f5

Please sign in to comment.