Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: WncControllerK64F
Fork of WNCInterface by
platform.h
00001 /** 00002 * \file platform.h 00003 * 00004 * \brief mbed TLS Platform abstraction layer 00005 * 00006 * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 * 00021 * This file is part of mbed TLS (https://tls.mbed.org) 00022 */ 00023 #ifndef MBEDTLS_PLATFORM_H 00024 #define MBEDTLS_PLATFORM_H 00025 00026 #if !defined(MBEDTLS_CONFIG_FILE) 00027 #include "config.h" 00028 #else 00029 #include MBEDTLS_CONFIG_FILE 00030 #endif 00031 00032 #if defined(MBEDTLS_HAVE_TIME) 00033 #include "mbedtls/platform_time.h" 00034 #endif 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 int myprintf(const char *f, ...); 00041 00042 /** 00043 * \name SECTION: Module settings 00044 * 00045 * The configuration options you can set for this module are in this section. 00046 * Either change them in config.h or define them on the compiler command line. 00047 * \{ 00048 */ 00049 00050 #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) 00051 #include <stdio.h> 00052 #include <stdlib.h> 00053 #include <time.h> 00054 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF) 00055 #if defined(_WIN32) 00056 #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< Default snprintf to use */ 00057 #else 00058 #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */ 00059 #endif 00060 #endif 00061 #if !defined(MBEDTLS_PLATFORM_STD_PRINTF) 00062 #define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use */ 00063 #endif 00064 #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF) 00065 #define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */ 00066 #endif 00067 #if !defined(MBEDTLS_PLATFORM_STD_CALLOC) 00068 #define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use */ 00069 #endif 00070 #if !defined(MBEDTLS_PLATFORM_STD_FREE) 00071 #define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use */ 00072 #endif 00073 #if !defined(MBEDTLS_PLATFORM_STD_EXIT) 00074 #define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use */ 00075 #endif 00076 #if !defined(MBEDTLS_PLATFORM_STD_TIME) 00077 #define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use */ 00078 #endif 00079 #if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS) 00080 #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< Default exit value to use */ 00081 #endif 00082 #if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE) 00083 #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< Default exit value to use */ 00084 #endif 00085 #if defined(MBEDTLS_FS_IO) 00086 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) 00087 #define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read 00088 #endif 00089 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) 00090 #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write 00091 #endif 00092 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE) 00093 #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" 00094 #endif 00095 #endif /* MBEDTLS_FS_IO */ 00096 #else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */ 00097 #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) 00098 #include MBEDTLS_PLATFORM_STD_MEM_HDR 00099 #endif 00100 #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */ 00101 00102 00103 /* \} name SECTION: Module settings */ 00104 00105 /* 00106 * The function pointers for calloc and free 00107 */ 00108 #if defined(MBEDTLS_PLATFORM_MEMORY) 00109 #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \ 00110 defined(MBEDTLS_PLATFORM_CALLOC_MACRO) 00111 #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO 00112 #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO 00113 #else 00114 /* For size_t */ 00115 #include <stddef.h> 00116 extern void * (*mbedtls_calloc)( size_t n, size_t size ); 00117 extern void (*mbedtls_free)( void *ptr ); 00118 00119 /** 00120 * \brief Set your own memory implementation function pointers 00121 * 00122 * \param calloc_func the calloc function implementation 00123 * \param free_func the free function implementation 00124 * 00125 * \return 0 if successful 00126 */ 00127 int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ), 00128 void (*free_func)( void * ) ); 00129 #endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */ 00130 #else /* !MBEDTLS_PLATFORM_MEMORY */ 00131 #define mbedtls_free free 00132 #define mbedtls_calloc calloc 00133 #endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */ 00134 00135 /* 00136 * The function pointers for fprintf 00137 */ 00138 #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) 00139 /* We need FILE * */ 00140 #include <stdio.h> 00141 extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... ); 00142 00143 /** 00144 * \brief Set your own fprintf function pointer 00145 * 00146 * \param fprintf_func the fprintf function implementation 00147 * 00148 * \return 0 00149 */ 00150 int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *, 00151 ... ) ); 00152 #else 00153 #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) 00154 #define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO 00155 #else 00156 #define mbedtls_fprintf fprintf 00157 #endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */ 00158 #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */ 00159 00160 /* 00161 * The function pointers for printf 00162 */ 00163 #if defined(MBEDTLS_PLATFORM_PRINTF_ALT) 00164 extern int (*mbedtls_printf)( const char *format, ... ); 00165 00166 /** 00167 * \brief Set your own printf function pointer 00168 * 00169 * \param printf_func the printf function implementation 00170 * 00171 * \return 0 00172 */ 00173 int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) ); 00174 #else /* !MBEDTLS_PLATFORM_PRINTF_ALT */ 00175 #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) 00176 #define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO 00177 #else 00178 #define mbedtls_printf printf 00179 #endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */ 00180 #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */ 00181 00182 /* 00183 * The function pointers for snprintf 00184 * 00185 * The snprintf implementation should conform to C99: 00186 * - it *must* always correctly zero-terminate the buffer 00187 * (except when n == 0, then it must leave the buffer untouched) 00188 * - however it is acceptable to return -1 instead of the required length when 00189 * the destination buffer is too short. 00190 */ 00191 #if defined(_WIN32) 00192 /* For Windows (inc. MSYS2), we provide our own fixed implementation */ 00193 int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... ); 00194 #endif 00195 00196 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) 00197 extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... ); 00198 00199 /** 00200 * \brief Set your own snprintf function pointer 00201 * 00202 * \param snprintf_func the snprintf function implementation 00203 * 00204 * \return 0 00205 */ 00206 int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n, 00207 const char * format, ... ) ); 00208 #else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */ 00209 #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) 00210 #define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO 00211 #else 00212 #define mbedtls_snprintf snprintf 00213 #endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */ 00214 #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */ 00215 00216 /* 00217 * The function pointers for exit 00218 */ 00219 #if defined(MBEDTLS_PLATFORM_EXIT_ALT) 00220 extern void (*mbedtls_exit)( int status ); 00221 00222 /** 00223 * \brief Set your own exit function pointer 00224 * 00225 * \param exit_func the exit function implementation 00226 * 00227 * \return 0 00228 */ 00229 int mbedtls_platform_set_exit( void (*exit_func)( int status ) ); 00230 #else 00231 #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) 00232 #define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO 00233 #else 00234 #define mbedtls_exit exit 00235 #endif /* MBEDTLS_PLATFORM_EXIT_MACRO */ 00236 #endif /* MBEDTLS_PLATFORM_EXIT_ALT */ 00237 00238 /* 00239 * The default exit values 00240 */ 00241 #if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS) 00242 #define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 00243 #else 00244 #define MBEDTLS_EXIT_SUCCESS 0 00245 #endif 00246 #if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE) 00247 #define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE 00248 #else 00249 #define MBEDTLS_EXIT_FAILURE 1 00250 #endif 00251 00252 /* 00253 * The function pointers for reading from and writing a seed file to 00254 * Non-Volatile storage (NV) in a platform-independent way 00255 * 00256 * Only enabled when the NV seed entropy source is enabled 00257 */ 00258 #if defined(MBEDTLS_ENTROPY_NV_SEED) 00259 #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO) 00260 /* Internal standard platform definitions */ 00261 int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len ); 00262 int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len ); 00263 #endif 00264 00265 #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) 00266 extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ); 00267 extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ); 00268 00269 /** 00270 * \brief Set your own seed file writing/reading functions 00271 * 00272 * \param nv_seed_read_func the seed reading function implementation 00273 * \param nv_seed_write_func the seed writing function implementation 00274 * 00275 * \return 0 00276 */ 00277 int mbedtls_platform_set_nv_seed( 00278 int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ), 00279 int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len ) 00280 ); 00281 #else 00282 #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \ 00283 defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) 00284 #define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO 00285 #define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO 00286 #else 00287 #define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read 00288 #define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write 00289 #endif 00290 #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */ 00291 #endif /* MBEDTLS_ENTROPY_NV_SEED */ 00292 00293 #ifdef __cplusplus 00294 } 00295 #endif 00296 00297 #endif /* platform.h */
Generated on Tue Jul 12 2022 20:52:40 by
