Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
fcc_dev_flow.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 00017 #include "factory_configurator_client.h" 00018 #include "key_config_manager.h" 00019 #include "fcc_defs.h" 00020 #include "pv_error_handling.h" 00021 #include "fcc_utils.h" 00022 00023 typedef struct fcc_deloveper_mode_item_params { 00024 const char *item_name; 00025 kcm_item_type_e item_kcm_type; 00026 const uint8_t *item_data; 00027 const uint32_t item_data_size; 00028 } fcc_deloveper_mode_item_params_s; 00029 00030 //bootstrap endpoint name 00031 extern const char MBED_CLOUD_DEV_BOOTSTRAP_ENDPOINT_NAME[]; 00032 //bootstrap server uri 00033 extern const char MBED_CLOUD_DEV_BOOTSTRAP_SERVER_URI[]; 00034 //bootstrap device certificate 00035 extern const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE[]; 00036 extern const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE_SIZE; 00037 //bootstrap server root ca certificate 00038 extern const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE[]; 00039 extern const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE_SIZE; 00040 //bootstrap device private key 00041 extern const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY[]; 00042 extern const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY_SIZE; 00043 //device manufacturer 00044 extern const char MBED_CLOUD_DEV_MANUFACTURER[]; 00045 //device model number 00046 extern const char MBED_CLOUD_DEV_MODEL_NUMBER[]; 00047 //device serial number 00048 extern const char MBED_CLOUD_DEV_SERIAL_NUMBER[]; 00049 //device type 00050 extern const char MBED_CLOUD_DEV_DEVICE_TYPE[]; 00051 //device hw version 00052 extern const char MBED_CLOUD_DEV_HARDWARE_VERSION[]; 00053 //device total memory 00054 extern const uint32_t MBED_CLOUD_DEV_MEMORY_TOTAL_KB; 00055 00056 00057 fcc_status_e fcc_developer_flow(void) 00058 { 00059 kcm_status_e kcm_status = KCM_STATUS_SUCCESS; 00060 fcc_status_e fcc_status = FCC_STATUS_SUCCESS; 00061 const bool is_factory_item = true; 00062 static const uint32_t is_bootstrap_mode = 1; 00063 const fcc_deloveper_mode_item_params_s fcc_deloveper_mode_item_params_table[] = { 00064 00065 //param name //param kcm type //param data //param data_size 00066 //Device general info 00067 { g_fcc_use_bootstrap_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)&is_bootstrap_mode, sizeof(uint32_t) }, 00068 { g_fcc_endpoint_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)MBED_CLOUD_DEV_BOOTSTRAP_ENDPOINT_NAME, (uint32_t)strlen((char*)MBED_CLOUD_DEV_BOOTSTRAP_ENDPOINT_NAME) }, 00069 //Bootstrap configuration 00070 { g_fcc_bootstrap_device_certificate_name, KCM_CERTIFICATE_ITEM, MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE, MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE_SIZE }, 00071 { g_fcc_bootstrap_server_ca_certificate_name, KCM_CERTIFICATE_ITEM, MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE, MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE_SIZE }, 00072 { g_fcc_bootstrap_device_private_key_name, KCM_PRIVATE_KEY_ITEM, MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY, MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY_SIZE }, 00073 { g_fcc_bootstrap_server_uri_name, KCM_CONFIG_ITEM, (const uint8_t*)MBED_CLOUD_DEV_BOOTSTRAP_SERVER_URI, (uint32_t)strlen((char*)MBED_CLOUD_DEV_BOOTSTRAP_SERVER_URI) }, 00074 //device meta data 00075 { g_fcc_manufacturer_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)MBED_CLOUD_DEV_MANUFACTURER, (uint32_t)strlen((char*)MBED_CLOUD_DEV_MANUFACTURER) }, 00076 { g_fcc_model_number_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)MBED_CLOUD_DEV_MODEL_NUMBER, (uint32_t)strlen((char*)MBED_CLOUD_DEV_MODEL_NUMBER) }, 00077 { g_fcc_device_serial_number_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)MBED_CLOUD_DEV_SERIAL_NUMBER, (uint32_t)strlen((char*)MBED_CLOUD_DEV_SERIAL_NUMBER) }, 00078 { g_fcc_device_type_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)MBED_CLOUD_DEV_DEVICE_TYPE, (uint32_t)strlen((char*)MBED_CLOUD_DEV_DEVICE_TYPE) }, 00079 { g_fcc_hardware_version_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)MBED_CLOUD_DEV_HARDWARE_VERSION, (uint32_t)strlen((char*)MBED_CLOUD_DEV_HARDWARE_VERSION) }, 00080 { g_fcc_memory_size_parameter_name, KCM_CONFIG_ITEM, (const uint8_t*)&MBED_CLOUD_DEV_MEMORY_TOTAL_KB, sizeof(uint32_t) }, 00081 00082 //last item 00083 { NULL, KCM_LAST_ITEM, NULL, 0}, 00084 }; 00085 00086 const fcc_deloveper_mode_item_params_s* mandatory_items_iter = &fcc_deloveper_mode_item_params_table[0]; 00087 00088 SA_PV_LOG_INFO_FUNC_ENTER_NO_ARGS(); 00089 00090 for (; mandatory_items_iter->item_name!= NULL; mandatory_items_iter++) { 00091 00092 kcm_status = kcm_item_store((const uint8_t*)(mandatory_items_iter->item_name), strlen(mandatory_items_iter->item_name), mandatory_items_iter->item_kcm_type, is_factory_item, 00093 (const uint8_t*)(mandatory_items_iter->item_data), mandatory_items_iter->item_data_size, NULL); 00094 00095 //FIXME : add relevant error translation. 00096 SA_PV_ERR_RECOVERABLE_RETURN_IF((kcm_status != KCM_STATUS_SUCCESS), fcc_convert_kcm_to_fcc_status(kcm_status), "Store status: %d, Failed to store %s", kcm_status, mandatory_items_iter->item_name); 00097 } 00098 00099 fcc_status = fcc_trust_ca_cert_id_set(); 00100 SA_PV_ERR_RECOVERABLE_RETURN_IF((fcc_status != FCC_STATUS_SUCCESS), fcc_status, "Failed to set ca certificate identifier"); 00101 00102 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00103 00104 return fcc_status; 00105 }
Generated on Tue Jul 12 2022 19:01:34 by 1.7.2