Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
fcc_bundle_config_params_utils.c
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // Licensed under the Apache License, Version 2.0 (the "License"); 00005 // you may not use this file except in compliance with the License. 00006 // You may obtain a copy of the License at 00007 // 00008 // http://www.apache.org/licenses/LICENSE-2.0 00009 // 00010 // Unless required by applicable law or agreed to in writing, software 00011 // distributed under the License is distributed on an "AS IS" BASIS, 00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 // See the License for the specific language governing permissions and 00014 // limitations under the License. 00015 // ---------------------------------------------------------------------------- 00016 #include "fcc_bundle_handler.h" 00017 #include "cn-cbor.h" 00018 #include "pv_error_handling.h" 00019 #include "fcc_bundle_utils.h" 00020 #include "key_config_manager.h" 00021 #include "fcc_defs.h" 00022 #include "fcc_output_info_handler.h" 00023 #include "factory_configurator_client.h" 00024 #include "general_utils.h" 00025 #include "fcc_time_profiling.h" 00026 #include "fcc_utils.h" 00027 00028 static fcc_status_e set_time_from_config_param(const fcc_bundle_data_param_s *current_time) 00029 { 00030 00031 fcc_status_e status; 00032 uint64_t time = 0; 00033 00034 SA_PV_ERR_RECOVERABLE_RETURN_IF((current_time == NULL), FCC_STATUS_INVALID_PARAMETER, "Got invalid or corrupted 'current_time' pointer"); 00035 00036 // Check given time length before copying 00037 SA_PV_ERR_RECOVERABLE_RETURN_IF((current_time->data_size > sizeof(uint64_t)), FCC_STATUS_MEMORY_OUT, "Time length (%" PRIu32 "B) too long (corrupted format?)", (uint32_t)current_time->data_size); 00038 memcpy(&time, current_time->data, current_time->data_size); 00039 00040 status = fcc_time_set(time); 00041 SA_PV_ERR_RECOVERABLE_RETURN_IF((status != FCC_STATUS_SUCCESS), FCC_STATUS_ERROR, "fcc_time_set failed"); 00042 00043 00044 return FCC_STATUS_SUCCESS; 00045 } 00046 00047 fcc_status_e fcc_bundle_process_config_params(const cn_cbor *config_params_list_cb) 00048 { 00049 00050 bool success = false; 00051 fcc_status_e fcc_status = FCC_STATUS_SUCCESS; 00052 fcc_status_e output_info_fcc_status = FCC_STATUS_SUCCESS; 00053 kcm_status_e kcm_result = KCM_STATUS_SUCCESS; 00054 uint32_t config_param_index = 0; 00055 cn_cbor *config_param_cb; 00056 fcc_bundle_data_param_s config_param; 00057 size_t currentTimeLength = strlen(g_fcc_current_time_parameter_name); 00058 00059 SA_PV_LOG_TRACE_FUNC_ENTER_NO_ARGS(); 00060 SA_PV_ERR_RECOVERABLE_RETURN_IF((config_params_list_cb == NULL), fcc_status = FCC_STATUS_INVALID_PARAMETER, "Invalid config_params_list_cb pointer"); 00061 00062 //Initialize data struct 00063 memset(&config_param, 0, sizeof(config_param)); 00064 00065 for (config_param_index = 0; config_param_index < (uint32_t)config_params_list_cb->length; config_param_index++) { 00066 00067 FCC_SET_START_TIMER(fcc_config_param_timer); 00068 00069 //fcc_bundle_clean_and_free_data_param(&config_param); 00070 00071 //Get key CBOR struct at index key_index 00072 config_param_cb = cn_cbor_index(config_params_list_cb, config_param_index); 00073 SA_PV_ERR_RECOVERABLE_RETURN_IF((config_param_cb == NULL), fcc_status = FCC_STATUS_BUNDLE_ERROR, "Failed to get certificate at index (%" PRIu32 ") ", config_param_index); 00074 SA_PV_ERR_RECOVERABLE_RETURN_IF((config_param_cb->type != CN_CBOR_MAP), fcc_status = FCC_STATUS_BUNDLE_ERROR, "Wrong type of config param CBOR struct at index (%" PRIu32 ")", config_param_index); 00075 00076 success = fcc_bundle_get_data_param(config_param_cb, &config_param); 00077 SA_PV_ERR_RECOVERABLE_RETURN_IF((success != true), fcc_status = FCC_STATUS_BUNDLE_ERROR, "Failed to get config param data at index (%" PRIu32 ") ", config_param_index); 00078 00079 // Sets the time 00080 if (is_memory_equal(config_param.name, config_param.name_len, g_fcc_current_time_parameter_name, currentTimeLength)) { 00081 fcc_status = set_time_from_config_param(&config_param); 00082 SA_PV_ERR_RECOVERABLE_GOTO_IF((fcc_status != FCC_STATUS_SUCCESS), fcc_status = fcc_status, exit, "set_time_from_config_param failed"); 00083 } else { 00084 kcm_result = kcm_item_store(config_param.name, config_param.name_len, KCM_CONFIG_ITEM, true, config_param.data, config_param.data_size, config_param.acl); 00085 SA_PV_ERR_RECOVERABLE_GOTO_IF((kcm_result != KCM_STATUS_SUCCESS), fcc_status = fcc_convert_kcm_to_fcc_status(kcm_result), exit, "Failed to store configuration parameter at index (%" PRIu32 ") ", (uint32_t)config_param_index); 00086 } 00087 FCC_END_TIMER((char*)config_param.name, config_param.name_len, fcc_config_param_timer); 00088 } 00089 00090 exit: 00091 if (kcm_result != KCM_STATUS_SUCCESS) { 00092 00093 output_info_fcc_status = fcc_bundle_store_error_info(config_param.name, config_param.name_len, kcm_result); 00094 SA_PV_ERR_RECOVERABLE_RETURN_IF((output_info_fcc_status != FCC_STATUS_SUCCESS), 00095 fcc_status = FCC_STATUS_OUTPUT_INFO_ERROR, 00096 "Failed to create output kcm_status error %d", kcm_result); 00097 } 00098 fcc_bundle_clean_and_free_data_param(&config_param); 00099 SA_PV_LOG_TRACE_FUNC_EXIT_NO_ARGS(); 00100 00101 return fcc_status; 00102 }
Generated on Tue Jul 12 2022 20:20:59 by
