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.
Dependents: CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more
wolfio.h
00001 /* io.h 00002 * 00003 * Copyright (C) 2006-2020 wolfSSL Inc. 00004 * 00005 * This file is part of wolfSSL. 00006 * 00007 * wolfSSL 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 * wolfSSL 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-1335, USA 00020 */ 00021 00022 /*! 00023 \file wolfssl/wolfio.h 00024 */ 00025 00026 #ifndef WOLFSSL_IO_H 00027 #define WOLFSSL_IO_H 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 /* Micrium uses NetSock I/O callbacks in wolfio.c */ 00034 #if !defined(WOLFSSL_USER_IO) 00035 /* OCSP and CRL_IO require HTTP client */ 00036 #if defined(HAVE_OCSP) || defined(HAVE_CRL_IO) 00037 #ifndef HAVE_HTTP_CLIENT 00038 #define HAVE_HTTP_CLIENT 00039 #endif 00040 #endif 00041 #endif 00042 00043 #if !defined(WOLFSSL_USER_IO) 00044 /* Micrium uses NetSock I/O callbacks in wolfio.c */ 00045 #if !defined(USE_WOLFSSL_IO) && !defined(MICRIUM) && \ 00046 !defined(WOLFSSL_CONTIKI) && !defined(WOLFSSL_NO_SOCK) 00047 #define USE_WOLFSSL_IO 00048 #endif 00049 #endif 00050 00051 00052 #if defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT) 00053 00054 #ifdef HAVE_LIBZ 00055 #include "zlib.h" 00056 #endif 00057 00058 #ifndef USE_WINDOWS_API 00059 #if defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT) 00060 /* lwIP needs to be configured to use sockets API in this mode */ 00061 /* LWIP_SOCKET 1 in lwip/opt.h or in build */ 00062 #include "lwip/sockets.h" 00063 #ifndef LWIP_PROVIDE_ERRNO 00064 #include <errno.h> 00065 #define LWIP_PROVIDE_ERRNO 1 00066 #endif 00067 #elif defined(FREESCALE_MQX) 00068 #include <posix.h> 00069 #include <rtcs.h> 00070 #elif defined(FREESCALE_KSDK_MQX) 00071 #include <rtcs.h> 00072 #elif (defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)) 00073 #include "rl_net.h" 00074 #include "errno.h" 00075 #elif defined(WOLFSSL_CMSIS_RTOS) 00076 #include "cmsis_os.h" 00077 #elif defined(WOLFSSL_CMSIS_RTOSv2) 00078 #include "cmsis_os2.h" 00079 #elif defined(WOLFSSL_TIRTOS) 00080 #include <sys/socket.h> 00081 #elif defined(FREERTOS_TCP) 00082 #include "FreeRTOS_Sockets.h" 00083 #elif defined(WOLFSSL_IAR_ARM) 00084 /* nothing */ 00085 #elif defined(HAVE_NETX_BSD) 00086 #ifdef NETX_DUO 00087 #include "nxd_bsd.h" 00088 #else 00089 #include "nx_bsd.h" 00090 #endif 00091 #elif defined(WOLFSSL_VXWORKS) 00092 #include <sockLib.h> 00093 #include <errno.h> 00094 #elif defined(WOLFSSL_NUCLEUS_1_2) 00095 #include <externs.h> 00096 #include <errno.h> 00097 #elif defined(WOLFSSL_ATMEL) 00098 #include "socket/include/socket.h" 00099 #elif defined(INTIME_RTOS) 00100 #undef MIN 00101 #undef MAX 00102 #include <rt.h> 00103 #include <sys/types.h> 00104 #include <sys/socket.h> 00105 #include <netdb.h> 00106 #include <netinet/in.h> 00107 #include <io.h> 00108 /* <sys/socket.h> defines these, to avoid conflict, do undef */ 00109 #undef SOCKADDR 00110 #undef SOCKADDR_IN 00111 #elif defined(WOLFSSL_PRCONNECT_PRO) 00112 #include <prconnect_pro/prconnect_pro.h> 00113 #include <sys/types.h> 00114 #include <errno.h> 00115 #include <unistd.h> 00116 #include <fcntl.h> 00117 #include <netdb.h> 00118 #include <sys/ioctl.h> 00119 #elif defined(WOLFSSL_SGX) 00120 #include <errno.h> 00121 #elif defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) 00122 #include <mn_socket/mn_socket.h> 00123 #elif defined(WOLFSSL_DEOS) 00124 #include <socketapi.h> 00125 #include <lwip-socket.h> 00126 #include <errno.h> 00127 #elif defined(WOLFSSL_ZEPHYR) 00128 #include <net/socket.h> 00129 #elif defined(HAVE_NETX) 00130 #include "nx_api.h" 00131 #include "errno.h" 00132 #elif !defined(WOLFSSL_NO_SOCK) 00133 #include <sys/types.h> 00134 #include <errno.h> 00135 #ifndef EBSNET 00136 #include <unistd.h> 00137 #endif 00138 #include <fcntl.h> 00139 #define XFCNTL(fd, flag, block) fcntl((fd), (flag), (block)) 00140 00141 #if defined(HAVE_RTP_SYS) 00142 #include <socket.h> 00143 #elif defined(EBSNET) 00144 #include "rtipapi.h" /* errno */ 00145 #include "socket.h" 00146 #elif !defined(DEVKITPRO) && !defined(WOLFSSL_PICOTCP) \ 00147 && !defined(WOLFSSL_CONTIKI) && !defined(WOLFSSL_WICED) \ 00148 && !defined(WOLFSSL_GNRC) && !defined(WOLFSSL_RIOT_OS) 00149 #include <sys/socket.h> 00150 #include <arpa/inet.h> 00151 #include <netinet/in.h> 00152 #include <netdb.h> 00153 #ifdef __PPU 00154 #include <netex/errno.h> 00155 #else 00156 #include <sys/ioctl.h> 00157 #endif 00158 #endif 00159 #endif 00160 00161 #if defined(WOLFSSL_RENESAS_RA6M3G) /* Uses FREERTOS_TCP */ 00162 #include <errno.h> 00163 #endif 00164 00165 #endif /* USE_WINDOWS_API */ 00166 00167 #ifdef __sun 00168 #include <sys/filio.h> 00169 #endif 00170 00171 #ifdef USE_WINDOWS_API 00172 /* no epipe yet */ 00173 #ifndef WSAEPIPE 00174 #define WSAEPIPE -12345 00175 #endif 00176 #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK 00177 #define SOCKET_EAGAIN WSAETIMEDOUT 00178 #define SOCKET_ECONNRESET WSAECONNRESET 00179 #define SOCKET_EINTR WSAEINTR 00180 #define SOCKET_EPIPE WSAEPIPE 00181 #define SOCKET_ECONNREFUSED WSAENOTCONN 00182 #define SOCKET_ECONNABORTED WSAECONNABORTED 00183 #elif defined(__PPU) 00184 #define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK 00185 #define SOCKET_EAGAIN SYS_NET_EAGAIN 00186 #define SOCKET_ECONNRESET SYS_NET_ECONNRESET 00187 #define SOCKET_EINTR SYS_NET_EINTR 00188 #define SOCKET_EPIPE SYS_NET_EPIPE 00189 #define SOCKET_ECONNREFUSED SYS_NET_ECONNREFUSED 00190 #define SOCKET_ECONNABORTED SYS_NET_ECONNABORTED 00191 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) 00192 #if MQX_USE_IO_OLD 00193 /* RTCS old I/O doesn't have an EWOULDBLOCK */ 00194 #define SOCKET_EWOULDBLOCK EAGAIN 00195 #define SOCKET_EAGAIN EAGAIN 00196 #define SOCKET_ECONNRESET RTCSERR_TCP_CONN_RESET 00197 #define SOCKET_EINTR EINTR 00198 #define SOCKET_EPIPE EPIPE 00199 #define SOCKET_ECONNREFUSED RTCSERR_TCP_CONN_REFUSED 00200 #define SOCKET_ECONNABORTED RTCSERR_TCP_CONN_ABORTED 00201 #else 00202 #define SOCKET_EWOULDBLOCK NIO_EWOULDBLOCK 00203 #define SOCKET_EAGAIN NIO_EAGAIN 00204 #define SOCKET_ECONNRESET NIO_ECONNRESET 00205 #define SOCKET_EINTR NIO_EINTR 00206 #define SOCKET_EPIPE NIO_EPIPE 00207 #define SOCKET_ECONNREFUSED NIO_ECONNREFUSED 00208 #define SOCKET_ECONNABORTED NIO_ECONNABORTED 00209 #endif 00210 #elif defined(WOLFSSL_MDK_ARM)|| defined(WOLFSSL_KEIL_TCP_NET) 00211 #define SOCKET_EWOULDBLOCK BSD_ERROR_WOULDBLOCK 00212 #define SOCKET_EAGAIN BSD_ERROR_LOCKED 00213 #define SOCKET_ECONNRESET BSD_ERROR_CLOSED 00214 #define SOCKET_EINTR BSD_ERROR 00215 #define SOCKET_EPIPE BSD_ERROR 00216 #define SOCKET_ECONNREFUSED BSD_ERROR 00217 #define SOCKET_ECONNABORTED BSD_ERROR 00218 #elif defined(WOLFSSL_PICOTCP) 00219 #define SOCKET_EWOULDBLOCK PICO_ERR_EAGAIN 00220 #define SOCKET_EAGAIN PICO_ERR_EAGAIN 00221 #define SOCKET_ECONNRESET PICO_ERR_ECONNRESET 00222 #define SOCKET_EINTR PICO_ERR_EINTR 00223 #define SOCKET_EPIPE PICO_ERR_EIO 00224 #define SOCKET_ECONNREFUSED PICO_ERR_ECONNREFUSED 00225 #define SOCKET_ECONNABORTED PICO_ERR_ESHUTDOWN 00226 #elif defined(FREERTOS_TCP) 00227 #define SOCKET_EWOULDBLOCK FREERTOS_EWOULDBLOCK 00228 #define SOCKET_EAGAIN FREERTOS_EWOULDBLOCK 00229 #define SOCKET_ECONNRESET FREERTOS_SOCKET_ERROR 00230 #define SOCKET_EINTR FREERTOS_SOCKET_ERROR 00231 #define SOCKET_EPIPE FREERTOS_SOCKET_ERROR 00232 #define SOCKET_ECONNREFUSED FREERTOS_SOCKET_ERROR 00233 #define SOCKET_ECONNABORTED FREERTOS_SOCKET_ERROR 00234 #elif defined(WOLFSSL_NUCLEUS_1_2) 00235 #define SOCKET_EWOULDBLOCK NU_WOULD_BLOCK 00236 #define SOCKET_EAGAIN NU_WOULD_BLOCK 00237 #define SOCKET_ECONNRESET NU_NOT_CONNECTED 00238 #define SOCKET_EINTR NU_NOT_CONNECTED 00239 #define SOCKET_EPIPE NU_NOT_CONNECTED 00240 #define SOCKET_ECONNREFUSED NU_CONNECTION_REFUSED 00241 #define SOCKET_ECONNABORTED NU_NOT_CONNECTED 00242 #elif defined(WOLFSSL_DEOS) 00243 #define SOCKET_EWOULDBLOCK EAGAIN 00244 #define SOCKET_EAGAIN EAGAIN 00245 #define SOCKET_ECONNRESET EINTR 00246 #define SOCKET_EINTR EINTR 00247 #define SOCKET_EPIPE EPIPE 00248 #define SOCKET_ECONNREFUSED SOCKET_ERROR 00249 #define SOCKET_ECONNABORTED SOCKET_ERROR 00250 #elif defined(HAVE_NETX) 00251 #define SOCKET_EWOULDBLOCK NX_NOT_CONNECTED 00252 #define SOCKET_EAGAIN NX_NOT_CONNECTED 00253 #define SOCKET_ECONNRESET NX_NOT_CONNECTED 00254 #define SOCKET_EINTR NX_NOT_CONNECTED 00255 #define SOCKET_EPIPE NX_NOT_CONNECTED 00256 #define SOCKET_ECONNREFUSED NX_NOT_CONNECTED 00257 #define SOCKET_ECONNABORTED NX_NOT_CONNECTED 00258 #else 00259 #define SOCKET_EWOULDBLOCK EWOULDBLOCK 00260 #define SOCKET_EAGAIN EAGAIN 00261 #define SOCKET_ECONNRESET ECONNRESET 00262 #define SOCKET_EINTR EINTR 00263 #define SOCKET_EPIPE EPIPE 00264 #define SOCKET_ECONNREFUSED ECONNREFUSED 00265 #define SOCKET_ECONNABORTED ECONNABORTED 00266 #endif /* USE_WINDOWS_API */ 00267 00268 #ifdef DEVKITPRO 00269 /* from network.h */ 00270 int net_send(int, const void*, int, unsigned int); 00271 int net_recv(int, void*, int, unsigned int); 00272 #define SEND_FUNCTION net_send 00273 #define RECV_FUNCTION net_recv 00274 #elif defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT) 00275 #define SEND_FUNCTION lwip_send 00276 #define RECV_FUNCTION lwip_recv 00277 #elif defined(WOLFSSL_PICOTCP) 00278 #define SEND_FUNCTION pico_send 00279 #define RECV_FUNCTION pico_recv 00280 #elif defined(FREERTOS_TCP) 00281 #define RECV_FUNCTION(a,b,c,d) FreeRTOS_recv((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d)) 00282 #define SEND_FUNCTION(a,b,c,d) FreeRTOS_send((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d)) 00283 #elif defined(WOLFSSL_VXWORKS) 00284 #define SEND_FUNCTION send 00285 #define RECV_FUNCTION recv 00286 #elif defined(WOLFSSL_NUCLEUS_1_2) 00287 #define SEND_FUNCTION NU_Send 00288 #define RECV_FUNCTION NU_Recv 00289 #elif defined(WOLFSSL_ZEPHYR) 00290 #ifndef WOLFSSL_MAX_SEND_SZ 00291 #define WOLFSSL_MAX_SEND_SZ 256 00292 #endif 00293 00294 #define SEND_FUNCTION send 00295 #define RECV_FUNCTION recv 00296 #else 00297 #define SEND_FUNCTION send 00298 #define RECV_FUNCTION recv 00299 #if !defined(HAVE_SOCKADDR) && !defined(WOLFSSL_NO_SOCK) 00300 #define HAVE_SOCKADDR 00301 #endif 00302 #endif 00303 00304 #ifdef USE_WINDOWS_API 00305 typedef unsigned int SOCKET_T; 00306 #else 00307 typedef int SOCKET_T; 00308 #endif 00309 00310 #ifndef WOLFSSL_NO_SOCK 00311 #ifndef XSOCKLENT 00312 #ifdef USE_WINDOWS_API 00313 #define XSOCKLENT int 00314 #else 00315 #define XSOCKLENT socklen_t 00316 #endif 00317 #endif 00318 00319 /* Socket Addr Support */ 00320 #ifdef HAVE_SOCKADDR 00321 typedef struct sockaddr SOCKADDR; 00322 typedef struct sockaddr_storage SOCKADDR_S; 00323 typedef struct sockaddr_in SOCKADDR_IN; 00324 #ifdef WOLFSSL_IPV6 00325 typedef struct sockaddr_in6 SOCKADDR_IN6; 00326 #endif 00327 typedef struct hostent HOSTENT; 00328 #endif /* HAVE_SOCKADDR */ 00329 00330 /* use gethostbyname for c99 */ 00331 #if defined(HAVE_GETADDRINFO) && !defined(WOLF_C99) 00332 typedef struct addrinfo ADDRINFO; 00333 #endif 00334 #endif /* WOLFSSL_NO_SOCK */ 00335 00336 00337 /* IO API's */ 00338 #ifdef HAVE_IO_TIMEOUT 00339 WOLFSSL_API int wolfIO_SetBlockingMode(SOCKET_T sockfd, int non_blocking); 00340 WOLFSSL_API void wolfIO_SetTimeout(int to_sec); 00341 WOLFSSL_API int wolfIO_Select(SOCKET_T sockfd, int to_sec); 00342 #endif 00343 WOLFSSL_API int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, 00344 unsigned short port, int to_sec); 00345 WOLFSSL_API int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags); 00346 WOLFSSL_API int wolfIO_Recv(SOCKET_T sd, char *buf, int sz, int rdFlags); 00347 00348 #endif /* USE_WOLFSSL_IO || HAVE_HTTP_CLIENT */ 00349 00350 #ifndef WOLFSSL_NO_SOCK 00351 #ifdef USE_WINDOWS_API 00352 #ifndef CloseSocket 00353 #define CloseSocket(s) closesocket(s) 00354 #endif 00355 #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); } 00356 #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) 00357 #ifndef CloseSocket 00358 extern int closesocket(int); 00359 #define CloseSocket(s) closesocket(s) 00360 #endif 00361 #define StartTCP() 00362 #else 00363 #ifndef CloseSocket 00364 #define CloseSocket(s) close(s) 00365 #endif 00366 #define StartTCP() 00367 #ifdef FREERTOS_TCP_WINSIM 00368 extern int close(int); 00369 #endif 00370 #endif 00371 #endif /* WOLFSSL_NO_SOCK */ 00372 00373 00374 WOLFSSL_API int BioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx); 00375 WOLFSSL_API int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00376 #if defined(USE_WOLFSSL_IO) 00377 /* default IO callbacks */ 00378 WOLFSSL_API int EmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00379 WOLFSSL_API int EmbedSend(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00380 00381 #ifdef WOLFSSL_DTLS 00382 WOLFSSL_API int EmbedReceiveFrom(WOLFSSL* ssl, char* buf, int sz, void*); 00383 WOLFSSL_API int EmbedSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00384 WOLFSSL_API int EmbedGenerateCookie(WOLFSSL* ssl, unsigned char* buf, 00385 int sz, void*); 00386 #ifdef WOLFSSL_MULTICAST 00387 WOLFSSL_API int EmbedReceiveFromMcast(WOLFSSL* ssl, 00388 char* buf, int sz, void*); 00389 #endif /* WOLFSSL_MULTICAST */ 00390 #ifdef WOLFSSL_SESSION_EXPORT 00391 WOLFSSL_API int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz, 00392 unsigned short* port, int* fam); 00393 WOLFSSL_API int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz, 00394 unsigned short port, int fam); 00395 #endif /* WOLFSSL_SESSION_EXPORT */ 00396 #endif /* WOLFSSL_DTLS */ 00397 #endif /* USE_WOLFSSL_IO */ 00398 00399 #ifdef HAVE_OCSP 00400 WOLFSSL_API int wolfIO_HttpBuildRequestOcsp(const char* domainName, 00401 const char* path, int ocspReqSz, unsigned char* buf, int bufSize); 00402 WOLFSSL_API int wolfIO_HttpProcessResponseOcsp(int sfd, 00403 unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz, 00404 void* heap); 00405 00406 WOLFSSL_API int EmbedOcspLookup(void*, const char*, int, unsigned char*, 00407 int, unsigned char**); 00408 WOLFSSL_API void EmbedOcspRespFree(void*, unsigned char*); 00409 #endif 00410 00411 #ifdef HAVE_CRL_IO 00412 WOLFSSL_API int wolfIO_HttpBuildRequestCrl(const char* url, int urlSz, 00413 const char* domainName, unsigned char* buf, int bufSize); 00414 WOLFSSL_API int wolfIO_HttpProcessResponseCrl(WOLFSSL_CRL* crl, int sfd, 00415 unsigned char* httpBuf, int httpBufSz); 00416 00417 WOLFSSL_API int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, 00418 int urlSz); 00419 #endif 00420 00421 00422 #if defined(HAVE_HTTP_CLIENT) 00423 WOLFSSL_API int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName, 00424 char* outPath, unsigned short* outPort); 00425 00426 WOLFSSL_API int wolfIO_HttpBuildRequest(const char* reqType, 00427 const char* domainName, const char* path, int pathLen, int reqSz, 00428 const char* contentType, unsigned char* buf, int bufSize); 00429 WOLFSSL_LOCAL int wolfIO_HttpBuildRequest_ex(const char* reqType, 00430 const char* domainName, const char* path, int pathLen, int reqSz, 00431 const char* contentType, const char *exHdrs, unsigned char* buf, int bufSize); 00432 WOLFSSL_API int wolfIO_HttpProcessResponse(int sfd, const char** appStrList, 00433 unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz, 00434 int dynType, void* heap); 00435 #endif /* HAVE_HTTP_CLIENT */ 00436 00437 00438 /* I/O callbacks */ 00439 typedef int (*CallbackIORecv)(WOLFSSL *ssl, char *buf, int sz, void *ctx); 00440 typedef int (*CallbackIOSend)(WOLFSSL *ssl, char *buf, int sz, void *ctx); 00441 WOLFSSL_API void wolfSSL_CTX_SetIORecv(WOLFSSL_CTX*, CallbackIORecv); 00442 WOLFSSL_API void wolfSSL_CTX_SetIOSend(WOLFSSL_CTX*, CallbackIOSend); 00443 WOLFSSL_API void wolfSSL_SSLSetIORecv(WOLFSSL*, CallbackIORecv); 00444 WOLFSSL_API void wolfSSL_SSLSetIOSend(WOLFSSL*, CallbackIOSend); 00445 /* deprecated old name */ 00446 #define wolfSSL_SetIORecv wolfSSL_CTX_SetIORecv 00447 #define wolfSSL_SetIOSend wolfSSL_CTX_SetIOSend 00448 00449 WOLFSSL_API void wolfSSL_SetIOReadCtx( WOLFSSL* ssl, void *ctx); 00450 WOLFSSL_API void wolfSSL_SetIOWriteCtx(WOLFSSL* ssl, void *ctx); 00451 00452 WOLFSSL_API void* wolfSSL_GetIOReadCtx( WOLFSSL* ssl); 00453 WOLFSSL_API void* wolfSSL_GetIOWriteCtx(WOLFSSL* ssl); 00454 00455 WOLFSSL_API void wolfSSL_SetIOReadFlags( WOLFSSL* ssl, int flags); 00456 WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags); 00457 00458 00459 #ifdef HAVE_NETX 00460 WOLFSSL_LOCAL int NetX_Receive(WOLFSSL *ssl, char *buf, int sz, void *ctx); 00461 WOLFSSL_LOCAL int NetX_Send(WOLFSSL *ssl, char *buf, int sz, void *ctx); 00462 00463 WOLFSSL_API void wolfSSL_SetIO_NetX(WOLFSSL* ssl, NX_TCP_SOCKET* nxsocket, 00464 ULONG waitoption); 00465 #endif /* HAVE_NETX */ 00466 00467 #ifdef MICRIUM 00468 WOLFSSL_LOCAL int MicriumSend(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00469 WOLFSSL_LOCAL int MicriumReceive(WOLFSSL* ssl, char* buf, int sz, 00470 void* ctx); 00471 WOLFSSL_LOCAL int MicriumReceiveFrom(WOLFSSL* ssl, char* buf, int sz, 00472 void* ctx); 00473 WOLFSSL_LOCAL int MicriumSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00474 #endif /* MICRIUM */ 00475 00476 #if defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) 00477 WOLFSSL_LOCAL int Mynewt_Receive(WOLFSSL *ssl, char *buf, int sz, void *ctx); 00478 WOLFSSL_LOCAL int Mynewt_Send(WOLFSSL* ssl, char *buf, int sz, void *ctx); 00479 WOLFSSL_API void wolfSSL_SetIO_Mynewt(WOLFSSL* ssl, struct mn_socket* mnSocket, 00480 struct mn_sockaddr_in* mnSockAddrIn); 00481 #endif /* defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) */ 00482 00483 #ifdef WOLFSSL_UIP 00484 00485 struct uip_wolfssl_ctx { 00486 union socket_connector { 00487 struct tcp_socket tcp; 00488 struct udp_socket udp; 00489 } conn; 00490 WOLFSSL_CTX *ctx; 00491 WOLFSSL *ssl; 00492 uint8_t *input_databuf; 00493 uint8_t *output_databuf; 00494 uint8_t *ssl_rx_databuf; 00495 int ssl_rb_len; 00496 int ssl_rb_off; 00497 struct process *process; 00498 tcp_socket_data_callback_t input_callback; 00499 tcp_socket_event_callback_t event_callback; 00500 int closing; 00501 uip_ipaddr_t peer_addr; 00502 uint16_t peer_port; 00503 }; 00504 00505 typedef struct uip_wolfssl_ctx uip_wolfssl_ctx; 00506 00507 WOLFSSL_LOCAL int uIPSend(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00508 WOLFSSL_LOCAL int uIPReceive(WOLFSSL* ssl, char* buf, int sz, 00509 void* ctx); 00510 WOLFSSL_LOCAL int uIPReceiveFrom(WOLFSSL* ssl, char* buf, int sz, 00511 void* ctx); 00512 WOLFSSL_LOCAL int uIPSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00513 00514 #endif 00515 00516 #ifdef WOLFSSL_GNRC 00517 #include <sock_types.h> 00518 #include <net/gnrc.h> 00519 #include <net/af.h> 00520 #include <net/sock.h> 00521 #include <net/gnrc/tcp.h> 00522 #include <net/gnrc/udp.h> 00523 00524 struct gnrc_wolfssl_ctx { 00525 union socket_connector { 00526 #ifdef MODULE_SOCK_TCP 00527 sock_tcp_t tcp; 00528 #endif 00529 sock_udp_t udp; 00530 } conn; 00531 WOLFSSL_CTX *ctx; 00532 WOLFSSL *ssl; 00533 00534 int closing; 00535 struct _sock_tl_ep peer_addr; 00536 }; 00537 00538 typedef struct gnrc_wolfssl_ctx sock_tls_t; 00539 00540 WOLFSSL_LOCAL int GNRC_ReceiveFrom(WOLFSSL* ssl, char* buf, int sz, 00541 void* ctx); 00542 WOLFSSL_LOCAL int GNRC_SendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx); 00543 00544 #endif 00545 00546 00547 #ifdef WOLFSSL_DTLS 00548 typedef int (*CallbackGenCookie)(WOLFSSL* ssl, unsigned char* buf, int sz, 00549 void* ctx); 00550 WOLFSSL_API void wolfSSL_CTX_SetGenCookie(WOLFSSL_CTX*, CallbackGenCookie); 00551 WOLFSSL_API void wolfSSL_SetCookieCtx(WOLFSSL* ssl, void *ctx); 00552 WOLFSSL_API void* wolfSSL_GetCookieCtx(WOLFSSL* ssl); 00553 00554 #ifdef WOLFSSL_SESSION_EXPORT 00555 typedef int (*CallbackGetPeer)(WOLFSSL* ssl, char* ip, int* ipSz, 00556 unsigned short* port, int* fam); 00557 typedef int (*CallbackSetPeer)(WOLFSSL* ssl, char* ip, int ipSz, 00558 unsigned short port, int fam); 00559 00560 WOLFSSL_API void wolfSSL_CTX_SetIOGetPeer(WOLFSSL_CTX*, CallbackGetPeer); 00561 WOLFSSL_API void wolfSSL_CTX_SetIOSetPeer(WOLFSSL_CTX*, CallbackSetPeer); 00562 #endif /* WOLFSSL_SESSION_EXPORT */ 00563 #endif 00564 00565 00566 00567 #ifndef XINET_NTOP 00568 #define XINET_NTOP(a,b,c,d) inet_ntop((a),(b),(c),(d)) 00569 #ifdef USE_WINDOWS_API /* Windows-friendly definition */ 00570 #undef XINET_NTOP 00571 #define XINET_NTOP(a,b,c,d) InetNtop((a),(b),(c),(d)) 00572 #endif 00573 #endif 00574 #ifndef XINET_PTON 00575 #define XINET_PTON(a,b,c) inet_pton((a),(b),(c)) 00576 #ifdef USE_WINDOWS_API /* Windows-friendly definition */ 00577 #undef XINET_PTON 00578 #define XINET_PTON(a,b,c) InetPton((a),(b),(c)) 00579 #endif 00580 #endif 00581 #ifndef XHTONS 00582 #define XHTONS(a) htons((a)) 00583 #endif 00584 #ifndef XNTOHS 00585 #define XNTOHS(a) ntohs((a)) 00586 #endif 00587 00588 #ifndef WOLFSSL_IP4 00589 #define WOLFSSL_IP4 AF_INET 00590 #endif 00591 #ifndef WOLFSSL_IP6 00592 #define WOLFSSL_IP6 AF_INET6 00593 #endif 00594 00595 00596 #ifdef __cplusplus 00597 } /* extern "C" */ 00598 #endif 00599 00600 #endif /* WOLFSSL_IO_H */ 00601
Generated on Tue Jul 12 2022 20:59:07 by
1.7.2