Skip to content

Commit

Permalink
platform: storage: remove generic word 'ota' in the apis
Browse files Browse the repository at this point in the history
  • Loading branch information
joelguittet committed Apr 10, 2024
1 parent 081a968 commit 69ab5ad
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 162 deletions.
56 changes: 28 additions & 28 deletions core/src/mender-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ typedef enum {
static mender_client_state_t mender_client_state = MENDER_CLIENT_STATE_INITIALIZATION;

/**
* @brief OTA ID and artifact name, used to report OTA status after rebooting
* @brief Deployment ID and artifact name, used to report deployment status after rebooting
*/
static char *mender_client_ota_id = NULL;
static char *mender_client_ota_artifact_name = NULL;
static char *mender_client_deployment_id = NULL;
static char *mender_client_deployment_artifact_name = NULL;

/**
* @brief Mender client work handle
Expand Down Expand Up @@ -285,13 +285,13 @@ mender_client_exit(void) {
mender_client_config.tenant_token = NULL;
mender_client_config.authentication_poll_interval = 0;
mender_client_config.update_poll_interval = 0;
if (NULL != mender_client_ota_id) {
free(mender_client_ota_id);
mender_client_ota_id = NULL;
if (NULL != mender_client_deployment_id) {
free(mender_client_deployment_id);
mender_client_deployment_id = NULL;
}
if (NULL != mender_client_ota_artifact_name) {
free(mender_client_ota_artifact_name);
mender_client_ota_artifact_name = NULL;
if (NULL != mender_client_deployment_artifact_name) {
free(mender_client_deployment_artifact_name);
mender_client_deployment_artifact_name = NULL;
}

return MENDER_OK;
Expand Down Expand Up @@ -347,10 +347,10 @@ mender_client_initialization_work_function(void) {
return ret;
}

/* Retrieve OTA ID if it is found (following an update) */
if (MENDER_OK != (ret = mender_storage_get_ota_deployment(&mender_client_ota_id, &mender_client_ota_artifact_name))) {
/* Retrieve deployment ID or artifact name if it is found (following an update) */
if (MENDER_OK != (ret = mender_storage_get_deployment(&mender_client_deployment_id, &mender_client_deployment_artifact_name))) {
if (MENDER_NOT_FOUND != ret) {
mender_log_error("Unable to get OTA ID");
mender_log_error("Unable to get deployment ID or artifact name");
return ret;
}
}
Expand All @@ -370,8 +370,8 @@ mender_client_authentication_work_function(void) {
if (NULL != mender_client_callbacks.authentication_failure) {
if (MENDER_OK != mender_client_callbacks.authentication_failure()) {

/* Check if OTA is pending */
if ((NULL != mender_client_ota_id) && (NULL != mender_client_ota_artifact_name)) {
/* Check if deployment is pending */
if ((NULL != mender_client_deployment_id) && (NULL != mender_client_deployment_artifact_name)) {
/* Authentication error callback inform the reboot should be done, probably something is broken and it prefers to rollback */
mender_log_error("Authentication error callback failed, rebooting");
goto REBOOT;
Expand All @@ -386,34 +386,34 @@ mender_client_authentication_work_function(void) {
if (NULL != mender_client_callbacks.authentication_success) {
if (MENDER_OK != mender_client_callbacks.authentication_success()) {

/* Check if OTA is pending */
if ((NULL != mender_client_ota_id) && (NULL != mender_client_ota_artifact_name)) {
/* Check if deployment is pending */
if ((NULL != mender_client_deployment_id) && (NULL != mender_client_deployment_artifact_name)) {
/* Authentication success callback inform the reboot should be done, probably something is broken and it prefers to rollback */
mender_log_error("Authentication success callback failed, rebooting");
goto REBOOT;
}
}
}

/* Check if OTA is pending */
if ((NULL != mender_client_ota_id) && (NULL != mender_client_ota_artifact_name)) {
/* Check if deployment is pending */
if ((NULL != mender_client_deployment_id) && (NULL != mender_client_deployment_artifact_name)) {

/* Check if artifact running is the pending one or if the configuration deployed is the expected one, fails if rollback occurred */
if ((!strcmp(mender_client_ota_artifact_name, mender_client_config.artifact_name))
|| ((mender_utils_strbeginwith(mender_client_ota_artifact_name, "configuration"))
&& (!strcmp(mender_client_ota_artifact_name + strlen("configuration") + 1, mender_client_ota_id)))) {
if ((!strcmp(mender_client_deployment_artifact_name, mender_client_config.artifact_name))
|| ((mender_utils_strbeginwith(mender_client_deployment_artifact_name, "configuration"))
&& (!strcmp(mender_client_deployment_artifact_name + strlen("configuration") + 1, mender_client_deployment_id)))) {

/* Publish deployment status success */
mender_client_publish_deployment_status(mender_client_ota_id, MENDER_DEPLOYMENT_STATUS_SUCCESS);
mender_client_publish_deployment_status(mender_client_deployment_id, MENDER_DEPLOYMENT_STATUS_SUCCESS);

} else {

/* Publish deployment status failure */
mender_client_publish_deployment_status(mender_client_ota_id, MENDER_DEPLOYMENT_STATUS_FAILURE);
mender_client_publish_deployment_status(mender_client_deployment_id, MENDER_DEPLOYMENT_STATUS_FAILURE);
}

/* Delete pending OTA */
mender_storage_delete_ota_deployment();
/* Delete pending deployment */
mender_storage_delete_deployment();
}

return MENDER_DONE;
Expand Down Expand Up @@ -475,9 +475,9 @@ mender_client_update_work_function(void) {
goto END;
}

/* Save OTA ID to publish deployment status after rebooting */
if (MENDER_OK != (ret = mender_storage_set_ota_deployment(id, artifact_name))) {
mender_log_error("Unable to save OTA ID");
/* Save deployment ID to publish deployment status after rebooting */
if (MENDER_OK != (ret = mender_storage_set_deployment(id, artifact_name))) {
mender_log_error("Unable to save deployment ID");
mender_client_publish_deployment_status(id, MENDER_DEPLOYMENT_STATUS_FAILURE);
goto END;
}
Expand Down
20 changes: 10 additions & 10 deletions include/mender-storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,26 @@ mender_err_t mender_storage_get_authentication_keys(unsigned char **private_key,
mender_err_t mender_storage_delete_authentication_keys(void);

/**
* @brief Set OTA deployment
* @param ota_id OTA ID to store
* @param ota_artifact_name Artifact name to store
* @brief Set deployment
* @param id Deployment ID to store
* @param artifact_name Deployment artifact name to store
* @return MENDER_OK if the function succeeds, error code otherwise
*/
mender_err_t mender_storage_set_ota_deployment(char *ota_id, char *ota_artifact_name);
mender_err_t mender_storage_set_deployment(char *id, char *artifact_name);

/**
* @brief Get OTA deployment
* @param ota_id OTA ID from storage, NULL if not found
* @param ota_artifact_name Artifact name from storage, NULL if not found
* @brief Get deployment
* @param id Deployment ID from storage, NULL if not found
* @param artifact_name Deployment artifact name from storage, NULL if not found
* @return MENDER_OK if the function succeeds, error code otherwise
*/
mender_err_t mender_storage_get_ota_deployment(char **ota_id, char **ota_artifact_name);
mender_err_t mender_storage_get_deployment(char **id, char **artifact_name);

/**
* @brief Delete OTA deployment
* @brief Delete deployment
* @return MENDER_OK if the function succeeds, error code otherwise
*/
mender_err_t mender_storage_delete_ota_deployment(void);
mender_err_t mender_storage_delete_deployment(void);

#ifdef CONFIG_MENDER_CLIENT_ADD_ON_CONFIGURE
#ifdef CONFIG_MENDER_CLIENT_CONFIGURE_STORAGE
Expand Down
76 changes: 38 additions & 38 deletions platform/storage/esp-idf/nvs/src/mender-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
/**
* @brief NVS keys
*/
#define MENDER_STORAGE_NVS_PRIVATE_KEY "key.der"
#define MENDER_STORAGE_NVS_PUBLIC_KEY "pubkey.der"
#define MENDER_STORAGE_NVS_OTA_ID "id"
#define MENDER_STORAGE_NVS_OTA_ARTIFACT_NAME "artifact_name"
#define MENDER_STORAGE_NVS_DEVICE_CONFIG "config.json"
#define MENDER_STORAGE_NVS_PRIVATE_KEY "key.der"
#define MENDER_STORAGE_NVS_PUBLIC_KEY "pubkey.der"
#define MENDER_STORAGE_NVS_DEPLOYMENT_ID "id"
#define MENDER_STORAGE_NVS_DEPLOYMENT_ARTIFACT_NAME "artifact_name"
#define MENDER_STORAGE_NVS_DEVICE_CONFIG "config.json"

/**
* @brief NVS storage handle
Expand Down Expand Up @@ -135,74 +135,74 @@ mender_storage_delete_authentication_keys(void) {
}

mender_err_t
mender_storage_set_ota_deployment(char *ota_id, char *ota_artifact_name) {
mender_storage_set_deployment(char *id, char *artifact_name) {

assert(NULL != ota_id);
assert(NULL != ota_artifact_name);
assert(NULL != id);
assert(NULL != artifact_name);

/* Write ID and artifact name */
if ((ESP_OK != nvs_set_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ID, ota_id))
|| (ESP_OK != nvs_set_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ARTIFACT_NAME, ota_artifact_name))) {
mender_log_error("Unable to write OTA ID or artifact name");
if ((ESP_OK != nvs_set_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ID, id))
|| (ESP_OK != nvs_set_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ARTIFACT_NAME, artifact_name))) {
mender_log_error("Unable to write deployment ID or artifact name");
return MENDER_FAIL;
}
if (ESP_OK != nvs_commit(mender_storage_nvs_handle)) {
mender_log_error("Unable to write OTA ID or artifact name");
mender_log_error("Unable to write deployment ID or artifact name");
return MENDER_FAIL;
}

return MENDER_OK;
}

mender_err_t
mender_storage_get_ota_deployment(char **ota_id, char **ota_artifact_name) {
mender_storage_get_deployment(char **id, char **artifact_name) {

assert(NULL != ota_id);
assert(NULL != ota_artifact_name);
size_t ota_id_length = 0;
size_t ota_artifact_name_length = 0;
assert(NULL != id);
assert(NULL != artifact_name);
size_t id_length = 0;
size_t artifact_name_length = 0;

/* Retrieve length of the ID and artifact name */
nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ID, NULL, &ota_id_length);
nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ARTIFACT_NAME, NULL, &ota_artifact_name_length);
if ((0 == ota_id_length) || (0 == ota_artifact_name_length)) {
mender_log_info("OTA ID or artifact name not available");
nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ID, NULL, &id_length);
nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ARTIFACT_NAME, NULL, &artifact_name_length);
if ((0 == id_length) || (0 == artifact_name_length)) {
mender_log_info("Deployment ID or artifact name not available");
return MENDER_NOT_FOUND;
}

/* Allocate memory to copy ID and artifact name */
if (NULL == (*ota_id = (char *)malloc(ota_id_length + 1))) {
/* Allocate memory to copy deployment ID and artifact name */
if (NULL == (*id = (char *)malloc(id_length + 1))) {
mender_log_error("Unable to allocate memory");
return MENDER_FAIL;
}
if (NULL == (*ota_artifact_name = (char *)malloc(ota_artifact_name_length + 1))) {
if (NULL == (*artifact_name = (char *)malloc(artifact_name_length + 1))) {
mender_log_error("Unable to allocate memory");
free(*ota_id);
*ota_id = NULL;
free(*id);
*id = NULL;
return MENDER_FAIL;
}

/* Read ID and artifact name */
if ((ESP_OK != nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ID, *ota_id, &ota_id_length))
|| (ESP_OK != nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ARTIFACT_NAME, *ota_artifact_name, &ota_artifact_name_length))) {
mender_log_error("Unable to read OTA ID or artifact name");
free(*ota_id);
*ota_id = NULL;
free(*ota_artifact_name);
*ota_artifact_name = NULL;
if ((ESP_OK != nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ID, *id, &id_length))
|| (ESP_OK != nvs_get_str(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ARTIFACT_NAME, *artifact_name, &artifact_name_length))) {
mender_log_error("Unable to read deployment ID or artifact name");
free(*id);
*id = NULL;
free(*artifact_name);
*artifact_name = NULL;
return MENDER_FAIL;
}

return MENDER_OK;
}

mender_err_t
mender_storage_delete_ota_deployment(void) {
mender_storage_delete_deployment(void) {

/* Delete ID and artifact name */
if ((ESP_OK != nvs_erase_key(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ID))
|| (ESP_OK != nvs_erase_key(mender_storage_nvs_handle, MENDER_STORAGE_NVS_OTA_ARTIFACT_NAME))) {
mender_log_error("Unable to delete OTA ID or artifact name");
/* Delete deployment ID and artifact name */
if ((ESP_OK != nvs_erase_key(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ID))
|| (ESP_OK != nvs_erase_key(mender_storage_nvs_handle, MENDER_STORAGE_NVS_DEPLOYMENT_ARTIFACT_NAME))) {
mender_log_error("Unable to delete deployment ID or artifact name");
return MENDER_FAIL;
}

Expand Down
14 changes: 7 additions & 7 deletions platform/storage/generic/weak/src/mender-storage.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ mender_storage_delete_authentication_keys(void) {
}

__attribute__((weak)) mender_err_t
mender_storage_set_ota_deployment(char *ota_id, char *ota_artifact_name) {
mender_storage_set_deployment(char *id, char *artifact_name) {

(void)ota_id;
(void)ota_artifact_name;
(void)id;
(void)artifact_name;

/* Nothing to do */
return MENDER_NOT_IMPLEMENTED;
}

__attribute__((weak)) mender_err_t
mender_storage_get_ota_deployment(char **ota_id, char **ota_artifact_name) {
mender_storage_get_deployment(char **id, char **artifact_name) {

(void)ota_id;
(void)ota_artifact_name;
(void)id;
(void)artifact_name;

/* Nothing to do */
return MENDER_NOT_IMPLEMENTED;
}

__attribute__((weak)) mender_err_t
mender_storage_delete_ota_deployment(void) {
mender_storage_delete_deployment(void) {

/* Nothing to do */
return MENDER_NOT_IMPLEMENTED;
Expand Down
Loading

0 comments on commit 69ab5ad

Please sign in to comment.