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 * \file platform.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief mbed TLS Platform abstraction layer
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_PLATFORM_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_PLATFORM_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 27 #include "config.h"
mbedAustin 11:cada08fc8a70 28 #else
mbedAustin 11:cada08fc8a70 29 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 30 #endif
mbedAustin 11:cada08fc8a70 31
mbedAustin 11:cada08fc8a70 32 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 33 extern "C" {
mbedAustin 11:cada08fc8a70 34 #endif
mbedAustin 11:cada08fc8a70 35
mbedAustin 11:cada08fc8a70 36 /**
mbedAustin 11:cada08fc8a70 37 * \name SECTION: Module settings
mbedAustin 11:cada08fc8a70 38 *
mbedAustin 11:cada08fc8a70 39 * The configuration options you can set for this module are in this section.
mbedAustin 11:cada08fc8a70 40 * Either change them in config.h or define them on the compiler command line.
mbedAustin 11:cada08fc8a70 41 * \{
mbedAustin 11:cada08fc8a70 42 */
mbedAustin 11:cada08fc8a70 43
mbedAustin 11:cada08fc8a70 44 #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
mbedAustin 11:cada08fc8a70 45 #include <stdio.h>
mbedAustin 11:cada08fc8a70 46 #include <stdlib.h>
mbedAustin 11:cada08fc8a70 47 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
mbedAustin 11:cada08fc8a70 48 #if defined(_WIN32)
mbedAustin 11:cada08fc8a70 49 #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< Default snprintf to use */
mbedAustin 11:cada08fc8a70 50 #else
mbedAustin 11:cada08fc8a70 51 #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
mbedAustin 11:cada08fc8a70 52 #endif
mbedAustin 11:cada08fc8a70 53 #endif
mbedAustin 11:cada08fc8a70 54 #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
mbedAustin 11:cada08fc8a70 55 #define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use */
mbedAustin 11:cada08fc8a70 56 #endif
mbedAustin 11:cada08fc8a70 57 #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
mbedAustin 11:cada08fc8a70 58 #define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
mbedAustin 11:cada08fc8a70 59 #endif
mbedAustin 11:cada08fc8a70 60 #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
mbedAustin 11:cada08fc8a70 61 #define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use */
mbedAustin 11:cada08fc8a70 62 #endif
mbedAustin 11:cada08fc8a70 63 #if !defined(MBEDTLS_PLATFORM_STD_FREE)
mbedAustin 11:cada08fc8a70 64 #define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use */
mbedAustin 11:cada08fc8a70 65 #endif
mbedAustin 11:cada08fc8a70 66 #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
mbedAustin 11:cada08fc8a70 67 #define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default free to use */
mbedAustin 11:cada08fc8a70 68 #endif
mbedAustin 11:cada08fc8a70 69 #else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
mbedAustin 11:cada08fc8a70 70 #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
mbedAustin 11:cada08fc8a70 71 #include MBEDTLS_PLATFORM_STD_MEM_HDR
mbedAustin 11:cada08fc8a70 72 #endif
mbedAustin 11:cada08fc8a70 73 #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
mbedAustin 11:cada08fc8a70 74
mbedAustin 11:cada08fc8a70 75 /* \} name SECTION: Module settings */
mbedAustin 11:cada08fc8a70 76
mbedAustin 11:cada08fc8a70 77 /*
mbedAustin 11:cada08fc8a70 78 * The function pointers for calloc and free
mbedAustin 11:cada08fc8a70 79 */
mbedAustin 11:cada08fc8a70 80 #if defined(MBEDTLS_PLATFORM_MEMORY)
mbedAustin 11:cada08fc8a70 81 #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
mbedAustin 11:cada08fc8a70 82 defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
mbedAustin 11:cada08fc8a70 83 #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
mbedAustin 11:cada08fc8a70 84 #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
mbedAustin 11:cada08fc8a70 85 #else
mbedAustin 11:cada08fc8a70 86 /* For size_t */
mbedAustin 11:cada08fc8a70 87 #include <stddef.h>
mbedAustin 11:cada08fc8a70 88 extern void * (*mbedtls_calloc)( size_t n, size_t size );
mbedAustin 11:cada08fc8a70 89 extern void (*mbedtls_free)( void *ptr );
mbedAustin 11:cada08fc8a70 90
mbedAustin 11:cada08fc8a70 91 /**
mbedAustin 11:cada08fc8a70 92 * \brief Set your own memory implementation function pointers
mbedAustin 11:cada08fc8a70 93 *
mbedAustin 11:cada08fc8a70 94 * \param calloc_func the calloc function implementation
mbedAustin 11:cada08fc8a70 95 * \param free_func the free function implementation
mbedAustin 11:cada08fc8a70 96 *
mbedAustin 11:cada08fc8a70 97 * \return 0 if successful
mbedAustin 11:cada08fc8a70 98 */
mbedAustin 11:cada08fc8a70 99 int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
mbedAustin 11:cada08fc8a70 100 void (*free_func)( void * ) );
mbedAustin 11:cada08fc8a70 101 #endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
mbedAustin 11:cada08fc8a70 102 #else /* !MBEDTLS_PLATFORM_MEMORY */
mbedAustin 11:cada08fc8a70 103 #define mbedtls_free free
mbedAustin 11:cada08fc8a70 104 #define mbedtls_calloc calloc
mbedAustin 11:cada08fc8a70 105 #endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
mbedAustin 11:cada08fc8a70 106
mbedAustin 11:cada08fc8a70 107 /*
mbedAustin 11:cada08fc8a70 108 * The function pointers for fprintf
mbedAustin 11:cada08fc8a70 109 */
mbedAustin 11:cada08fc8a70 110 #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
mbedAustin 11:cada08fc8a70 111 /* We need FILE * */
mbedAustin 11:cada08fc8a70 112 #include <stdio.h>
mbedAustin 11:cada08fc8a70 113 extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
mbedAustin 11:cada08fc8a70 114
mbedAustin 11:cada08fc8a70 115 /**
mbedAustin 11:cada08fc8a70 116 * \brief Set your own fprintf function pointer
mbedAustin 11:cada08fc8a70 117 *
mbedAustin 11:cada08fc8a70 118 * \param fprintf_func the fprintf function implementation
mbedAustin 11:cada08fc8a70 119 *
mbedAustin 11:cada08fc8a70 120 * \return 0
mbedAustin 11:cada08fc8a70 121 */
mbedAustin 11:cada08fc8a70 122 int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
mbedAustin 11:cada08fc8a70 123 ... ) );
mbedAustin 11:cada08fc8a70 124 #else
mbedAustin 11:cada08fc8a70 125 #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
mbedAustin 11:cada08fc8a70 126 #define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
mbedAustin 11:cada08fc8a70 127 #else
mbedAustin 11:cada08fc8a70 128 #define mbedtls_fprintf fprintf
mbedAustin 11:cada08fc8a70 129 #endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
mbedAustin 11:cada08fc8a70 130 #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
mbedAustin 11:cada08fc8a70 131
mbedAustin 11:cada08fc8a70 132 /*
mbedAustin 11:cada08fc8a70 133 * The function pointers for printf
mbedAustin 11:cada08fc8a70 134 */
mbedAustin 11:cada08fc8a70 135 #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
mbedAustin 11:cada08fc8a70 136 extern int (*mbedtls_printf)( const char *format, ... );
mbedAustin 11:cada08fc8a70 137
mbedAustin 11:cada08fc8a70 138 /**
mbedAustin 11:cada08fc8a70 139 * \brief Set your own printf function pointer
mbedAustin 11:cada08fc8a70 140 *
mbedAustin 11:cada08fc8a70 141 * \param printf_func the printf function implementation
mbedAustin 11:cada08fc8a70 142 *
mbedAustin 11:cada08fc8a70 143 * \return 0
mbedAustin 11:cada08fc8a70 144 */
mbedAustin 11:cada08fc8a70 145 int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
mbedAustin 11:cada08fc8a70 146 #else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
mbedAustin 11:cada08fc8a70 147 #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
mbedAustin 11:cada08fc8a70 148 #define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
mbedAustin 11:cada08fc8a70 149 #else
mbedAustin 11:cada08fc8a70 150 #define mbedtls_printf printf
mbedAustin 11:cada08fc8a70 151 #endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
mbedAustin 11:cada08fc8a70 152 #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
mbedAustin 11:cada08fc8a70 153
mbedAustin 11:cada08fc8a70 154 /*
mbedAustin 11:cada08fc8a70 155 * The function pointers for snprintf
mbedAustin 11:cada08fc8a70 156 *
mbedAustin 11:cada08fc8a70 157 * The snprintf implementation should conform to C99:
mbedAustin 11:cada08fc8a70 158 * - it *must* always correctly zero-terminate the buffer
mbedAustin 11:cada08fc8a70 159 * (except when n == 0, then it must leave the buffer untouched)
mbedAustin 11:cada08fc8a70 160 * - however it is acceptable to return -1 instead of the required length when
mbedAustin 11:cada08fc8a70 161 * the destination buffer is too short.
mbedAustin 11:cada08fc8a70 162 */
mbedAustin 11:cada08fc8a70 163 #if defined(_WIN32)
mbedAustin 11:cada08fc8a70 164 /* For Windows (inc. MSYS2), we provide our own fixed implementation */
mbedAustin 11:cada08fc8a70 165 int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
mbedAustin 11:cada08fc8a70 166 #endif
mbedAustin 11:cada08fc8a70 167
mbedAustin 11:cada08fc8a70 168 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
mbedAustin 11:cada08fc8a70 169 extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
mbedAustin 11:cada08fc8a70 170
mbedAustin 11:cada08fc8a70 171 /**
mbedAustin 11:cada08fc8a70 172 * \brief Set your own snprintf function pointer
mbedAustin 11:cada08fc8a70 173 *
mbedAustin 11:cada08fc8a70 174 * \param snprintf_func the snprintf function implementation
mbedAustin 11:cada08fc8a70 175 *
mbedAustin 11:cada08fc8a70 176 * \return 0
mbedAustin 11:cada08fc8a70 177 */
mbedAustin 11:cada08fc8a70 178 int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
mbedAustin 11:cada08fc8a70 179 const char * format, ... ) );
mbedAustin 11:cada08fc8a70 180 #else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
mbedAustin 11:cada08fc8a70 181 #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
mbedAustin 11:cada08fc8a70 182 #define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
mbedAustin 11:cada08fc8a70 183 #else
mbedAustin 11:cada08fc8a70 184 #define mbedtls_snprintf snprintf
mbedAustin 11:cada08fc8a70 185 #endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
mbedAustin 11:cada08fc8a70 186 #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
mbedAustin 11:cada08fc8a70 187
mbedAustin 11:cada08fc8a70 188 /*
mbedAustin 11:cada08fc8a70 189 * The function pointers for exit
mbedAustin 11:cada08fc8a70 190 */
mbedAustin 11:cada08fc8a70 191 #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
mbedAustin 11:cada08fc8a70 192 extern void (*mbedtls_exit)( int status );
mbedAustin 11:cada08fc8a70 193
mbedAustin 11:cada08fc8a70 194 /**
mbedAustin 11:cada08fc8a70 195 * \brief Set your own exit function pointer
mbedAustin 11:cada08fc8a70 196 *
mbedAustin 11:cada08fc8a70 197 * \param exit_func the exit function implementation
mbedAustin 11:cada08fc8a70 198 *
mbedAustin 11:cada08fc8a70 199 * \return 0
mbedAustin 11:cada08fc8a70 200 */
mbedAustin 11:cada08fc8a70 201 int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
mbedAustin 11:cada08fc8a70 202 #else
mbedAustin 11:cada08fc8a70 203 #if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
mbedAustin 11:cada08fc8a70 204 #define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
mbedAustin 11:cada08fc8a70 205 #else
mbedAustin 11:cada08fc8a70 206 #define mbedtls_exit exit
mbedAustin 11:cada08fc8a70 207 #endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
mbedAustin 11:cada08fc8a70 208 #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
mbedAustin 11:cada08fc8a70 209
mbedAustin 11:cada08fc8a70 210 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 211 }
mbedAustin 11:cada08fc8a70 212 #endif
mbedAustin 11:cada08fc8a70 213
mbedAustin 11:cada08fc8a70 214 #endif /* platform.h */