mbed client on ethernet with LWIP

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by sandbox

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /*
mbedAustin 11:cada08fc8a70 2 * Platform abstraction layer
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 5 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 6 *
mbedAustin 11:cada08fc8a70 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 8 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 9 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 10 *
mbedAustin 11:cada08fc8a70 11 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 16 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 17 * limitations under the License.
mbedAustin 11:cada08fc8a70 18 *
mbedAustin 11:cada08fc8a70 19 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 20 */
mbedAustin 11:cada08fc8a70 21
mbedAustin 11:cada08fc8a70 22 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 23 #include "mbedtls/config.h"
mbedAustin 11:cada08fc8a70 24 #else
mbedAustin 11:cada08fc8a70 25 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 26 #endif
mbedAustin 11:cada08fc8a70 27
mbedAustin 11:cada08fc8a70 28 #if defined(MBEDTLS_PLATFORM_C)
mbedAustin 11:cada08fc8a70 29
mbedAustin 11:cada08fc8a70 30 #include "mbedtls/platform.h"
mbedAustin 11:cada08fc8a70 31
mbedAustin 11:cada08fc8a70 32 #if defined(MBEDTLS_PLATFORM_MEMORY)
mbedAustin 11:cada08fc8a70 33 #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
mbedAustin 11:cada08fc8a70 34 static void *platform_calloc_uninit( size_t n, size_t size )
mbedAustin 11:cada08fc8a70 35 {
mbedAustin 11:cada08fc8a70 36 ((void) n);
mbedAustin 11:cada08fc8a70 37 ((void) size);
mbedAustin 11:cada08fc8a70 38 return( NULL );
mbedAustin 11:cada08fc8a70 39 }
mbedAustin 11:cada08fc8a70 40
mbedAustin 11:cada08fc8a70 41 #define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
mbedAustin 11:cada08fc8a70 42 #endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
mbedAustin 11:cada08fc8a70 43
mbedAustin 11:cada08fc8a70 44 #if !defined(MBEDTLS_PLATFORM_STD_FREE)
mbedAustin 11:cada08fc8a70 45 static void platform_free_uninit( void *ptr )
mbedAustin 11:cada08fc8a70 46 {
mbedAustin 11:cada08fc8a70 47 ((void) ptr);
mbedAustin 11:cada08fc8a70 48 }
mbedAustin 11:cada08fc8a70 49
mbedAustin 11:cada08fc8a70 50 #define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
mbedAustin 11:cada08fc8a70 51 #endif /* !MBEDTLS_PLATFORM_STD_FREE */
mbedAustin 11:cada08fc8a70 52
mbedAustin 11:cada08fc8a70 53 void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
mbedAustin 11:cada08fc8a70 54 void (*mbedtls_free)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
mbedAustin 11:cada08fc8a70 55
mbedAustin 11:cada08fc8a70 56 int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
mbedAustin 11:cada08fc8a70 57 void (*free_func)( void * ) )
mbedAustin 11:cada08fc8a70 58 {
mbedAustin 11:cada08fc8a70 59 mbedtls_calloc = calloc_func;
mbedAustin 11:cada08fc8a70 60 mbedtls_free = free_func;
mbedAustin 11:cada08fc8a70 61 return( 0 );
mbedAustin 11:cada08fc8a70 62 }
mbedAustin 11:cada08fc8a70 63 #endif /* MBEDTLS_PLATFORM_MEMORY */
mbedAustin 11:cada08fc8a70 64
mbedAustin 11:cada08fc8a70 65 #if defined(_WIN32)
mbedAustin 11:cada08fc8a70 66 #include <stdarg.h>
mbedAustin 11:cada08fc8a70 67 int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
mbedAustin 11:cada08fc8a70 68 {
mbedAustin 11:cada08fc8a70 69 int ret;
mbedAustin 11:cada08fc8a70 70 va_list argp;
mbedAustin 11:cada08fc8a70 71
mbedAustin 11:cada08fc8a70 72 /* Avoid calling the invalid parameter handler by checking ourselves */
mbedAustin 11:cada08fc8a70 73 if( s == NULL || n == 0 || fmt == NULL )
mbedAustin 11:cada08fc8a70 74 return( -1 );
mbedAustin 11:cada08fc8a70 75
mbedAustin 11:cada08fc8a70 76 va_start( argp, fmt );
mbedAustin 11:cada08fc8a70 77 #if defined(_TRUNCATE)
mbedAustin 11:cada08fc8a70 78 ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
mbedAustin 11:cada08fc8a70 79 #else
mbedAustin 11:cada08fc8a70 80 ret = _vsnprintf( s, n, fmt, argp );
mbedAustin 11:cada08fc8a70 81 if( ret < 0 || (size_t) ret == n )
mbedAustin 11:cada08fc8a70 82 {
mbedAustin 11:cada08fc8a70 83 s[n-1] = '\0';
mbedAustin 11:cada08fc8a70 84 ret = -1;
mbedAustin 11:cada08fc8a70 85 }
mbedAustin 11:cada08fc8a70 86 #endif
mbedAustin 11:cada08fc8a70 87 va_end( argp );
mbedAustin 11:cada08fc8a70 88
mbedAustin 11:cada08fc8a70 89 return( ret );
mbedAustin 11:cada08fc8a70 90 }
mbedAustin 11:cada08fc8a70 91 #endif
mbedAustin 11:cada08fc8a70 92
mbedAustin 11:cada08fc8a70 93 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
mbedAustin 11:cada08fc8a70 94 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
mbedAustin 11:cada08fc8a70 95 /*
mbedAustin 11:cada08fc8a70 96 * Make dummy function to prevent NULL pointer dereferences
mbedAustin 11:cada08fc8a70 97 */
mbedAustin 11:cada08fc8a70 98 static int platform_snprintf_uninit( char * s, size_t n,
mbedAustin 11:cada08fc8a70 99 const char * format, ... )
mbedAustin 11:cada08fc8a70 100 {
mbedAustin 11:cada08fc8a70 101 ((void) s);
mbedAustin 11:cada08fc8a70 102 ((void) n);
mbedAustin 11:cada08fc8a70 103 ((void) format);
mbedAustin 11:cada08fc8a70 104 return( 0 );
mbedAustin 11:cada08fc8a70 105 }
mbedAustin 11:cada08fc8a70 106
mbedAustin 11:cada08fc8a70 107 #define MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
mbedAustin 11:cada08fc8a70 108 #endif /* !MBEDTLS_PLATFORM_STD_SNPRINTF */
mbedAustin 11:cada08fc8a70 109
mbedAustin 11:cada08fc8a70 110 int (*mbedtls_snprintf)( char * s, size_t n,
mbedAustin 11:cada08fc8a70 111 const char * format,
mbedAustin 11:cada08fc8a70 112 ... ) = MBEDTLS_PLATFORM_STD_SNPRINTF;
mbedAustin 11:cada08fc8a70 113
mbedAustin 11:cada08fc8a70 114 int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
mbedAustin 11:cada08fc8a70 115 const char * format,
mbedAustin 11:cada08fc8a70 116 ... ) )
mbedAustin 11:cada08fc8a70 117 {
mbedAustin 11:cada08fc8a70 118 mbedtls_snprintf = snprintf_func;
mbedAustin 11:cada08fc8a70 119 return( 0 );
mbedAustin 11:cada08fc8a70 120 }
mbedAustin 11:cada08fc8a70 121 #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
mbedAustin 11:cada08fc8a70 122
mbedAustin 11:cada08fc8a70 123 #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
mbedAustin 11:cada08fc8a70 124 #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
mbedAustin 11:cada08fc8a70 125 /*
mbedAustin 11:cada08fc8a70 126 * Make dummy function to prevent NULL pointer dereferences
mbedAustin 11:cada08fc8a70 127 */
mbedAustin 11:cada08fc8a70 128 static int platform_printf_uninit( const char *format, ... )
mbedAustin 11:cada08fc8a70 129 {
mbedAustin 11:cada08fc8a70 130 ((void) format);
mbedAustin 11:cada08fc8a70 131 return( 0 );
mbedAustin 11:cada08fc8a70 132 }
mbedAustin 11:cada08fc8a70 133
mbedAustin 11:cada08fc8a70 134 #define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit
mbedAustin 11:cada08fc8a70 135 #endif /* !MBEDTLS_PLATFORM_STD_PRINTF */
mbedAustin 11:cada08fc8a70 136
mbedAustin 11:cada08fc8a70 137 int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF;
mbedAustin 11:cada08fc8a70 138
mbedAustin 11:cada08fc8a70 139 int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) )
mbedAustin 11:cada08fc8a70 140 {
mbedAustin 11:cada08fc8a70 141 mbedtls_printf = printf_func;
mbedAustin 11:cada08fc8a70 142 return( 0 );
mbedAustin 11:cada08fc8a70 143 }
mbedAustin 11:cada08fc8a70 144 #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
mbedAustin 11:cada08fc8a70 145
mbedAustin 11:cada08fc8a70 146 #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
mbedAustin 11:cada08fc8a70 147 #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
mbedAustin 11:cada08fc8a70 148 /*
mbedAustin 11:cada08fc8a70 149 * Make dummy function to prevent NULL pointer dereferences
mbedAustin 11:cada08fc8a70 150 */
mbedAustin 11:cada08fc8a70 151 static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
mbedAustin 11:cada08fc8a70 152 {
mbedAustin 11:cada08fc8a70 153 ((void) stream);
mbedAustin 11:cada08fc8a70 154 ((void) format);
mbedAustin 11:cada08fc8a70 155 return( 0 );
mbedAustin 11:cada08fc8a70 156 }
mbedAustin 11:cada08fc8a70 157
mbedAustin 11:cada08fc8a70 158 #define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit
mbedAustin 11:cada08fc8a70 159 #endif /* !MBEDTLS_PLATFORM_STD_FPRINTF */
mbedAustin 11:cada08fc8a70 160
mbedAustin 11:cada08fc8a70 161 int (*mbedtls_fprintf)( FILE *, const char *, ... ) =
mbedAustin 11:cada08fc8a70 162 MBEDTLS_PLATFORM_STD_FPRINTF;
mbedAustin 11:cada08fc8a70 163
mbedAustin 11:cada08fc8a70 164 int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
mbedAustin 11:cada08fc8a70 165 {
mbedAustin 11:cada08fc8a70 166 mbedtls_fprintf = fprintf_func;
mbedAustin 11:cada08fc8a70 167 return( 0 );
mbedAustin 11:cada08fc8a70 168 }
mbedAustin 11:cada08fc8a70 169 #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
mbedAustin 11:cada08fc8a70 170
mbedAustin 11:cada08fc8a70 171 #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
mbedAustin 11:cada08fc8a70 172 #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
mbedAustin 11:cada08fc8a70 173 /*
mbedAustin 11:cada08fc8a70 174 * Make dummy function to prevent NULL pointer dereferences
mbedAustin 11:cada08fc8a70 175 */
mbedAustin 11:cada08fc8a70 176 static void platform_exit_uninit( int status )
mbedAustin 11:cada08fc8a70 177 {
mbedAustin 11:cada08fc8a70 178 ((void) status);
mbedAustin 11:cada08fc8a70 179 }
mbedAustin 11:cada08fc8a70 180
mbedAustin 11:cada08fc8a70 181 #define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit
mbedAustin 11:cada08fc8a70 182 #endif /* !MBEDTLS_PLATFORM_STD_EXIT */
mbedAustin 11:cada08fc8a70 183
mbedAustin 11:cada08fc8a70 184 void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT;
mbedAustin 11:cada08fc8a70 185
mbedAustin 11:cada08fc8a70 186 int mbedtls_platform_set_exit( void (*exit_func)( int status ) )
mbedAustin 11:cada08fc8a70 187 {
mbedAustin 11:cada08fc8a70 188 mbedtls_exit = exit_func;
mbedAustin 11:cada08fc8a70 189 return( 0 );
mbedAustin 11:cada08fc8a70 190 }
mbedAustin 11:cada08fc8a70 191 #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
mbedAustin 11:cada08fc8a70 192
mbedAustin 11:cada08fc8a70 193 #endif /* MBEDTLS_PLATFORM_C */