Mayank Gupta / Mbed OS pelion-example-frdm

Dependencies:   FXAS21002 FXOS8700Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_uc_device_identity.c Source File

arm_uc_device_identity.c

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2016-2017 ARM Ltd.
00003 //
00004 // SPDX-License-Identifier: Apache-2.0
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the "License");
00007 // you may not use this file except in compliance with the License.
00008 // You may obtain a copy of the License at
00009 //
00010 //     http://www.apache.org/licenses/LICENSE-2.0
00011 //
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 // ----------------------------------------------------------------------------
00018 
00019 #include "pal4life-device-identity/pal_device_identity.h"
00020 #include "update-client-common/arm_uc_config.h"
00021 
00022 #if defined(ARM_UC_FEATURE_IDENTITY_KCM) && (ARM_UC_FEATURE_IDENTITY_KCM == 1)
00023 extern const ARM_PAL_DEVICE_IDENTITY arm_uc_device_identity_kcm;
00024 static const ARM_PAL_DEVICE_IDENTITY *arm_uc_device_identity =
00025     &arm_uc_device_identity_kcm;
00026 #elif defined(ARM_UC_FEATURE_IDENTITY_RAW_CONFIG) && (ARM_UC_FEATURE_IDENTITY_RAW_CONFIG == 1)
00027 extern const ARM_PAL_DEVICE_IDENTITY arm_uc_device_identity_raw;
00028 static const ARM_PAL_DEVICE_IDENTITY *arm_uc_device_identity =
00029     &arm_uc_device_identity_raw;
00030 #elif defined(ARM_UC_FEATURE_IDENTITY_NVSTORE) && (ARM_UC_FEATURE_IDENTITY_NVSTORE == 1)
00031 extern const ARM_PAL_DEVICE_IDENTITY arm_uc_device_identity_nvstore;
00032 static const ARM_PAL_DEVICE_IDENTITY *arm_uc_device_identity =
00033     &arm_uc_device_identity_nvstore;
00034 #else
00035 #error No configuration store set
00036 #endif
00037 
00038 /**
00039  * @brief Function for setting the vendor GUID.
00040  * @details The GUID is copied.
00041  * @param vendor_guid Pointer to a arm_uc_guid_t GUID.
00042  * @return Error code.
00043  */
00044 arm_uc_error_t pal_setVendorGuid(const arm_uc_guid_t *vendor_guid)
00045 {
00046     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00047 
00048     if (arm_uc_device_identity) {
00049         result = arm_uc_device_identity->SetVendorGuid(vendor_guid);
00050     }
00051 
00052     return result;
00053 }
00054 
00055 /**
00056  * @brief Function for getting a pointer to the vendor GUID.
00057  * @param vendor_guid Pointer to a arm_uc_guid_t pointer.
00058  * @return Error code.
00059  */
00060 arm_uc_error_t pal_getVendorGuid(arm_uc_guid_t *vendor_guid)
00061 {
00062     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00063 
00064     if (arm_uc_device_identity) {
00065         result = arm_uc_device_identity->GetVendorGuid(vendor_guid);
00066     }
00067 
00068     return result;
00069 }
00070 
00071 /**
00072  * @brief Function for setting the device class GUID.
00073  * @details The GUID is copied.
00074  * @param class_guid Pointer to a arm_uc_guid_t GUID.
00075  * @return Error code.
00076  */
00077 arm_uc_error_t pal_setClassGuid(const arm_uc_guid_t *class_guid)
00078 {
00079     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00080 
00081     if (arm_uc_device_identity) {
00082         result = arm_uc_device_identity->SetClassGuid(class_guid);
00083     }
00084 
00085     return result;
00086 }
00087 
00088 /**
00089  * @brief Function for getting a pointer to the device class GUID.
00090  * @param class_guid Pointer to a arm_uc_guid_t pointer.
00091  * @return Error code.
00092  */
00093 arm_uc_error_t pal_getClassGuid(arm_uc_guid_t *class_guid)
00094 {
00095     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00096 
00097     if (arm_uc_device_identity) {
00098         result = arm_uc_device_identity->GetClassGuid(class_guid);
00099     }
00100 
00101     return result;
00102 }
00103 
00104 /**
00105  * @brief Function for setting the device GUID.
00106  * @details The GUID is copied.
00107  * @param device_guid Pointer to a arm_uc_guid_t GUID.
00108  * @return Error code.
00109  */
00110 arm_uc_error_t pal_setDeviceGuid(const arm_uc_guid_t *device_guid)
00111 {
00112     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00113 
00114     if (arm_uc_device_identity) {
00115         result = arm_uc_device_identity->SetDeviceGuid(device_guid);
00116     }
00117 
00118     return result;
00119 }
00120 
00121 /**
00122  * @brief Function for getting a pointer to the device GUID.
00123  * @param device_guid Pointer to a arm_uc_guid_t pointer.
00124  * @return Error code.
00125  */
00126 arm_uc_error_t pal_getDeviceGuid(arm_uc_guid_t *device_guid)
00127 {
00128     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00129 
00130     if (arm_uc_device_identity) {
00131         result = arm_uc_device_identity->GetDeviceGuid(device_guid);
00132     }
00133 
00134     return result;
00135 }
00136 
00137 /**
00138  * @brief Check whether the three GUIDs provided are valid on the device.
00139  * @details
00140  * @param vendor_guid Buffer pointer to the Vendor GUID.
00141  * @param class_guid  Buffer pointer to the device class GUID.
00142  * @param device_guid Buffer pointer to the device GUID.
00143  * @return Error code.
00144  */
00145 arm_uc_error_t pal_deviceIdentityCheck(const arm_uc_buffer_t *vendor_guid,
00146                                        const arm_uc_buffer_t *class_guid,
00147                                        const arm_uc_buffer_t *device_guid)
00148 {
00149     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00150 
00151     if (arm_uc_device_identity) {
00152         result = arm_uc_device_identity->DeviceIdentityCheck(vendor_guid,
00153                                                              class_guid,
00154                                                              device_guid);
00155     }
00156 
00157     return result;
00158 }