-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
974 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
* @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). | ||
* | ||
* @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 | ||
* | ||
* @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 | ||
* | ||
* @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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.