blob: a233b6322210f7215c3b9a64302c32bc95c26ab3 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* io.h
2 *
3 * Copyright (C) 2006-2021 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
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-1335, USA
20 */
21
22/*!
23 \file wolfssl/wolfio.h
24*/
25
26#ifndef WOLFSSL_IO_H
27#define WOLFSSL_IO_H
28
29#ifdef __cplusplus
30 extern "C" {
31#endif
32
33/* Micrium uses NetSock I/O callbacks in wolfio.c */
34#if !defined(WOLFSSL_USER_IO)
35 /* OCSP and CRL_IO require HTTP client */
36 #if defined(HAVE_OCSP) || defined(HAVE_CRL_IO)
37 #ifndef HAVE_HTTP_CLIENT
38 #define HAVE_HTTP_CLIENT
39 #endif
40 #endif
41#endif
42
43#if !defined(WOLFSSL_USER_IO)
44 /* Micrium uses NetSock I/O callbacks in wolfio.c */
45 #if !defined(USE_WOLFSSL_IO) && !defined(MICRIUM) && \
46 !defined(WOLFSSL_CONTIKI) && !defined(WOLFSSL_NO_SOCK)
47 #define USE_WOLFSSL_IO
48 #endif
49#endif
50
51
52#if defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT)
53
54#ifdef HAVE_LIBZ
55 #include "zlib.h"
56#endif
57
58#ifndef USE_WINDOWS_API
59 #if defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT)
60 /* lwIP needs to be configured to use sockets API in this mode */
61 /* LWIP_SOCKET 1 in lwip/opt.h or in build */
62 #include "lwip/sockets.h"
63 #ifndef LWIP_PROVIDE_ERRNO
64 #include <errno.h>
65 #define LWIP_PROVIDE_ERRNO 1
66 #endif
67 #elif defined(FREESCALE_MQX)
68 #include <posix.h>
69 #include <rtcs.h>
70 #elif defined(FREESCALE_KSDK_MQX)
71 #include <rtcs.h>
72 #elif (defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET))
73 #include "rl_net.h"
74 #include "errno.h"
75 #elif defined(WOLFSSL_CMSIS_RTOS)
76 #include "cmsis_os.h"
77 #elif defined(WOLFSSL_CMSIS_RTOSv2)
78 #include "cmsis_os2.h"
79 #elif defined(WOLFSSL_TIRTOS)
80 #include <sys/socket.h>
81 #elif defined(FREERTOS_TCP)
82 #include "FreeRTOS_Sockets.h"
83 #elif defined(WOLFSSL_IAR_ARM)
84 /* nothing */
85 #elif defined(HAVE_NETX_BSD)
86 #ifdef NETX_DUO
87 #include "nxd_bsd.h"
88 #else
89 #include "nx_bsd.h"
90 #endif
91 #elif defined(WOLFSSL_VXWORKS)
92 #include <sockLib.h>
93 #include <errno.h>
94 #elif defined(WOLFSSL_NUCLEUS_1_2)
95 #include <externs.h>
96 #include <errno.h>
97 #elif defined(WOLFSSL_LINUXKM)
98 /* the requisite linux/net.h is included in wc_port.h, with incompatible warnings masked out. */
99 #elif defined(WOLFSSL_ATMEL)
100 #include "socket/include/socket.h"
101 #elif defined(INTIME_RTOS)
102 #undef MIN
103 #undef MAX
104 #include <rt.h>
105 #include <sys/types.h>
106 #include <sys/socket.h>
107 #include <netdb.h>
108 #include <netinet/in.h>
109 #include <io.h>
110 /* <sys/socket.h> defines these, to avoid conflict, do undef */
111 #undef SOCKADDR
112 #undef SOCKADDR_IN
113 #elif defined(WOLFSSL_PRCONNECT_PRO)
114 #include <prconnect_pro/prconnect_pro.h>
115 #include <sys/types.h>
116 #include <errno.h>
117 #include <unistd.h>
118 #include <fcntl.h>
119 #include <netdb.h>
120 #include <sys/ioctl.h>
121 #elif defined(WOLFSSL_SGX)
122 #include <errno.h>
123 #elif defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
124 #include <mn_socket/mn_socket.h>
125 #elif defined(WOLFSSL_DEOS)
126 #include <socketapi.h>
127 #include <lwip-socket.h>
128 #include <errno.h>
129 #elif defined(WOLFSSL_ZEPHYR)
130 #include <net/socket.h>
131 #elif defined(MICROCHIP_PIC32)
132 #include <sys/errno.h>
133 #elif defined(HAVE_NETX)
134 #include "nx_api.h"
135 #include "errno.h"
136 #elif defined(FUSION_RTOS)
137 #include <sys/fcltypes.h>
138 #include <fclerrno.h>
139 #include <fclfcntl.h>
140 #elif !defined(WOLFSSL_NO_SOCK)
141 #include <sys/types.h>
142 #include <errno.h>
143 #ifndef EBSNET
144 #include <unistd.h>
145 #endif
146 #include <fcntl.h>
147 #define XFCNTL(fd, flag, block) fcntl((fd), (flag), (block))
148
149 #if defined(HAVE_RTP_SYS)
150 #include <socket.h>
151 #elif defined(EBSNET)
152 #include "rtipapi.h" /* errno */
153 #include "socket.h"
154 #elif !defined(DEVKITPRO) && !defined(WOLFSSL_PICOTCP) \
155 && !defined(WOLFSSL_CONTIKI) && !defined(WOLFSSL_WICED) \
156 && !defined(WOLFSSL_GNRC) && !defined(WOLFSSL_RIOT_OS)
157 #include <sys/socket.h>
158 #include <arpa/inet.h>
159 #include <netinet/in.h>
160 #include <netdb.h>
161 #ifdef __PPU
162 #include <netex/errno.h>
163 #else
164 #include <sys/ioctl.h>
165 #endif
166 #endif
167 #endif
168
169 #if defined(WOLFSSL_RENESAS_RA6M3G) || defined(WOLFSSL_RENESAS_RA6M3) /* Uses FREERTOS_TCP */
170 #include <errno.h>
171 #endif
172
173#endif /* USE_WINDOWS_API */
174
175#ifdef __sun
176 #include <sys/filio.h>
177#endif
178
179#ifdef USE_WINDOWS_API
180 /* no epipe yet */
181 #ifndef WSAEPIPE
182 #define WSAEPIPE -12345
183 #endif
184 #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
185 #define SOCKET_EAGAIN WSAETIMEDOUT
186 #define SOCKET_ECONNRESET WSAECONNRESET
187 #define SOCKET_EINTR WSAEINTR
188 #define SOCKET_EPIPE WSAEPIPE
189 #define SOCKET_ECONNREFUSED WSAENOTCONN
190 #define SOCKET_ECONNABORTED WSAECONNABORTED
191#elif defined(__PPU)
192 #define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK
193 #define SOCKET_EAGAIN SYS_NET_EAGAIN
194 #define SOCKET_ECONNRESET SYS_NET_ECONNRESET
195 #define SOCKET_EINTR SYS_NET_EINTR
196 #define SOCKET_EPIPE SYS_NET_EPIPE
197 #define SOCKET_ECONNREFUSED SYS_NET_ECONNREFUSED
198 #define SOCKET_ECONNABORTED SYS_NET_ECONNABORTED
199#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
200 #if MQX_USE_IO_OLD
201 /* RTCS old I/O doesn't have an EWOULDBLOCK */
202 #define SOCKET_EWOULDBLOCK EAGAIN
203 #define SOCKET_EAGAIN EAGAIN
204 #define SOCKET_ECONNRESET RTCSERR_TCP_CONN_RESET
205 #define SOCKET_EINTR EINTR
206 #define SOCKET_EPIPE EPIPE
207 #define SOCKET_ECONNREFUSED RTCSERR_TCP_CONN_REFUSED
208 #define SOCKET_ECONNABORTED RTCSERR_TCP_CONN_ABORTED
209 #else
210 #define SOCKET_EWOULDBLOCK NIO_EWOULDBLOCK
211 #define SOCKET_EAGAIN NIO_EAGAIN
212 #define SOCKET_ECONNRESET NIO_ECONNRESET
213 #define SOCKET_EINTR NIO_EINTR
214 #define SOCKET_EPIPE NIO_EPIPE
215 #define SOCKET_ECONNREFUSED NIO_ECONNREFUSED
216 #define SOCKET_ECONNABORTED NIO_ECONNABORTED
217 #endif
218#elif defined(WOLFSSL_MDK_ARM)|| defined(WOLFSSL_KEIL_TCP_NET)
219 #define SOCKET_EWOULDBLOCK BSD_ERROR_WOULDBLOCK
220 #define SOCKET_EAGAIN BSD_ERROR_LOCKED
221 #define SOCKET_ECONNRESET BSD_ERROR_CLOSED
222 #define SOCKET_EINTR BSD_ERROR
223 #define SOCKET_EPIPE BSD_ERROR
224 #define SOCKET_ECONNREFUSED BSD_ERROR
225 #define SOCKET_ECONNABORTED BSD_ERROR
226#elif defined(WOLFSSL_PICOTCP)
227 #define SOCKET_EWOULDBLOCK PICO_ERR_EAGAIN
228 #define SOCKET_EAGAIN PICO_ERR_EAGAIN
229 #define SOCKET_ECONNRESET PICO_ERR_ECONNRESET
230 #define SOCKET_EINTR PICO_ERR_EINTR
231 #define SOCKET_EPIPE PICO_ERR_EIO
232 #define SOCKET_ECONNREFUSED PICO_ERR_ECONNREFUSED
233 #define SOCKET_ECONNABORTED PICO_ERR_ESHUTDOWN
234#elif defined(FREERTOS_TCP)
235 #define SOCKET_EWOULDBLOCK FREERTOS_EWOULDBLOCK
236 #define SOCKET_EAGAIN FREERTOS_EWOULDBLOCK
237 #define SOCKET_ECONNRESET FREERTOS_SOCKET_ERROR
238 #define SOCKET_EINTR FREERTOS_SOCKET_ERROR
239 #define SOCKET_EPIPE FREERTOS_SOCKET_ERROR
240 #define SOCKET_ECONNREFUSED FREERTOS_SOCKET_ERROR
241 #define SOCKET_ECONNABORTED FREERTOS_SOCKET_ERROR
242#elif defined(WOLFSSL_NUCLEUS_1_2)
243 #define SOCKET_EWOULDBLOCK NU_WOULD_BLOCK
244 #define SOCKET_EAGAIN NU_WOULD_BLOCK
245 #define SOCKET_ECONNRESET NU_NOT_CONNECTED
246 #define SOCKET_EINTR NU_NOT_CONNECTED
247 #define SOCKET_EPIPE NU_NOT_CONNECTED
248 #define SOCKET_ECONNREFUSED NU_CONNECTION_REFUSED
249 #define SOCKET_ECONNABORTED NU_NOT_CONNECTED
250#elif defined(WOLFSSL_DEOS)
251 /* `sockaddr_storage` is not defined in DEOS. This workaround will
252 * work for IPV4, but not IPV6
253 */
254 #define sockaddr_storage sockaddr_in
255 #define SOCKET_EWOULDBLOCK EAGAIN
256 #define SOCKET_EAGAIN EAGAIN
257 #define SOCKET_ECONNRESET EINTR
258 #define SOCKET_EINTR EINTR
259 #define SOCKET_EPIPE EPIPE
260 #define SOCKET_ECONNREFUSED SOCKET_ERROR
261 #define SOCKET_ECONNABORTED SOCKET_ERROR
262#elif defined(HAVE_NETX)
263 #define SOCKET_EWOULDBLOCK NX_NOT_CONNECTED
264 #define SOCKET_EAGAIN NX_NOT_CONNECTED
265 #define SOCKET_ECONNRESET NX_NOT_CONNECTED
266 #define SOCKET_EINTR NX_NOT_CONNECTED
267 #define SOCKET_EPIPE NX_NOT_CONNECTED
268 #define SOCKET_ECONNREFUSED NX_NOT_CONNECTED
269 #define SOCKET_ECONNABORTED NX_NOT_CONNECTED
270#elif defined(FUSION_RTOS)
271 #define SOCKET_EWOULDBLOCK FCL_EWOULDBLOCK
272 #define SOCKET_EAGAIN FCL_EAGAIN
273 #define SOCKET_ECONNRESET FNS_ECONNRESET
274 #define SOCKET_EINTR FCL_EINTR
275 #define SOCKET_EPIPE FCL_EPIPE
276 #define SOCKET_ECONNREFUSED FCL_ECONNREFUSED
277 #define SOCKET_ECONNABORTED FNS_ECONNABORTED
278#else
279 #define SOCKET_EWOULDBLOCK EWOULDBLOCK
280 #define SOCKET_EAGAIN EAGAIN
281 #define SOCKET_ECONNRESET ECONNRESET
282 #define SOCKET_EINTR EINTR
283 #define SOCKET_EPIPE EPIPE
284 #define SOCKET_ECONNREFUSED ECONNREFUSED
285 #define SOCKET_ECONNABORTED ECONNABORTED
286#endif /* USE_WINDOWS_API */
287
288#ifdef DEVKITPRO
289 /* from network.h */
290 #include <network.h>
291 #define SEND_FUNCTION net_send
292 #define RECV_FUNCTION net_recv
293#elif defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT)
294 #define SEND_FUNCTION lwip_send
295 #define RECV_FUNCTION lwip_recv
296#elif defined(WOLFSSL_PICOTCP)
297 #define SEND_FUNCTION pico_send
298 #define RECV_FUNCTION pico_recv
299#elif defined(FREERTOS_TCP)
300 #define RECV_FUNCTION(a,b,c,d) FreeRTOS_recv((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d))
301 #define SEND_FUNCTION(a,b,c,d) FreeRTOS_send((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d))
302#elif defined(WOLFSSL_VXWORKS)
303 #define SEND_FUNCTION send
304 #define RECV_FUNCTION recv
305#elif defined(WOLFSSL_NUCLEUS_1_2)
306 #define SEND_FUNCTION NU_Send
307 #define RECV_FUNCTION NU_Recv
308#elif defined(FUSION_RTOS)
309 #define SEND_FUNCTION FNS_SEND
310 #define RECV_FUNCTION FNS_RECV
311#elif defined(WOLFSSL_ZEPHYR)
312 #ifndef WOLFSSL_MAX_SEND_SZ
313 #define WOLFSSL_MAX_SEND_SZ 256
314 #endif
315
316 #define SEND_FUNCTION send
317 #define RECV_FUNCTION recv
318#elif defined(WOLFSSL_LINUXKM)
319 #define SEND_FUNCTION linuxkm_send
320 #define RECV_FUNCTION linuxkm_recv
321#else
322 #define SEND_FUNCTION send
323 #define RECV_FUNCTION recv
324 #if !defined(HAVE_SOCKADDR) && !defined(WOLFSSL_NO_SOCK)
325 #define HAVE_SOCKADDR
326 #endif
327#endif
328
329#ifdef USE_WINDOWS_API
330 typedef unsigned int SOCKET_T;
331 #ifndef SOCKET_INVALID
332 #define SOCKET_INVALID INVALID_SOCKET
333 #endif
334#else
335 typedef int SOCKET_T;
336 #ifndef SOCKET_INVALID
337 #define SOCKET_INVALID -1
338 #endif
339#endif
340
341#ifndef WOLFSSL_NO_SOCK
342 #ifndef XSOCKLENT
343 #ifdef USE_WINDOWS_API
344 #define XSOCKLENT int
345 #else
346 #define XSOCKLENT socklen_t
347 #endif
348 #endif
349
350 /* Socket Addr Support */
351 #ifdef HAVE_SOCKADDR
352 typedef struct sockaddr SOCKADDR;
353 typedef struct sockaddr_storage SOCKADDR_S;
354 typedef struct sockaddr_in SOCKADDR_IN;
355 #ifdef WOLFSSL_IPV6
356 typedef struct sockaddr_in6 SOCKADDR_IN6;
357 #endif
358 typedef struct hostent HOSTENT;
359 #endif /* HAVE_SOCKADDR */
360
361 /* use gethostbyname for c99 */
362 #if defined(HAVE_GETADDRINFO) && !defined(WOLF_C99)
363 typedef struct addrinfo ADDRINFO;
364 #endif
365#endif /* WOLFSSL_NO_SOCK */
366
367
368/* IO API's */
369#ifdef HAVE_IO_TIMEOUT
370 WOLFSSL_API int wolfIO_SetBlockingMode(SOCKET_T sockfd, int non_blocking);
371 WOLFSSL_API void wolfIO_SetTimeout(int to_sec);
372 WOLFSSL_API int wolfIO_Select(SOCKET_T sockfd, int to_sec);
373#endif
374WOLFSSL_API int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip,
375 unsigned short port, int to_sec);
376WOLFSSL_API int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags);
377WOLFSSL_API int wolfIO_Recv(SOCKET_T sd, char *buf, int sz, int rdFlags);
378
379#endif /* USE_WOLFSSL_IO || HAVE_HTTP_CLIENT */
380
381#ifndef WOLFSSL_NO_SOCK
382#ifdef USE_WINDOWS_API
383 #ifndef CloseSocket
384 #define CloseSocket(s) closesocket(s)
385 #endif
386 #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); }
387#elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
388 #ifndef CloseSocket
389 extern int closesocket(int);
390 #define CloseSocket(s) closesocket(s)
391 #endif
392 #define StartTCP()
393#elif defined(FUSION_RTOS)
394 #ifndef CloseSocket
395 #define CloseSocket(s) do { \
396 int err; \
397 FNS_CLOSE(s, &err); \
398 } while(0)
399 #endif
400#else
401 #ifndef CloseSocket
402 #define CloseSocket(s) close(s)
403 #endif
404 #define StartTCP()
405 #ifdef FREERTOS_TCP_WINSIM
406 extern int close(int);
407 #endif
408#endif
409#endif /* WOLFSSL_NO_SOCK */
410
411
412WOLFSSL_API int BioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx);
413WOLFSSL_API int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
414#if defined(USE_WOLFSSL_IO)
415 /* default IO callbacks */
416 WOLFSSL_API int EmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
417 WOLFSSL_API int EmbedSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
418
419 #ifdef WOLFSSL_DTLS
420 WOLFSSL_API int EmbedReceiveFrom(WOLFSSL* ssl, char* buf, int sz, void*);
421 WOLFSSL_API int EmbedSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
422 WOLFSSL_API int EmbedGenerateCookie(WOLFSSL* ssl, unsigned char* buf,
423 int sz, void*);
424 #ifdef WOLFSSL_MULTICAST
425 WOLFSSL_API int EmbedReceiveFromMcast(WOLFSSL* ssl,
426 char* buf, int sz, void*);
427 #endif /* WOLFSSL_MULTICAST */
428 #ifdef WOLFSSL_SESSION_EXPORT
429 WOLFSSL_API int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz,
430 unsigned short* port, int* fam);
431 WOLFSSL_API int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz,
432 unsigned short port, int fam);
433 #endif /* WOLFSSL_SESSION_EXPORT */
434 #endif /* WOLFSSL_DTLS */
435#endif /* USE_WOLFSSL_IO */
436
437#ifdef HAVE_OCSP
438 WOLFSSL_API int wolfIO_HttpBuildRequestOcsp(const char* domainName,
439 const char* path, int ocspReqSz, unsigned char* buf, int bufSize);
440 WOLFSSL_API int wolfIO_HttpProcessResponseOcsp(int sfd,
441 unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz,
442 void* heap);
443
444 WOLFSSL_API int EmbedOcspLookup(void*, const char*, int, unsigned char*,
445 int, unsigned char**);
446 WOLFSSL_API void EmbedOcspRespFree(void*, unsigned char*);
447#endif
448
449#ifdef HAVE_CRL_IO
450 WOLFSSL_API int wolfIO_HttpBuildRequestCrl(const char* url, int urlSz,
451 const char* domainName, unsigned char* buf, int bufSize);
452 WOLFSSL_API int wolfIO_HttpProcessResponseCrl(WOLFSSL_CRL* crl, int sfd,
453 unsigned char* httpBuf, int httpBufSz);
454
455 WOLFSSL_API int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url,
456 int urlSz);
457#endif
458
459
460#if defined(HAVE_HTTP_CLIENT)
461 WOLFSSL_API int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName,
462 char* outPath, unsigned short* outPort);
463
464 WOLFSSL_API int wolfIO_HttpBuildRequest(const char* reqType,
465 const char* domainName, const char* path, int pathLen, int reqSz,
466 const char* contentType, unsigned char* buf, int bufSize);
467 WOLFSSL_LOCAL int wolfIO_HttpBuildRequest_ex(const char* reqType,
468 const char* domainName, const char* path, int pathLen, int reqSz,
469 const char* contentType, const char *exHdrs, unsigned char* buf, int bufSize);
470 WOLFSSL_API int wolfIO_HttpProcessResponse(int sfd, const char** appStrList,
471 unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz,
472 int dynType, void* heap);
473#endif /* HAVE_HTTP_CLIENT */
474
475
476/* I/O callbacks */
477typedef int (*CallbackIORecv)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
478typedef int (*CallbackIOSend)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
479WOLFSSL_API void wolfSSL_CTX_SetIORecv(WOLFSSL_CTX*, CallbackIORecv);
480WOLFSSL_API void wolfSSL_CTX_SetIOSend(WOLFSSL_CTX*, CallbackIOSend);
481WOLFSSL_API void wolfSSL_SSLSetIORecv(WOLFSSL*, CallbackIORecv);
482WOLFSSL_API void wolfSSL_SSLSetIOSend(WOLFSSL*, CallbackIOSend);
483/* deprecated old name */
484#define wolfSSL_SetIORecv wolfSSL_CTX_SetIORecv
485#define wolfSSL_SetIOSend wolfSSL_CTX_SetIOSend
486
487WOLFSSL_API void wolfSSL_SetIOReadCtx( WOLFSSL* ssl, void *ctx);
488WOLFSSL_API void wolfSSL_SetIOWriteCtx(WOLFSSL* ssl, void *ctx);
489
490WOLFSSL_API void* wolfSSL_GetIOReadCtx( WOLFSSL* ssl);
491WOLFSSL_API void* wolfSSL_GetIOWriteCtx(WOLFSSL* ssl);
492
493WOLFSSL_API void wolfSSL_SetIOReadFlags( WOLFSSL* ssl, int flags);
494WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
495
496
497#ifdef HAVE_NETX
498 WOLFSSL_LOCAL int NetX_Receive(WOLFSSL *ssl, char *buf, int sz, void *ctx);
499 WOLFSSL_LOCAL int NetX_Send(WOLFSSL *ssl, char *buf, int sz, void *ctx);
500
501 WOLFSSL_API void wolfSSL_SetIO_NetX(WOLFSSL* ssl, NX_TCP_SOCKET* nxsocket,
502 ULONG waitoption);
503#endif /* HAVE_NETX */
504
505#ifdef MICRIUM
506 WOLFSSL_LOCAL int MicriumSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
507 WOLFSSL_LOCAL int MicriumReceive(WOLFSSL* ssl, char* buf, int sz,
508 void* ctx);
509 WOLFSSL_LOCAL int MicriumReceiveFrom(WOLFSSL* ssl, char* buf, int sz,
510 void* ctx);
511 WOLFSSL_LOCAL int MicriumSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
512#endif /* MICRIUM */
513
514#if defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
515 WOLFSSL_LOCAL int Mynewt_Receive(WOLFSSL *ssl, char *buf, int sz, void *ctx);
516 WOLFSSL_LOCAL int Mynewt_Send(WOLFSSL* ssl, char *buf, int sz, void *ctx);
517 WOLFSSL_API void wolfSSL_SetIO_Mynewt(WOLFSSL* ssl, struct mn_socket* mnSocket,
518 struct mn_sockaddr_in* mnSockAddrIn);
519#endif /* defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) */
520
521#ifdef WOLFSSL_UIP
522
523 struct uip_wolfssl_ctx {
524 union socket_connector {
525 struct tcp_socket tcp;
526 struct udp_socket udp;
527 } conn;
528 WOLFSSL_CTX *ctx;
529 WOLFSSL *ssl;
530 byte *input_databuf;
531 byte *output_databuf;
532 byte *ssl_rx_databuf;
533 int ssl_rb_len;
534 int ssl_rb_off;
535 struct process *process;
536 tcp_socket_data_callback_t input_callback;
537 tcp_socket_event_callback_t event_callback;
538 int closing;
539 uip_ipaddr_t peer_addr;
540 word16 peer_port;
541 };
542
543 typedef struct uip_wolfssl_ctx uip_wolfssl_ctx;
544
545 WOLFSSL_LOCAL int uIPSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
546 WOLFSSL_LOCAL int uIPReceive(WOLFSSL* ssl, char* buf, int sz,
547 void* ctx);
548 WOLFSSL_LOCAL int uIPReceiveFrom(WOLFSSL* ssl, char* buf, int sz,
549 void* ctx);
550 WOLFSSL_LOCAL int uIPSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
551
552#endif
553
554#ifdef WOLFSSL_GNRC
555 #include <sock_types.h>
556 #include <net/gnrc.h>
557 #include <net/af.h>
558 #include <net/sock.h>
559 #include <net/gnrc/tcp.h>
560 #include <net/gnrc/udp.h>
561
562 struct gnrc_wolfssl_ctx {
563 union socket_connector {
564 #ifdef MODULE_SOCK_TCP
565 sock_tcp_t tcp;
566 #endif
567 sock_udp_t udp;
568 } conn;
569 WOLFSSL_CTX *ctx;
570 WOLFSSL *ssl;
571
572 int closing;
573 struct _sock_tl_ep peer_addr;
574 };
575
576 typedef struct gnrc_wolfssl_ctx sock_tls_t;
577
578 WOLFSSL_LOCAL int GNRC_ReceiveFrom(WOLFSSL* ssl, char* buf, int sz,
579 void* ctx);
580 WOLFSSL_LOCAL int GNRC_SendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
581
582#endif
583
584
585#ifdef WOLFSSL_DTLS
586 typedef int (*CallbackGenCookie)(WOLFSSL* ssl, unsigned char* buf, int sz,
587 void* ctx);
588 WOLFSSL_API void wolfSSL_CTX_SetGenCookie(WOLFSSL_CTX*, CallbackGenCookie);
589 WOLFSSL_API void wolfSSL_SetCookieCtx(WOLFSSL* ssl, void *ctx);
590 WOLFSSL_API void* wolfSSL_GetCookieCtx(WOLFSSL* ssl);
591
592 #ifdef WOLFSSL_SESSION_EXPORT
593 typedef int (*CallbackGetPeer)(WOLFSSL* ssl, char* ip, int* ipSz,
594 unsigned short* port, int* fam);
595 typedef int (*CallbackSetPeer)(WOLFSSL* ssl, char* ip, int ipSz,
596 unsigned short port, int fam);
597
598 WOLFSSL_API void wolfSSL_CTX_SetIOGetPeer(WOLFSSL_CTX*, CallbackGetPeer);
599 WOLFSSL_API void wolfSSL_CTX_SetIOSetPeer(WOLFSSL_CTX*, CallbackSetPeer);
600 #endif /* WOLFSSL_SESSION_EXPORT */
601#endif
602
603
604
605#ifndef XINET_NTOP
606 #define XINET_NTOP(a,b,c,d) inet_ntop((a),(b),(c),(d))
607 #ifdef USE_WINDOWS_API /* Windows-friendly definition */
608 #undef XINET_NTOP
609 #define XINET_NTOP(a,b,c,d) InetNtop((a),(b),(c),(d))
610 #endif
611#endif
612#ifndef XINET_PTON
613 #define XINET_PTON(a,b,c) inet_pton((a),(b),(c))
614 #ifdef USE_WINDOWS_API /* Windows-friendly definition */
615 #undef XINET_PTON
616 #define XINET_PTON(a,b,c) InetPton((a),(b),(c))
617 #endif
618#endif
619
620#ifndef XHTONS
621 #if !defined(WOLFSSL_NO_SOCK) && (defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT))
622 #define XHTONS(a) htons((a))
623 #else
624 /* we don't have sockets, so define our own htons and ntohs */
625 #ifdef BIG_ENDIAN_ORDER
626 #define XHTONS(a) (a)
627 #else
628 #define XHTONS(a) ((((a) >> 8) & 0xff) | (((a) & 0xff) << 8))
629 #endif
630 #endif
631#endif
632#ifndef XNTOHS
633 #if !defined(WOLFSSL_NO_SOCK) && (defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT))
634 #define XNTOHS(a) ntohs((a))
635 #else
636 /* we don't have sockets, so define our own htons and ntohs */
637 #ifdef BIG_ENDIAN_ORDER
638 #define XNTOHS(a) (a)
639 #else
640 #define XNTOHS(a) ((((a) >> 8) & 0xff) | (((a) & 0xff) << 8))
641 #endif
642 #endif
643#endif
644
645#ifndef WOLFSSL_IP4
646 #define WOLFSSL_IP4 AF_INET
647#endif
648#ifndef WOLFSSL_IP6
649 #define WOLFSSL_IP6 AF_INET6
650#endif
651
652
653#ifdef __cplusplus
654 } /* extern "C" */
655#endif
656
657#endif /* WOLFSSL_IO_H */