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
pal_plat_rot.cpp
00001 /******************************************************************************* 00002 * Copyright 2016-2018 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 #ifdef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT 00017 #include "pal.h" 00018 #include "pal_plat_rot.h" 00019 #include "KVMap.h" 00020 #include "mbed_error.h" 00021 #include "TDBStore.h" 00022 #include "DeviceKey.h" 00023 00024 #define MAX_DEVICE_KEY_SIZE_IN_BYTES DEVICE_KEY_32BYTE 00025 00026 using namespace mbed; 00027 // If there is no "HW ROT", this code is enabled. It will in practice either use a pre-generated 00028 // ROT in SOTP or generate it once on the fly. 00029 #if (PAL_USE_HW_ROT == 0) 00030 00031 00032 #define TRACE_GROUP "PAL" 00033 00034 palStatus_t pal_plat_osGetRoT(uint8_t * key, size_t keyLenBytes) 00035 { 00036 int error; 00037 KVMap &kv_map = KVMap::get_instance(); 00038 KVStore *inner_store = kv_map.get_internal_kv_instance(NULL); 00039 00040 //Check key buffer 00041 if (key == NULL) { 00042 return PAL_ERR_INVALID_ARGUMENT ; 00043 } 00044 //Check key buffer size 00045 if (keyLenBytes != PAL_DEVICE_KEY_SIZE_IN_BYTES) { 00046 return PAL_ERR_INVALID_ARGUMENT ; 00047 } 00048 //Check internal instance 00049 if (inner_store == NULL) { 00050 return PAL_ERR_NULL_POINTER ; 00051 } 00052 00053 //Read ROT 00054 error = ((TDBStore *)inner_store)->reserved_data_get(key, keyLenBytes); 00055 if (error != MBED_SUCCESS) { 00056 if (error == MBED_ERROR_ITEM_NOT_FOUND) { 00057 return PAL_ERR_ITEM_NOT_EXIST ; 00058 } 00059 return PAL_ERR_GENERIC_FAILURE ; 00060 } 00061 00062 return PAL_SUCCESS; 00063 } 00064 palStatus_t pal_plat_osSetRoT(uint8_t * key, size_t keyLenBytes) 00065 { 00066 int error; 00067 DeviceKey &devkey = DeviceKey::get_instance(); 00068 00069 //Check key buffer 00070 if (key == NULL) { 00071 return PAL_ERR_INVALID_ARGUMENT ; 00072 } 00073 //Check key buffer size 00074 if (keyLenBytes != PAL_DEVICE_KEY_SIZE_IN_BYTES) { 00075 return PAL_ERR_INVALID_ARGUMENT ; 00076 } 00077 00078 //Set ROT 00079 error = devkey.device_inject_root_of_trust((uint32_t*)key, keyLenBytes); 00080 if (error != MBED_SUCCESS) { 00081 if (error == DEVICEKEY_ALREADY_EXIST) { 00082 return PAL_ERR_ITEM_EXIST ; 00083 } 00084 return PAL_ERR_GENERIC_FAILURE ; 00085 } 00086 00087 return PAL_SUCCESS; 00088 } 00089 #endif // (PAL_USE_HW_ROT == 0) 00090 #endif //#ifdef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT
Generated on Tue Jul 12 2022 20:21:02 by
