Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_uc_pre_shared_key.c Source File

arm_uc_pre_shared_key.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 "update-client-control-center/arm_uc_pre_shared_key.h"
00020 
00021 /* Pointer to the pre-shared-key. Module only supports 1 key at a time. */
00022 static const uint8_t* arm_uc_psk_key = NULL;
00023 static uint16_t arm_uc_psk_size = 0;
00024 
00025 /**
00026  * @brief Register event handler.
00027  *
00028  * @param callback Event handler to signal result.
00029  * @return Error code.
00030  */
00031 arm_uc_error_t ARM_UC_PreSharedKey_Initialize(void (*callback)(uint32_t))
00032 {
00033     return (arm_uc_error_t){ ERR_NONE};
00034 }
00035 
00036 /**
00037  * @brief Set pointer to pre-shared-key with the given size.
00038  *
00039  * @param key Pointer to pre-shared-key.
00040  * @param bits Key size in bits.
00041  *
00042  * @return Error code.
00043  */
00044 arm_uc_error_t ARM_UC_PreSharedKey_SetKey(const uint8_t* key, uint16_t bits)
00045 {
00046     arm_uc_psk_key = key;
00047     arm_uc_psk_size = bits;
00048 
00049     return (arm_uc_error_t){ ERR_NONE};
00050 }
00051 
00052 /**
00053  * @brief Get pointer to pre-shared-key with the given size.
00054  *
00055  * @param key Pointer-pointer to the shared key.
00056  * @param bits Key size in bits.
00057  *
00058  * @return Error code.
00059  */
00060 arm_uc_error_t ARM_UC_PreSharedKey_GetKey(const uint8_t** key, uint16_t bits)
00061 {
00062     arm_uc_error_t retval = (arm_uc_error_t){ ERR_INVALID_PARAMETER };
00063 
00064     if (key && (bits == arm_uc_psk_size))
00065     {
00066         /* set return value */
00067         retval = (arm_uc_error_t){ ERR_NONE };
00068 
00069         /* assign PSK pointer */
00070         *key = arm_uc_psk_key;
00071     }
00072 
00073     return retval;
00074 }