I added functionality to get the RSSI, BER, and Cell Neighbor for reporting connection issues to M2X

Dependencies:   WncControllerK64F

Committer:
JMF
Date:
Tue Nov 01 14:22:56 2016 +0000
Revision:
12:0071cb144c7a
Adding mbedtls files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 12:0071cb144c7a 1 /*
JMF 12:0071cb144c7a 2 * Hardware entropy collector for the K64F, using Freescale's RNGA
JMF 12:0071cb144c7a 3 *
JMF 12:0071cb144c7a 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
JMF 12:0071cb144c7a 5 * SPDX-License-Identifier: Apache-2.0
JMF 12:0071cb144c7a 6 *
JMF 12:0071cb144c7a 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
JMF 12:0071cb144c7a 8 * not use this file except in compliance with the License.
JMF 12:0071cb144c7a 9 * You may obtain a copy of the License at
JMF 12:0071cb144c7a 10 *
JMF 12:0071cb144c7a 11 * http://www.apache.org/licenses/LICENSE-2.0
JMF 12:0071cb144c7a 12 *
JMF 12:0071cb144c7a 13 * Unless required by applicable law or agreed to in writing, software
JMF 12:0071cb144c7a 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
JMF 12:0071cb144c7a 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 12:0071cb144c7a 16 * See the License for the specific language governing permissions and
JMF 12:0071cb144c7a 17 * limitations under the License.
JMF 12:0071cb144c7a 18 *
JMF 12:0071cb144c7a 19 * This file is part of mbed TLS (https://tls.mbed.org)
JMF 12:0071cb144c7a 20 */
JMF 12:0071cb144c7a 21
JMF 12:0071cb144c7a 22 /*
JMF 12:0071cb144c7a 23 * WARNING: this is temporary!
JMF 12:0071cb144c7a 24 * This should be in a separate yotta module which would be a target
JMF 12:0071cb144c7a 25 * dependency of mbedtls (see IOTSSL-313)
JMF 12:0071cb144c7a 26 */
JMF 12:0071cb144c7a 27
JMF 12:0071cb144c7a 28 #if defined(TARGET_LIKE_K64F)
JMF 12:0071cb144c7a 29
JMF 12:0071cb144c7a 30 /*
JMF 12:0071cb144c7a 31 * Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
JMF 12:0071cb144c7a 32 */
JMF 12:0071cb144c7a 33
JMF 12:0071cb144c7a 34 #include "fsl_clock_manager.h"
JMF 12:0071cb144c7a 35
JMF 12:0071cb144c7a 36 /*
JMF 12:0071cb144c7a 37 * Get one byte of entropy from the RNG, assuming it is up and running.
JMF 12:0071cb144c7a 38 * As recommended (34.1.1), get only one bit of each output.
JMF 12:0071cb144c7a 39 */
JMF 12:0071cb144c7a 40 static void rng_get_byte( unsigned char *byte )
JMF 12:0071cb144c7a 41 {
JMF 12:0071cb144c7a 42 size_t bit;
JMF 12:0071cb144c7a 43
JMF 12:0071cb144c7a 44 /* 34.5 Steps 3-4-5: poll SR and read from OR when ready */
JMF 12:0071cb144c7a 45 for( bit = 0; bit < 8; bit++ )
JMF 12:0071cb144c7a 46 {
JMF 12:0071cb144c7a 47 while( ( RNG->SR & RNG_SR_OREG_LVL_MASK ) == 0 );
JMF 12:0071cb144c7a 48 *byte |= ( RNG->OR & 1 ) << bit;
JMF 12:0071cb144c7a 49 }
JMF 12:0071cb144c7a 50 }
JMF 12:0071cb144c7a 51
JMF 12:0071cb144c7a 52 /*
JMF 12:0071cb144c7a 53 * Get len bytes of entropy from the hardware RNG.
JMF 12:0071cb144c7a 54 */
JMF 12:0071cb144c7a 55 int mbedtls_hardware_poll( void *data,
JMF 12:0071cb144c7a 56 unsigned char *output, size_t len, size_t *olen )
JMF 12:0071cb144c7a 57 {
JMF 12:0071cb144c7a 58 size_t i;
JMF 12:0071cb144c7a 59 int ret;
JMF 12:0071cb144c7a 60 ((void) data);
JMF 12:0071cb144c7a 61
JMF 12:0071cb144c7a 62 CLOCK_SYS_EnableRngaClock( 0 );
JMF 12:0071cb144c7a 63
JMF 12:0071cb144c7a 64 /* Set "Interrupt Mask", "High Assurance" and "Go",
JMF 12:0071cb144c7a 65 * unset "Clear interrupt" and "Sleep" */
JMF 12:0071cb144c7a 66 RNG->CR = RNG_CR_INTM_MASK | RNG_CR_HA_MASK | RNG_CR_GO_MASK;
JMF 12:0071cb144c7a 67
JMF 12:0071cb144c7a 68 for( i = 0; i < len; i++ )
JMF 12:0071cb144c7a 69 rng_get_byte( output + i );
JMF 12:0071cb144c7a 70
JMF 12:0071cb144c7a 71 /* Just be extra sure that we didn't do it wrong */
JMF 12:0071cb144c7a 72 if( ( RNG->SR & RNG_SR_SECV_MASK ) != 0 )
JMF 12:0071cb144c7a 73 {
JMF 12:0071cb144c7a 74 ret = -1;
JMF 12:0071cb144c7a 75 goto cleanup;
JMF 12:0071cb144c7a 76 }
JMF 12:0071cb144c7a 77
JMF 12:0071cb144c7a 78 *olen = len;
JMF 12:0071cb144c7a 79 ret = 0;
JMF 12:0071cb144c7a 80
JMF 12:0071cb144c7a 81 cleanup:
JMF 12:0071cb144c7a 82 /* Disable clock to save power - assume we're the only users of RNG */
JMF 12:0071cb144c7a 83 CLOCK_SYS_DisableRngaClock( 0 );
JMF 12:0071cb144c7a 84
JMF 12:0071cb144c7a 85 return( ret );
JMF 12:0071cb144c7a 86 }
JMF 12:0071cb144c7a 87
JMF 12:0071cb144c7a 88 #endif