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

Dependencies:   WncControllerK64F

Committer:
JMF
Date:
Thu Nov 17 16:13:29 2016 +0000
Revision:
18:198e9b0acf11
Parent:
12:0071cb144c7a
Updates to mbed os resulted in mutex.h going away and rtos.h needed to be used; This fixes the Mutex typedef failure.  Also cast data buffers from 'char *' to (const std::uint8_t*) to conform with Fred's changes in WncController

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 12:0071cb144c7a 1 /*
JMF 12:0071cb144c7a 2 * VIA PadLock support functions
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 * This implementation is based on the VIA PadLock Programming Guide:
JMF 12:0071cb144c7a 23 *
JMF 12:0071cb144c7a 24 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/
JMF 12:0071cb144c7a 25 * programming_guide.pdf
JMF 12:0071cb144c7a 26 */
JMF 12:0071cb144c7a 27
JMF 12:0071cb144c7a 28 #if !defined(MBEDTLS_CONFIG_FILE)
JMF 12:0071cb144c7a 29 #include "mbedtls/config.h"
JMF 12:0071cb144c7a 30 #else
JMF 12:0071cb144c7a 31 #include MBEDTLS_CONFIG_FILE
JMF 12:0071cb144c7a 32 #endif
JMF 12:0071cb144c7a 33
JMF 12:0071cb144c7a 34 #if defined(MBEDTLS_PADLOCK_C)
JMF 12:0071cb144c7a 35
JMF 12:0071cb144c7a 36 #include "mbedtls/padlock.h"
JMF 12:0071cb144c7a 37
JMF 12:0071cb144c7a 38 #include <string.h>
JMF 12:0071cb144c7a 39
JMF 12:0071cb144c7a 40 #ifndef asm
JMF 12:0071cb144c7a 41 #define asm __asm
JMF 12:0071cb144c7a 42 #endif
JMF 12:0071cb144c7a 43
JMF 12:0071cb144c7a 44 #if defined(MBEDTLS_HAVE_X86)
JMF 12:0071cb144c7a 45
JMF 12:0071cb144c7a 46 /*
JMF 12:0071cb144c7a 47 * PadLock detection routine
JMF 12:0071cb144c7a 48 */
JMF 12:0071cb144c7a 49 int mbedtls_padlock_has_support( int feature )
JMF 12:0071cb144c7a 50 {
JMF 12:0071cb144c7a 51 static int flags = -1;
JMF 12:0071cb144c7a 52 int ebx = 0, edx = 0;
JMF 12:0071cb144c7a 53
JMF 12:0071cb144c7a 54 if( flags == -1 )
JMF 12:0071cb144c7a 55 {
JMF 12:0071cb144c7a 56 asm( "movl %%ebx, %0 \n\t"
JMF 12:0071cb144c7a 57 "movl $0xC0000000, %%eax \n\t"
JMF 12:0071cb144c7a 58 "cpuid \n\t"
JMF 12:0071cb144c7a 59 "cmpl $0xC0000001, %%eax \n\t"
JMF 12:0071cb144c7a 60 "movl $0, %%edx \n\t"
JMF 12:0071cb144c7a 61 "jb unsupported \n\t"
JMF 12:0071cb144c7a 62 "movl $0xC0000001, %%eax \n\t"
JMF 12:0071cb144c7a 63 "cpuid \n\t"
JMF 12:0071cb144c7a 64 "unsupported: \n\t"
JMF 12:0071cb144c7a 65 "movl %%edx, %1 \n\t"
JMF 12:0071cb144c7a 66 "movl %2, %%ebx \n\t"
JMF 12:0071cb144c7a 67 : "=m" (ebx), "=m" (edx)
JMF 12:0071cb144c7a 68 : "m" (ebx)
JMF 12:0071cb144c7a 69 : "eax", "ecx", "edx" );
JMF 12:0071cb144c7a 70
JMF 12:0071cb144c7a 71 flags = edx;
JMF 12:0071cb144c7a 72 }
JMF 12:0071cb144c7a 73
JMF 12:0071cb144c7a 74 return( flags & feature );
JMF 12:0071cb144c7a 75 }
JMF 12:0071cb144c7a 76
JMF 12:0071cb144c7a 77 /*
JMF 12:0071cb144c7a 78 * PadLock AES-ECB block en(de)cryption
JMF 12:0071cb144c7a 79 */
JMF 12:0071cb144c7a 80 int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
JMF 12:0071cb144c7a 81 int mode,
JMF 12:0071cb144c7a 82 const unsigned char input[16],
JMF 12:0071cb144c7a 83 unsigned char output[16] )
JMF 12:0071cb144c7a 84 {
JMF 12:0071cb144c7a 85 int ebx = 0;
JMF 12:0071cb144c7a 86 uint32_t *rk;
JMF 12:0071cb144c7a 87 uint32_t *blk;
JMF 12:0071cb144c7a 88 uint32_t *ctrl;
JMF 12:0071cb144c7a 89 unsigned char buf[256];
JMF 12:0071cb144c7a 90
JMF 12:0071cb144c7a 91 rk = ctx->rk;
JMF 12:0071cb144c7a 92 blk = MBEDTLS_PADLOCK_ALIGN16( buf );
JMF 12:0071cb144c7a 93 memcpy( blk, input, 16 );
JMF 12:0071cb144c7a 94
JMF 12:0071cb144c7a 95 ctrl = blk + 4;
JMF 12:0071cb144c7a 96 *ctrl = 0x80 | ctx->nr | ( ( ctx->nr + ( mode^1 ) - 10 ) << 9 );
JMF 12:0071cb144c7a 97
JMF 12:0071cb144c7a 98 asm( "pushfl \n\t"
JMF 12:0071cb144c7a 99 "popfl \n\t"
JMF 12:0071cb144c7a 100 "movl %%ebx, %0 \n\t"
JMF 12:0071cb144c7a 101 "movl $1, %%ecx \n\t"
JMF 12:0071cb144c7a 102 "movl %2, %%edx \n\t"
JMF 12:0071cb144c7a 103 "movl %3, %%ebx \n\t"
JMF 12:0071cb144c7a 104 "movl %4, %%esi \n\t"
JMF 12:0071cb144c7a 105 "movl %4, %%edi \n\t"
JMF 12:0071cb144c7a 106 ".byte 0xf3,0x0f,0xa7,0xc8 \n\t"
JMF 12:0071cb144c7a 107 "movl %1, %%ebx \n\t"
JMF 12:0071cb144c7a 108 : "=m" (ebx)
JMF 12:0071cb144c7a 109 : "m" (ebx), "m" (ctrl), "m" (rk), "m" (blk)
JMF 12:0071cb144c7a 110 : "memory", "ecx", "edx", "esi", "edi" );
JMF 12:0071cb144c7a 111
JMF 12:0071cb144c7a 112 memcpy( output, blk, 16 );
JMF 12:0071cb144c7a 113
JMF 12:0071cb144c7a 114 return( 0 );
JMF 12:0071cb144c7a 115 }
JMF 12:0071cb144c7a 116
JMF 12:0071cb144c7a 117 /*
JMF 12:0071cb144c7a 118 * PadLock AES-CBC buffer en(de)cryption
JMF 12:0071cb144c7a 119 */
JMF 12:0071cb144c7a 120 int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
JMF 12:0071cb144c7a 121 int mode,
JMF 12:0071cb144c7a 122 size_t length,
JMF 12:0071cb144c7a 123 unsigned char iv[16],
JMF 12:0071cb144c7a 124 const unsigned char *input,
JMF 12:0071cb144c7a 125 unsigned char *output )
JMF 12:0071cb144c7a 126 {
JMF 12:0071cb144c7a 127 int ebx = 0;
JMF 12:0071cb144c7a 128 size_t count;
JMF 12:0071cb144c7a 129 uint32_t *rk;
JMF 12:0071cb144c7a 130 uint32_t *iw;
JMF 12:0071cb144c7a 131 uint32_t *ctrl;
JMF 12:0071cb144c7a 132 unsigned char buf[256];
JMF 12:0071cb144c7a 133
JMF 12:0071cb144c7a 134 if( ( (long) input & 15 ) != 0 ||
JMF 12:0071cb144c7a 135 ( (long) output & 15 ) != 0 )
JMF 12:0071cb144c7a 136 return( MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED );
JMF 12:0071cb144c7a 137
JMF 12:0071cb144c7a 138 rk = ctx->rk;
JMF 12:0071cb144c7a 139 iw = MBEDTLS_PADLOCK_ALIGN16( buf );
JMF 12:0071cb144c7a 140 memcpy( iw, iv, 16 );
JMF 12:0071cb144c7a 141
JMF 12:0071cb144c7a 142 ctrl = iw + 4;
JMF 12:0071cb144c7a 143 *ctrl = 0x80 | ctx->nr | ( ( ctx->nr + ( mode ^ 1 ) - 10 ) << 9 );
JMF 12:0071cb144c7a 144
JMF 12:0071cb144c7a 145 count = ( length + 15 ) >> 4;
JMF 12:0071cb144c7a 146
JMF 12:0071cb144c7a 147 asm( "pushfl \n\t"
JMF 12:0071cb144c7a 148 "popfl \n\t"
JMF 12:0071cb144c7a 149 "movl %%ebx, %0 \n\t"
JMF 12:0071cb144c7a 150 "movl %2, %%ecx \n\t"
JMF 12:0071cb144c7a 151 "movl %3, %%edx \n\t"
JMF 12:0071cb144c7a 152 "movl %4, %%ebx \n\t"
JMF 12:0071cb144c7a 153 "movl %5, %%esi \n\t"
JMF 12:0071cb144c7a 154 "movl %6, %%edi \n\t"
JMF 12:0071cb144c7a 155 "movl %7, %%eax \n\t"
JMF 12:0071cb144c7a 156 ".byte 0xf3,0x0f,0xa7,0xd0 \n\t"
JMF 12:0071cb144c7a 157 "movl %1, %%ebx \n\t"
JMF 12:0071cb144c7a 158 : "=m" (ebx)
JMF 12:0071cb144c7a 159 : "m" (ebx), "m" (count), "m" (ctrl),
JMF 12:0071cb144c7a 160 "m" (rk), "m" (input), "m" (output), "m" (iw)
JMF 12:0071cb144c7a 161 : "memory", "eax", "ecx", "edx", "esi", "edi" );
JMF 12:0071cb144c7a 162
JMF 12:0071cb144c7a 163 memcpy( iv, iw, 16 );
JMF 12:0071cb144c7a 164
JMF 12:0071cb144c7a 165 return( 0 );
JMF 12:0071cb144c7a 166 }
JMF 12:0071cb144c7a 167
JMF 12:0071cb144c7a 168 #endif /* MBEDTLS_HAVE_X86 */
JMF 12:0071cb144c7a 169
JMF 12:0071cb144c7a 170 #endif /* MBEDTLS_PADLOCK_C */