MultiTech / CyaSSL

Dependents:   HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wc_port.h Source File

wc_port.h

00001 /* port.h
00002  *
00003  * Copyright (C) 2006-2014 wolfSSL Inc.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00020  */
00021 
00022 
00023 #ifndef CTAO_CRYPT_PORT_H
00024 #define CTAO_CRYPT_PORT_H
00025 
00026 
00027 #ifdef __cplusplus
00028     extern "C" {
00029 #endif
00030 
00031 
00032 #ifdef USE_WINDOWS_API 
00033     #ifdef CYASSL_GAME_BUILD
00034         #include "system/xtl.h"
00035     #else
00036         #ifndef WIN32_LEAN_AND_MEAN
00037             #define WIN32_LEAN_AND_MEAN
00038         #endif
00039         #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
00040             /* On WinCE winsock2.h must be included before windows.h */
00041             #include <winsock2.h>
00042         #endif
00043         #include <windows.h>
00044     #endif
00045 #elif defined(THREADX)
00046     #ifndef SINGLE_THREADED
00047         #include "tx_api.h"
00048     #endif
00049 #elif defined(MICRIUM)
00050     /* do nothing, just don't pick Unix */
00051 #elif defined(FREERTOS) || defined(CYASSL_SAFERTOS)
00052     /* do nothing */
00053 #elif defined(EBSNET)
00054     /* do nothing */
00055 #elif defined(FREESCALE_MQX)
00056     /* do nothing */
00057 #elif defined(CYASSL_MDK_ARM)
00058     #if defined(CYASSL_MDK5)
00059          #include "cmsis_os.h"
00060     #else
00061         #include <rtl.h>
00062     #endif
00063 #elif defined(CYASSL_CMSIS_RTOS)
00064     #include "cmsis_os.h"    
00065 #elif defined(CYASSL_TIRTOS)
00066     #include <ti/sysbios/BIOS.h>
00067     #include <ti/sysbios/knl/Semaphore.h>
00068 #else
00069     #ifndef SINGLE_THREADED
00070         #define CYASSL_PTHREADS
00071         #include <pthread.h>
00072     #endif
00073     #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
00074         #include <unistd.h>      /* for close of BIO */
00075     #endif
00076 #endif
00077 
00078 
00079 #ifdef SINGLE_THREADED
00080     typedef int CyaSSL_Mutex;
00081 #else /* MULTI_THREADED */
00082     /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */
00083     #ifdef FREERTOS
00084         typedef xSemaphoreHandle CyaSSL_Mutex;
00085     #elif defined(CYASSL_SAFERTOS)
00086         typedef struct CyaSSL_Mutex {
00087             signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
00088             xSemaphoreHandle mutex;
00089         } CyaSSL_Mutex;
00090     #elif defined(USE_WINDOWS_API)
00091         typedef CRITICAL_SECTION CyaSSL_Mutex;
00092     #elif defined(CYASSL_PTHREADS)
00093         typedef pthread_mutex_t CyaSSL_Mutex;
00094     #elif defined(THREADX)
00095         typedef TX_MUTEX CyaSSL_Mutex;
00096     #elif defined(MICRIUM)
00097         typedef OS_MUTEX CyaSSL_Mutex;
00098     #elif defined(EBSNET)
00099         typedef RTP_MUTEX CyaSSL_Mutex;
00100     #elif defined(FREESCALE_MQX)
00101         typedef MUTEX_STRUCT CyaSSL_Mutex;
00102     #elif defined(CYASSL_MDK_ARM)
00103         #if defined(CYASSL_CMSIS_RTOS)
00104             typedef osMutexId CyaSSL_Mutex;
00105         #else
00106             typedef OS_MUT CyaSSL_Mutex;
00107         #endif
00108     #elif defined(CYASSL_CMSIS_RTOS)
00109         typedef osMutexId CyaSSL_Mutex;
00110     #elif defined(CYASSL_TIRTOS)
00111         typedef ti_sysbios_knl_Semaphore_Handle CyaSSL_Mutex;
00112     #else
00113         #error Need a mutex type in multithreaded mode
00114     #endif /* USE_WINDOWS_API */
00115 #endif /* SINGLE_THREADED */
00116 
00117 CYASSL_LOCAL int InitMutex(CyaSSL_Mutex*);
00118 CYASSL_LOCAL int FreeMutex(CyaSSL_Mutex*);
00119 CYASSL_LOCAL int LockMutex(CyaSSL_Mutex*);
00120 CYASSL_LOCAL int UnLockMutex(CyaSSL_Mutex*);
00121 
00122 
00123 /* filesystem abstraction layer, used by ssl.c */
00124 #ifndef NO_FILESYSTEM
00125 
00126 #if defined(EBSNET)
00127     #define XFILE                    int
00128     #define XFOPEN(NAME, MODE)       vf_open((const char *)NAME, VO_RDONLY, 0);
00129     #define XFSEEK                   vf_lseek
00130     #define XFTELL                   vf_tell
00131     #define XREWIND                  vf_rewind
00132     #define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT)
00133     #define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT)
00134     #define XFCLOSE                  vf_close
00135     #define XSEEK_END                VSEEK_END
00136     #define XBADFILE                 -1
00137 #elif defined(LSR_FS)
00138     #include <fs.h>
00139     #define XFILE                   struct fs_file*
00140     #define XFOPEN(NAME, MODE)      fs_open((char*)NAME);
00141     #define XFSEEK(F, O, W)         (void)F
00142     #define XFTELL(F)               (F)->len
00143     #define XREWIND(F)              (void)F
00144     #define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT)
00145     #define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT)
00146     #define XFCLOSE                 fs_close
00147     #define XSEEK_END               0
00148     #define XBADFILE                NULL
00149 #elif defined(FREESCALE_MQX)
00150     #define XFILE                   MQX_FILE_PTR
00151     #define XFOPEN                  fopen
00152     #define XFSEEK                  fseek
00153     #define XFTELL                  ftell
00154     #define XREWIND(F)              fseek(F, 0, IO_SEEK_SET)
00155     #define XFREAD                  fread
00156     #define XFWRITE                 fwrite
00157     #define XFCLOSE                 fclose
00158     #define XSEEK_END               IO_SEEK_END
00159     #define XBADFILE                NULL
00160 #elif defined(MICRIUM)
00161     #include <fs.h>
00162     #define XFILE      FS_FILE*
00163     #define XFOPEN     fs_fopen
00164     #define XFSEEK     fs_fseek
00165     #define XFTELL     fs_ftell
00166     #define XREWIND    fs_rewind
00167     #define XFREAD     fs_fread
00168     #define XFWRITE    fs_fwrite
00169     #define XFCLOSE    fs_fclose
00170     #define XSEEK_END  FS_SEEK_END
00171     #define XBADFILE   NULL
00172 #else
00173     /* stdio, default case */
00174     #define XFILE      FILE*
00175     #if defined(CYASSL_MDK_ARM)
00176         #include <stdio.h>
00177         extern FILE * CyaSSL_fopen(const char *name, const char *mode) ;
00178         #define XFOPEN     CyaSSL_fopen
00179     #else
00180         #define XFOPEN     fopen
00181     #endif
00182     #define XFSEEK     fseek
00183     #define XFTELL     ftell
00184     #define XREWIND    rewind
00185     #define XFREAD     fread
00186     #define XFWRITE    fwrite
00187     #define XFCLOSE    fclose
00188     #define XSEEK_END  SEEK_END
00189     #define XBADFILE   NULL
00190 #endif
00191 
00192 #endif /* NO_FILESYSTEM */
00193 
00194 
00195 #ifdef __cplusplus
00196     }  /* extern "C" */
00197 #endif
00198 
00199 #endif /* CTAO_CRYPT_PORT_H */
00200