source: UsbWattMeter/trunk/wolfssl-3.7.0/wolfssl/wolfcrypt/wc_port.h@ 165

Last change on this file since 165 was 164, checked in by coas-nagasima, 8 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr
File size: 8.5 KB
Line 
1/* wc_port.h
2 *
3 * Copyright (C) 2006-2015 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL. (formerly known as CyaSSL)
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22
23#ifndef WOLF_CRYPT_PORT_H
24#define WOLF_CRYPT_PORT_H
25
26#include <wolfssl/wolfcrypt/types.h>
27
28#ifdef __cplusplus
29 extern "C" {
30#endif
31
32
33#ifdef USE_WINDOWS_API
34 #ifdef WOLFSSL_GAME_BUILD
35 #include "system/xtl.h"
36 #else
37 #ifndef WIN32_LEAN_AND_MEAN
38 #define WIN32_LEAN_AND_MEAN
39 #endif
40 #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
41 /* On WinCE winsock2.h must be included before windows.h */
42 #include <winsock2.h>
43 #endif
44 #include <windows.h>
45 #endif
46#elif defined(THREADX)
47 #ifndef SINGLE_THREADED
48 #include "tx_api.h"
49 #endif
50#elif defined(MICRIUM)
51 /* do nothing, just don't pick Unix */
52#elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS)
53 /* do nothing */
54#elif defined(EBSNET)
55 /* do nothing */
56#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
57 /* do nothing */
58#elif defined(FREESCALE_FREE_RTOS)
59 #include "fsl_os_abstraction.h"
60#elif defined(WOLFSSL_LWIP)
61 #include "lwip/sys.h"
62#elif defined(WOLFSSL_uITRON4)
63 #include "kernel.h"
64#elif defined(WOLFSSL_uTKERNEL2)
65 #include "tk/tkernel.h"
66#elif defined(WOLFSSL_MDK_ARM)
67 #if defined(WOLFSSL_MDK5)
68 #include "cmsis_os.h"
69 #else
70 #include <rtl.h>
71 #endif
72#elif defined(WOLFSSL_CMSIS_RTOS)
73 #include "cmsis_os.h"
74#elif defined(WOLFSSL_TIRTOS)
75 #include <ti/sysbios/BIOS.h>
76 #include <ti/sysbios/knl/Semaphore.h>
77#else
78 #ifndef SINGLE_THREADED
79 #define WOLFSSL_PTHREADS
80 #include <pthread.h>
81 #endif
82 #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
83 #include <unistd.h> /* for close of BIO */
84 #endif
85#endif
86
87
88#ifdef SINGLE_THREADED
89 typedef int wolfSSL_Mutex;
90#else /* MULTI_THREADED */
91 /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */
92 #if defined(FREERTOS)
93 typedef xSemaphoreHandle wolfSSL_Mutex;
94 #elif defined(FREERTOS_TCP)
95 #include "FreeRTOS.h"
96 #include "semphr.h"
97 typedef SemaphoreHandle_t wolfSSL_Mutex;
98 #elif defined(WOLFSSL_SAFERTOS)
99 typedef struct wolfSSL_Mutex {
100 signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
101 xSemaphoreHandle mutex;
102 } wolfSSL_Mutex;
103 #elif defined(USE_WINDOWS_API)
104 typedef CRITICAL_SECTION wolfSSL_Mutex;
105 #elif defined(WOLFSSL_PTHREADS)
106 typedef pthread_mutex_t wolfSSL_Mutex;
107 #elif defined(THREADX)
108 typedef TX_MUTEX wolfSSL_Mutex;
109 #elif defined(MICRIUM)
110 typedef OS_MUTEX wolfSSL_Mutex;
111 #elif defined(EBSNET)
112 typedef RTP_MUTEX wolfSSL_Mutex;
113 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
114 typedef MUTEX_STRUCT wolfSSL_Mutex;
115 #elif defined(FREESCALE_FREE_RTOS)
116 typedef mutex_t wolfSSL_Mutex;
117 #elif defined(WOLFSSL_LWIP)
118 typedef sys_mutex_t wolfSSL_Mutex;
119 #elif defined(WOLFSSL_uITRON4)
120 typedef struct wolfSSL_Mutex {
121 T_CSEM sem ;
122 ID id ;
123 } wolfSSL_Mutex;
124 #elif defined(WOLFSSL_uTKERNEL2)
125 typedef struct wolfSSL_Mutex {
126 T_CSEM sem ;
127 ID id ;
128 } wolfSSL_Mutex;
129 #elif defined(WOLFSSL_MDK_ARM)
130 #if defined(WOLFSSL_CMSIS_RTOS)
131 typedef osMutexId wolfSSL_Mutex;
132 #else
133 typedef OS_MUT wolfSSL_Mutex;
134 #endif
135 #elif defined(WOLFSSL_CMSIS_RTOS)
136 typedef osMutexId wolfSSL_Mutex;
137 #elif defined(WOLFSSL_TIRTOS)
138 typedef ti_sysbios_knl_Semaphore_Handle wolfSSL_Mutex;
139 #else
140 #error Need a mutex type in multithreaded mode
141 #endif /* USE_WINDOWS_API */
142#endif /* SINGLE_THREADED */
143
144/* Enable crypt HW mutex for Freescale MMCAU */
145#if defined(FREESCALE_MMCAU)
146 #ifndef WOLFSSL_CRYPT_HW_MUTEX
147 #define WOLFSSL_CRYPT_HW_MUTEX 1
148 #endif
149#endif /* FREESCALE_MMCAU */
150
151#ifndef WOLFSSL_CRYPT_HW_MUTEX
152 #define WOLFSSL_CRYPT_HW_MUTEX 0
153#endif
154
155#if WOLFSSL_CRYPT_HW_MUTEX
156 /* wolfSSL_CryptHwMutexInit is called on first wolfSSL_CryptHwMutexLock,
157 however it's recommended to call this directly on Hw init to avoid possible
158 race condition where two calls to wolfSSL_CryptHwMutexLock are made at
159 the same time. */
160 int wolfSSL_CryptHwMutexInit(void);
161 int wolfSSL_CryptHwMutexLock(void);
162 int wolfSSL_CryptHwMutexUnLock(void);
163#else
164 /* Define stubs, since HW mutex is disabled */
165 #define wolfSSL_CryptHwMutexInit() 0 /* Success */
166 #define wolfSSL_CryptHwMutexLock() 0 /* Success */
167 #define wolfSSL_CryptHwMutexUnLock() 0 /* Success */
168#endif /* WOLFSSL_CRYPT_HW_MUTEX */
169
170/* Mutex functions */
171WOLFSSL_LOCAL int InitMutex(wolfSSL_Mutex*);
172WOLFSSL_LOCAL int FreeMutex(wolfSSL_Mutex*);
173WOLFSSL_LOCAL int LockMutex(wolfSSL_Mutex*);
174WOLFSSL_LOCAL int UnLockMutex(wolfSSL_Mutex*);
175
176/* main crypto initialization function */
177WOLFSSL_API int wolfcrypt_Init(void);
178
179/* filesystem abstraction layer, used by ssl.c */
180#ifndef NO_FILESYSTEM
181
182#if defined(EBSNET)
183 #define XFILE int
184 #define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0);
185 #define XFSEEK vf_lseek
186 #define XFTELL vf_tell
187 #define XREWIND vf_rewind
188 #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT)
189 #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT)
190 #define XFCLOSE vf_close
191 #define XSEEK_END VSEEK_END
192 #define XBADFILE -1
193#elif defined(LSR_FS)
194 #include <fs.h>
195 #define XFILE struct fs_file*
196 #define XFOPEN(NAME, MODE) fs_open((char*)NAME);
197 #define XFSEEK(F, O, W) (void)F
198 #define XFTELL(F) (F)->len
199 #define XREWIND(F) (void)F
200 #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT)
201 #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT)
202 #define XFCLOSE fs_close
203 #define XSEEK_END 0
204 #define XBADFILE NULL
205#elif defined(FREESCALE_MQX)
206 #define XFILE MQX_FILE_PTR
207 #define XFOPEN fopen
208 #define XFSEEK fseek
209 #define XFTELL ftell
210 #define XREWIND(F) fseek(F, 0, IO_SEEK_SET)
211 #define XFREAD fread
212 #define XFWRITE fwrite
213 #define XFCLOSE fclose
214 #define XSEEK_END IO_SEEK_END
215 #define XBADFILE NULL
216#elif defined(MICRIUM)
217 #include <fs.h>
218 #define XFILE FS_FILE*
219 #define XFOPEN fs_fopen
220 #define XFSEEK fs_fseek
221 #define XFTELL fs_ftell
222 #define XREWIND fs_rewind
223 #define XFREAD fs_fread
224 #define XFWRITE fs_fwrite
225 #define XFCLOSE fs_fclose
226 #define XSEEK_END FS_SEEK_END
227 #define XBADFILE NULL
228#else
229 /* stdio, default case */
230 #define XFILE FILE*
231 #if defined(WOLFSSL_MDK_ARM)
232 #include <stdio.h>
233 extern FILE * wolfSSL_fopen(const char *name, const char *mode) ;
234 #define XFOPEN wolfSSL_fopen
235 #else
236 #define XFOPEN fopen
237 #endif
238 #define XFSEEK fseek
239 #define XFTELL ftell
240 #define XREWIND rewind
241 #define XFREAD fread
242 #define XFWRITE fwrite
243 #define XFCLOSE fclose
244 #define XSEEK_END SEEK_END
245 #define XBADFILE NULL
246#endif
247
248#endif /* NO_FILESYSTEM */
249
250
251/* Windows API defines its own min() macro. */
252#if defined(USE_WINDOWS_API)
253 #ifdef min
254 #define WOLFSSL_HAVE_MIN
255 #endif /* min */
256 #ifdef max
257 #define WOLFSSL_HAVE_MAX
258 #endif /* max */
259#endif /* USE_WINDOWS_API */
260
261
262#ifdef __cplusplus
263 } /* extern "C" */
264#endif
265
266#endif /* WOLF_CRYPT_PORT_H */
267
Note: See TracBrowser for help on using the repository browser.