mbed TLS library

Dependents:   HTTPClient-SSL WS_SERVER

Committer:
ansond
Date:
Thu Jun 11 03:27:03 2015 +0000
Revision:
0:137634ff4186
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:137634ff4186 1 /**
ansond 0:137634ff4186 2 * \file platform.h
ansond 0:137634ff4186 3 *
ansond 0:137634ff4186 4 * \brief mbed TLS Platform abstraction layer
ansond 0:137634ff4186 5 *
ansond 0:137634ff4186 6 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
ansond 0:137634ff4186 7 *
ansond 0:137634ff4186 8 * This file is part of mbed TLS (https://tls.mbed.org)
ansond 0:137634ff4186 9 *
ansond 0:137634ff4186 10 * This program is free software; you can redistribute it and/or modify
ansond 0:137634ff4186 11 * it under the terms of the GNU General Public License as published by
ansond 0:137634ff4186 12 * the Free Software Foundation; either version 2 of the License, or
ansond 0:137634ff4186 13 * (at your option) any later version.
ansond 0:137634ff4186 14 *
ansond 0:137634ff4186 15 * This program is distributed in the hope that it will be useful,
ansond 0:137634ff4186 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ansond 0:137634ff4186 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ansond 0:137634ff4186 18 * GNU General Public License for more details.
ansond 0:137634ff4186 19 *
ansond 0:137634ff4186 20 * You should have received a copy of the GNU General Public License along
ansond 0:137634ff4186 21 * with this program; if not, write to the Free Software Foundation, Inc.,
ansond 0:137634ff4186 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ansond 0:137634ff4186 23 */
ansond 0:137634ff4186 24 #ifndef POLARSSL_PLATFORM_H
ansond 0:137634ff4186 25 #define POLARSSL_PLATFORM_H
ansond 0:137634ff4186 26
ansond 0:137634ff4186 27 #if !defined(POLARSSL_CONFIG_FILE)
ansond 0:137634ff4186 28 #include "config.h"
ansond 0:137634ff4186 29 #else
ansond 0:137634ff4186 30 #include POLARSSL_CONFIG_FILE
ansond 0:137634ff4186 31 #endif
ansond 0:137634ff4186 32
ansond 0:137634ff4186 33 /* Temporary compatibility hack for to keep MEMORY_C working */
ansond 0:137634ff4186 34 #if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
ansond 0:137634ff4186 35 #define POLARSSL_PLATFORM_MEMORY
ansond 0:137634ff4186 36 #endif
ansond 0:137634ff4186 37
ansond 0:137634ff4186 38 #ifdef __cplusplus
ansond 0:137634ff4186 39 extern "C" {
ansond 0:137634ff4186 40 #endif
ansond 0:137634ff4186 41
ansond 0:137634ff4186 42 /**
ansond 0:137634ff4186 43 * \name SECTION: Module settings
ansond 0:137634ff4186 44 *
ansond 0:137634ff4186 45 * The configuration options you can set for this module are in this section.
ansond 0:137634ff4186 46 * Either change them in config.h or define them on the compiler command line.
ansond 0:137634ff4186 47 * \{
ansond 0:137634ff4186 48 */
ansond 0:137634ff4186 49
ansond 0:137634ff4186 50 #if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
ansond 0:137634ff4186 51 #include <stdio.h>
ansond 0:137634ff4186 52 #include <stdlib.h>
ansond 0:137634ff4186 53 #if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
ansond 0:137634ff4186 54 #define POLARSSL_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
ansond 0:137634ff4186 55 #endif
ansond 0:137634ff4186 56 #if !defined(POLARSSL_PLATFORM_STD_PRINTF)
ansond 0:137634ff4186 57 #define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
ansond 0:137634ff4186 58 #endif
ansond 0:137634ff4186 59 #if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
ansond 0:137634ff4186 60 #define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
ansond 0:137634ff4186 61 #endif
ansond 0:137634ff4186 62 #if !defined(POLARSSL_PLATFORM_STD_MALLOC)
ansond 0:137634ff4186 63 #define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
ansond 0:137634ff4186 64 #endif
ansond 0:137634ff4186 65 #if !defined(POLARSSL_PLATFORM_STD_FREE)
ansond 0:137634ff4186 66 #define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
ansond 0:137634ff4186 67 #endif
ansond 0:137634ff4186 68 #if !defined(POLARSSL_PLATFORM_STD_EXIT)
ansond 0:137634ff4186 69 #define POLARSSL_PLATFORM_STD_EXIT exit /**< Default free to use */
ansond 0:137634ff4186 70 #endif
ansond 0:137634ff4186 71 #else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
ansond 0:137634ff4186 72 #if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
ansond 0:137634ff4186 73 #include POLARSSL_PLATFORM_STD_MEM_HDR
ansond 0:137634ff4186 74 #endif
ansond 0:137634ff4186 75 #endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
ansond 0:137634ff4186 76
ansond 0:137634ff4186 77 /* \} name SECTION: Module settings */
ansond 0:137634ff4186 78
ansond 0:137634ff4186 79 /*
ansond 0:137634ff4186 80 * The function pointers for malloc and free
ansond 0:137634ff4186 81 */
ansond 0:137634ff4186 82 #if defined(POLARSSL_PLATFORM_MEMORY)
ansond 0:137634ff4186 83 #if defined(POLARSSL_PLATFORM_FREE_MACRO) && \
ansond 0:137634ff4186 84 defined(POLARSSL_PLATFORM_MALLOC_MACRO)
ansond 0:137634ff4186 85 #define polarssl_free POLARSSL_PLATFORM_FREE_MACRO
ansond 0:137634ff4186 86 #define polarssl_malloc POLARSSL_PLATFORM_MALLOC_MACRO
ansond 0:137634ff4186 87 #else
ansond 0:137634ff4186 88 /* For size_t */
ansond 0:137634ff4186 89 #include <stddef.h>
ansond 0:137634ff4186 90 extern void * (*polarssl_malloc)( size_t len );
ansond 0:137634ff4186 91 extern void (*polarssl_free)( void *ptr );
ansond 0:137634ff4186 92
ansond 0:137634ff4186 93 /**
ansond 0:137634ff4186 94 * \brief Set your own memory implementation function pointers
ansond 0:137634ff4186 95 *
ansond 0:137634ff4186 96 * \param malloc_func the malloc function implementation
ansond 0:137634ff4186 97 * \param free_func the free function implementation
ansond 0:137634ff4186 98 *
ansond 0:137634ff4186 99 * \return 0 if successful
ansond 0:137634ff4186 100 */
ansond 0:137634ff4186 101 int platform_set_malloc_free( void * (*malloc_func)( size_t ),
ansond 0:137634ff4186 102 void (*free_func)( void * ) );
ansond 0:137634ff4186 103 #endif /* POLARSSL_PLATFORM_FREE_MACRO && POLARSSL_PLATFORM_MALLOC_MACRO */
ansond 0:137634ff4186 104 #else /* !POLARSSL_PLATFORM_MEMORY */
ansond 0:137634ff4186 105 #define polarssl_free free
ansond 0:137634ff4186 106 #define polarssl_malloc malloc
ansond 0:137634ff4186 107 #endif /* POLARSSL_PLATFORM_MEMORY && !POLARSSL_PLATFORM_{FREE,MALLOC}_MACRO */
ansond 0:137634ff4186 108
ansond 0:137634ff4186 109 /*
ansond 0:137634ff4186 110 * The function pointers for fprintf
ansond 0:137634ff4186 111 */
ansond 0:137634ff4186 112 #if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
ansond 0:137634ff4186 113 /* We need FILE * */
ansond 0:137634ff4186 114 #include <stdio.h>
ansond 0:137634ff4186 115 extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
ansond 0:137634ff4186 116
ansond 0:137634ff4186 117 /**
ansond 0:137634ff4186 118 * \brief Set your own fprintf function pointer
ansond 0:137634ff4186 119 *
ansond 0:137634ff4186 120 * \param fprintf_func the fprintf function implementation
ansond 0:137634ff4186 121 *
ansond 0:137634ff4186 122 * \return 0
ansond 0:137634ff4186 123 */
ansond 0:137634ff4186 124 int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
ansond 0:137634ff4186 125 ... ) );
ansond 0:137634ff4186 126 #else
ansond 0:137634ff4186 127 #if defined(POLARSSL_PLATFORM_FPRINTF_MACRO)
ansond 0:137634ff4186 128 #define polarssl_fprintf POLARSSL_PLATFORM_FPRINTF_MACRO
ansond 0:137634ff4186 129 #else
ansond 0:137634ff4186 130 #define polarssl_fprintf fprintf
ansond 0:137634ff4186 131 #endif /* POLARSSL_PLATFORM_FPRINTF_MACRO */
ansond 0:137634ff4186 132 #endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
ansond 0:137634ff4186 133
ansond 0:137634ff4186 134 /*
ansond 0:137634ff4186 135 * The function pointers for printf
ansond 0:137634ff4186 136 */
ansond 0:137634ff4186 137 #if defined(POLARSSL_PLATFORM_PRINTF_ALT)
ansond 0:137634ff4186 138 extern int (*polarssl_printf)( const char *format, ... );
ansond 0:137634ff4186 139
ansond 0:137634ff4186 140 /**
ansond 0:137634ff4186 141 * \brief Set your own printf function pointer
ansond 0:137634ff4186 142 *
ansond 0:137634ff4186 143 * \param printf_func the printf function implementation
ansond 0:137634ff4186 144 *
ansond 0:137634ff4186 145 * \return 0
ansond 0:137634ff4186 146 */
ansond 0:137634ff4186 147 int platform_set_printf( int (*printf_func)( const char *, ... ) );
ansond 0:137634ff4186 148 #else /* !POLARSSL_PLATFORM_PRINTF_ALT */
ansond 0:137634ff4186 149 #if defined(POLARSSL_PLATFORM_PRINTF_MACRO)
ansond 0:137634ff4186 150 #define polarssl_printf POLARSSL_PLATFORM_PRINTF_MACRO
ansond 0:137634ff4186 151 #else
ansond 0:137634ff4186 152 #define polarssl_printf printf
ansond 0:137634ff4186 153 #endif /* POLARSSL_PLATFORM_PRINTF_MACRO */
ansond 0:137634ff4186 154 #endif /* POLARSSL_PLATFORM_PRINTF_ALT */
ansond 0:137634ff4186 155
ansond 0:137634ff4186 156 /*
ansond 0:137634ff4186 157 * The function pointers for snprintf
ansond 0:137634ff4186 158 */
ansond 0:137634ff4186 159 #if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
ansond 0:137634ff4186 160 extern int (*polarssl_snprintf)( char * s, size_t n, const char * format, ... );
ansond 0:137634ff4186 161
ansond 0:137634ff4186 162 /**
ansond 0:137634ff4186 163 * \brief Set your own snprintf function pointer
ansond 0:137634ff4186 164 *
ansond 0:137634ff4186 165 * \param snprintf_func the snprintf function implementation
ansond 0:137634ff4186 166 *
ansond 0:137634ff4186 167 * \return 0
ansond 0:137634ff4186 168 */
ansond 0:137634ff4186 169 int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
ansond 0:137634ff4186 170 const char * format, ... ) );
ansond 0:137634ff4186 171 #else /* POLARSSL_PLATFORM_SNPRINTF_ALT */
ansond 0:137634ff4186 172 #if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO)
ansond 0:137634ff4186 173 #define polarssl_snprintf POLARSSL_PLATFORM_SNPRINTF_MACRO
ansond 0:137634ff4186 174 #else
ansond 0:137634ff4186 175 #define polarssl_snprintf snprintf
ansond 0:137634ff4186 176 #endif /* POLARSSL_PLATFORM_SNPRINTF_MACRO */
ansond 0:137634ff4186 177 #endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
ansond 0:137634ff4186 178
ansond 0:137634ff4186 179 /*
ansond 0:137634ff4186 180 * The function pointers for exit
ansond 0:137634ff4186 181 */
ansond 0:137634ff4186 182 #if defined(POLARSSL_PLATFORM_EXIT_ALT)
ansond 0:137634ff4186 183 extern void (*polarssl_exit)( int status );
ansond 0:137634ff4186 184
ansond 0:137634ff4186 185 /**
ansond 0:137634ff4186 186 * \brief Set your own exit function pointer
ansond 0:137634ff4186 187 *
ansond 0:137634ff4186 188 * \param exit_func the exit function implementation
ansond 0:137634ff4186 189 *
ansond 0:137634ff4186 190 * \return 0
ansond 0:137634ff4186 191 */
ansond 0:137634ff4186 192 int platform_set_exit( void (*exit_func)( int status ) );
ansond 0:137634ff4186 193 #else
ansond 0:137634ff4186 194 #if defined(POLARSSL_PLATFORM_EXIT_MACRO)
ansond 0:137634ff4186 195 #define polarssl_exit POLARSSL_PLATFORM_EXIT_MACRO
ansond 0:137634ff4186 196 #else
ansond 0:137634ff4186 197 #define polarssl_exit exit
ansond 0:137634ff4186 198 #endif /* POLARSSL_PLATFORM_EXIT_MACRO */
ansond 0:137634ff4186 199 #endif /* POLARSSL_PLATFORM_EXIT_ALT */
ansond 0:137634ff4186 200
ansond 0:137634ff4186 201 #ifdef __cplusplus
ansond 0:137634ff4186 202 }
ansond 0:137634ff4186 203 #endif
ansond 0:137634ff4186 204
ansond 0:137634ff4186 205 #endif /* platform.h */
ansond 0:137634ff4186 206