wolfio.h
Go to the documentation of this file.
1 /* io.h
2  *
3  * Copyright (C) 2006-2020 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 
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_ATMEL)
98  #include "socket/include/socket.h"
99  #elif defined(INTIME_RTOS)
100  #undef MIN
101  #undef MAX
102  #include <rt.h>
103  #include <sys/types.h>
104  #include <sys/socket.h>
105  #include <netdb.h>
106  #include <netinet/in.h>
107  #include <io.h>
108  /* <sys/socket.h> defines these, to avoid conflict, do undef */
109  #undef SOCKADDR
110  #undef SOCKADDR_IN
111  #elif defined(WOLFSSL_PRCONNECT_PRO)
112  #include <prconnect_pro/prconnect_pro.h>
113  #include <sys/types.h>
114  #include <errno.h>
115  #include <unistd.h>
116  #include <fcntl.h>
117  #include <netdb.h>
118  #include <sys/ioctl.h>
119  #elif defined(WOLFSSL_SGX)
120  #include <errno.h>
121  #elif defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
122  #include <mn_socket/mn_socket.h>
123  #elif defined(WOLFSSL_DEOS)
124  #include <socketapi.h>
125  #include <lwip-socket.h>
126  #include <errno.h>
127  #elif defined(WOLFSSL_ZEPHYR)
128  #include <net/socket.h>
129  #elif defined(HAVE_NETX)
130  #include "nx_api.h"
131  #include "errno.h"
132  #elif !defined(WOLFSSL_NO_SOCK)
133  #include <sys/types.h>
134  #include <errno.h>
135  #ifndef EBSNET
136  #include <unistd.h>
137  #endif
138  #include <fcntl.h>
139  #define XFCNTL(fd, flag, block) fcntl((fd), (flag), (block))
140 
141  #if defined(HAVE_RTP_SYS)
142  #include <socket.h>
143  #elif defined(EBSNET)
144  #include "rtipapi.h" /* errno */
145  #include "socket.h"
146  #elif !defined(DEVKITPRO) && !defined(WOLFSSL_PICOTCP) \
147  && !defined(WOLFSSL_CONTIKI) && !defined(WOLFSSL_WICED) \
148  && !defined(WOLFSSL_GNRC) && !defined(WOLFSSL_RIOT_OS)
149  #include <sys/socket.h>
150  #include <arpa/inet.h>
151  #include <netinet/in.h>
152  #include <netdb.h>
153  #ifdef __PPU
154  #include <netex/errno.h>
155  #else
156  #include <sys/ioctl.h>
157  #endif
158  #endif
159  #endif
160 
161  #if defined(WOLFSSL_RENESAS_RA6M3G) /* Uses FREERTOS_TCP */
162  #include <errno.h>
163  #endif
164 
165 #endif /* USE_WINDOWS_API */
166 
167 #ifdef __sun
168  #include <sys/filio.h>
169 #endif
170 
171 #ifdef USE_WINDOWS_API
172  /* no epipe yet */
173  #ifndef WSAEPIPE
174  #define WSAEPIPE -12345
175  #endif
176  #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
177  #define SOCKET_EAGAIN WSAETIMEDOUT
178  #define SOCKET_ECONNRESET WSAECONNRESET
179  #define SOCKET_EINTR WSAEINTR
180  #define SOCKET_EPIPE WSAEPIPE
181  #define SOCKET_ECONNREFUSED WSAENOTCONN
182  #define SOCKET_ECONNABORTED WSAECONNABORTED
183 #elif defined(__PPU)
184  #define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK
185  #define SOCKET_EAGAIN SYS_NET_EAGAIN
186  #define SOCKET_ECONNRESET SYS_NET_ECONNRESET
187  #define SOCKET_EINTR SYS_NET_EINTR
188  #define SOCKET_EPIPE SYS_NET_EPIPE
189  #define SOCKET_ECONNREFUSED SYS_NET_ECONNREFUSED
190  #define SOCKET_ECONNABORTED SYS_NET_ECONNABORTED
191 #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
192  #if MQX_USE_IO_OLD
193  /* RTCS old I/O doesn't have an EWOULDBLOCK */
194  #define SOCKET_EWOULDBLOCK EAGAIN
195  #define SOCKET_EAGAIN EAGAIN
196  #define SOCKET_ECONNRESET RTCSERR_TCP_CONN_RESET
197  #define SOCKET_EINTR EINTR
198  #define SOCKET_EPIPE EPIPE
199  #define SOCKET_ECONNREFUSED RTCSERR_TCP_CONN_REFUSED
200  #define SOCKET_ECONNABORTED RTCSERR_TCP_CONN_ABORTED
201  #else
202  #define SOCKET_EWOULDBLOCK NIO_EWOULDBLOCK
203  #define SOCKET_EAGAIN NIO_EAGAIN
204  #define SOCKET_ECONNRESET NIO_ECONNRESET
205  #define SOCKET_EINTR NIO_EINTR
206  #define SOCKET_EPIPE NIO_EPIPE
207  #define SOCKET_ECONNREFUSED NIO_ECONNREFUSED
208  #define SOCKET_ECONNABORTED NIO_ECONNABORTED
209  #endif
210 #elif defined(WOLFSSL_MDK_ARM)|| defined(WOLFSSL_KEIL_TCP_NET)
211  #define SOCKET_EWOULDBLOCK BSD_ERROR_WOULDBLOCK
212  #define SOCKET_EAGAIN BSD_ERROR_LOCKED
213  #define SOCKET_ECONNRESET BSD_ERROR_CLOSED
214  #define SOCKET_EINTR BSD_ERROR
215  #define SOCKET_EPIPE BSD_ERROR
216  #define SOCKET_ECONNREFUSED BSD_ERROR
217  #define SOCKET_ECONNABORTED BSD_ERROR
218 #elif defined(WOLFSSL_PICOTCP)
219  #define SOCKET_EWOULDBLOCK PICO_ERR_EAGAIN
220  #define SOCKET_EAGAIN PICO_ERR_EAGAIN
221  #define SOCKET_ECONNRESET PICO_ERR_ECONNRESET
222  #define SOCKET_EINTR PICO_ERR_EINTR
223  #define SOCKET_EPIPE PICO_ERR_EIO
224  #define SOCKET_ECONNREFUSED PICO_ERR_ECONNREFUSED
225  #define SOCKET_ECONNABORTED PICO_ERR_ESHUTDOWN
226 #elif defined(FREERTOS_TCP)
227  #define SOCKET_EWOULDBLOCK FREERTOS_EWOULDBLOCK
228  #define SOCKET_EAGAIN FREERTOS_EWOULDBLOCK
229  #define SOCKET_ECONNRESET FREERTOS_SOCKET_ERROR
230  #define SOCKET_EINTR FREERTOS_SOCKET_ERROR
231  #define SOCKET_EPIPE FREERTOS_SOCKET_ERROR
232  #define SOCKET_ECONNREFUSED FREERTOS_SOCKET_ERROR
233  #define SOCKET_ECONNABORTED FREERTOS_SOCKET_ERROR
234 #elif defined(WOLFSSL_NUCLEUS_1_2)
235  #define SOCKET_EWOULDBLOCK NU_WOULD_BLOCK
236  #define SOCKET_EAGAIN NU_WOULD_BLOCK
237  #define SOCKET_ECONNRESET NU_NOT_CONNECTED
238  #define SOCKET_EINTR NU_NOT_CONNECTED
239  #define SOCKET_EPIPE NU_NOT_CONNECTED
240  #define SOCKET_ECONNREFUSED NU_CONNECTION_REFUSED
241  #define SOCKET_ECONNABORTED NU_NOT_CONNECTED
242 #elif defined(WOLFSSL_DEOS)
243  #define SOCKET_EWOULDBLOCK EAGAIN
244  #define SOCKET_EAGAIN EAGAIN
245  #define SOCKET_ECONNRESET EINTR
246  #define SOCKET_EINTR EINTR
247  #define SOCKET_EPIPE EPIPE
248  #define SOCKET_ECONNREFUSED SOCKET_ERROR
249  #define SOCKET_ECONNABORTED SOCKET_ERROR
250 #elif defined(HAVE_NETX)
251  #define SOCKET_EWOULDBLOCK NX_NOT_CONNECTED
252  #define SOCKET_EAGAIN NX_NOT_CONNECTED
253  #define SOCKET_ECONNRESET NX_NOT_CONNECTED
254  #define SOCKET_EINTR NX_NOT_CONNECTED
255  #define SOCKET_EPIPE NX_NOT_CONNECTED
256  #define SOCKET_ECONNREFUSED NX_NOT_CONNECTED
257  #define SOCKET_ECONNABORTED NX_NOT_CONNECTED
258 #else
259  #define SOCKET_EWOULDBLOCK EWOULDBLOCK
260  #define SOCKET_EAGAIN EAGAIN
261  #define SOCKET_ECONNRESET ECONNRESET
262  #define SOCKET_EINTR EINTR
263  #define SOCKET_EPIPE EPIPE
264  #define SOCKET_ECONNREFUSED ECONNREFUSED
265  #define SOCKET_ECONNABORTED ECONNABORTED
266 #endif /* USE_WINDOWS_API */
267 
268 #ifdef DEVKITPRO
269  /* from network.h */
270  int net_send(int, const void*, int, unsigned int);
271  int net_recv(int, void*, int, unsigned int);
272  #define SEND_FUNCTION net_send
273  #define RECV_FUNCTION net_recv
274 #elif defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT)
275  #define SEND_FUNCTION lwip_send
276  #define RECV_FUNCTION lwip_recv
277 #elif defined(WOLFSSL_PICOTCP)
278  #define SEND_FUNCTION pico_send
279  #define RECV_FUNCTION pico_recv
280 #elif defined(FREERTOS_TCP)
281  #define RECV_FUNCTION(a,b,c,d) FreeRTOS_recv((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d))
282  #define SEND_FUNCTION(a,b,c,d) FreeRTOS_send((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d))
283 #elif defined(WOLFSSL_VXWORKS)
284  #define SEND_FUNCTION send
285  #define RECV_FUNCTION recv
286 #elif defined(WOLFSSL_NUCLEUS_1_2)
287  #define SEND_FUNCTION NU_Send
288  #define RECV_FUNCTION NU_Recv
289 #elif defined(WOLFSSL_ZEPHYR)
290  #ifndef WOLFSSL_MAX_SEND_SZ
291  #define WOLFSSL_MAX_SEND_SZ 256
292  #endif
293 
294  #define SEND_FUNCTION send
295  #define RECV_FUNCTION recv
296 #else
297  #define SEND_FUNCTION send
298  #define RECV_FUNCTION recv
299  #if !defined(HAVE_SOCKADDR) && !defined(WOLFSSL_NO_SOCK)
300  #define HAVE_SOCKADDR
301  #endif
302 #endif
303 
304 #ifdef USE_WINDOWS_API
305  typedef unsigned int SOCKET_T;
306 #else
307  typedef int SOCKET_T;
308 #endif
309 
310 #ifndef WOLFSSL_NO_SOCK
311  #ifndef XSOCKLENT
312  #ifdef USE_WINDOWS_API
313  #define XSOCKLENT int
314  #else
315  #define XSOCKLENT socklen_t
316  #endif
317  #endif
318 
319  /* Socket Addr Support */
320  #ifdef HAVE_SOCKADDR
321  typedef struct sockaddr SOCKADDR;
322  typedef struct sockaddr_storage SOCKADDR_S;
323  typedef struct sockaddr_in SOCKADDR_IN;
324  #ifdef WOLFSSL_IPV6
325  typedef struct sockaddr_in6 SOCKADDR_IN6;
326  #endif
327  typedef struct hostent HOSTENT;
328  #endif /* HAVE_SOCKADDR */
329 
330  /* use gethostbyname for c99 */
331  #if defined(HAVE_GETADDRINFO) && !defined(WOLF_C99)
332  typedef struct addrinfo ADDRINFO;
333  #endif
334 #endif /* WOLFSSL_NO_SOCK */
335 
336 
337 /* IO API's */
338 #ifdef HAVE_IO_TIMEOUT
339  WOLFSSL_API int wolfIO_SetBlockingMode(SOCKET_T sockfd, int non_blocking);
340  WOLFSSL_API void wolfIO_SetTimeout(int to_sec);
341  WOLFSSL_API int wolfIO_Select(SOCKET_T sockfd, int to_sec);
342 #endif
343 WOLFSSL_API int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip,
344  unsigned short port, int to_sec);
345 WOLFSSL_API int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags);
346 WOLFSSL_API int wolfIO_Recv(SOCKET_T sd, char *buf, int sz, int rdFlags);
347 
348 #endif /* USE_WOLFSSL_IO || HAVE_HTTP_CLIENT */
349 
350 #ifndef WOLFSSL_NO_SOCK
351 #ifdef USE_WINDOWS_API
352  #ifndef CloseSocket
353  #define CloseSocket(s) closesocket(s)
354  #endif
355  #define StartTCP() { WSADATA wsd; WSAStartup(0x0002, &wsd); }
356 #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
357  #ifndef CloseSocket
358  extern int closesocket(int);
359  #define CloseSocket(s) closesocket(s)
360  #endif
361  #define StartTCP()
362 #else
363  #ifndef CloseSocket
364  #define CloseSocket(s) close(s)
365  #endif
366  #define StartTCP()
367  #ifdef FREERTOS_TCP_WINSIM
368  extern int close(int);
369  #endif
370 #endif
371 #endif /* WOLFSSL_NO_SOCK */
372 
373 
374 WOLFSSL_API int BioSend(WOLFSSL* ssl, char *buf, int sz, void *ctx);
375 WOLFSSL_API int BioReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
376 #if defined(USE_WOLFSSL_IO)
377  /* default IO callbacks */
378  WOLFSSL_API int EmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
379  WOLFSSL_API int EmbedSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
380 
381  #ifdef WOLFSSL_DTLS
382  WOLFSSL_API int EmbedReceiveFrom(WOLFSSL* ssl, char* buf, int sz, void*);
383  WOLFSSL_API int EmbedSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
384  WOLFSSL_API int EmbedGenerateCookie(WOLFSSL* ssl, unsigned char* buf,
385  int sz, void*);
386  #ifdef WOLFSSL_MULTICAST
387  WOLFSSL_API int EmbedReceiveFromMcast(WOLFSSL* ssl,
388  char* buf, int sz, void*);
389  #endif /* WOLFSSL_MULTICAST */
390  #ifdef WOLFSSL_SESSION_EXPORT
391  WOLFSSL_API int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz,
392  unsigned short* port, int* fam);
393  WOLFSSL_API int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz,
394  unsigned short port, int fam);
395  #endif /* WOLFSSL_SESSION_EXPORT */
396  #endif /* WOLFSSL_DTLS */
397 #endif /* USE_WOLFSSL_IO */
398 
399 #ifdef HAVE_OCSP
400  WOLFSSL_API int wolfIO_HttpBuildRequestOcsp(const char* domainName,
401  const char* path, int ocspReqSz, unsigned char* buf, int bufSize);
402  WOLFSSL_API int wolfIO_HttpProcessResponseOcsp(int sfd,
403  unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz,
404  void* heap);
405 
406  WOLFSSL_API int EmbedOcspLookup(void*, const char*, int, unsigned char*,
407  int, unsigned char**);
408  WOLFSSL_API void EmbedOcspRespFree(void*, unsigned char*);
409 #endif
410 
411 #ifdef HAVE_CRL_IO
412  WOLFSSL_API int wolfIO_HttpBuildRequestCrl(const char* url, int urlSz,
413  const char* domainName, unsigned char* buf, int bufSize);
414  WOLFSSL_API int wolfIO_HttpProcessResponseCrl(WOLFSSL_CRL* crl, int sfd,
415  unsigned char* httpBuf, int httpBufSz);
416 
417  WOLFSSL_API int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url,
418  int urlSz);
419 #endif
420 
421 
422 #if defined(HAVE_HTTP_CLIENT)
423  WOLFSSL_API int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName,
424  char* outPath, unsigned short* outPort);
425 
426  WOLFSSL_API int wolfIO_HttpBuildRequest(const char* reqType,
427  const char* domainName, const char* path, int pathLen, int reqSz,
428  const char* contentType, unsigned char* buf, int bufSize);
429  WOLFSSL_LOCAL int wolfIO_HttpBuildRequest_ex(const char* reqType,
430  const char* domainName, const char* path, int pathLen, int reqSz,
431  const char* contentType, const char *exHdrs, unsigned char* buf, int bufSize);
432  WOLFSSL_API int wolfIO_HttpProcessResponse(int sfd, const char** appStrList,
433  unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz,
434  int dynType, void* heap);
435 #endif /* HAVE_HTTP_CLIENT */
436 
437 
438 /* I/O callbacks */
439 typedef int (*CallbackIORecv)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
440 typedef int (*CallbackIOSend)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
441 WOLFSSL_API void wolfSSL_CTX_SetIORecv(WOLFSSL_CTX*, CallbackIORecv);
442 WOLFSSL_API void wolfSSL_CTX_SetIOSend(WOLFSSL_CTX*, CallbackIOSend);
443 WOLFSSL_API void wolfSSL_SSLSetIORecv(WOLFSSL*, CallbackIORecv);
444 WOLFSSL_API void wolfSSL_SSLSetIOSend(WOLFSSL*, CallbackIOSend);
445 /* deprecated old name */
446 #define wolfSSL_SetIORecv wolfSSL_CTX_SetIORecv
447 #define wolfSSL_SetIOSend wolfSSL_CTX_SetIOSend
448 
449 WOLFSSL_API void wolfSSL_SetIOReadCtx( WOLFSSL* ssl, void *ctx);
450 WOLFSSL_API void wolfSSL_SetIOWriteCtx(WOLFSSL* ssl, void *ctx);
451 
452 WOLFSSL_API void* wolfSSL_GetIOReadCtx( WOLFSSL* ssl);
453 WOLFSSL_API void* wolfSSL_GetIOWriteCtx(WOLFSSL* ssl);
454 
455 WOLFSSL_API void wolfSSL_SetIOReadFlags( WOLFSSL* ssl, int flags);
456 WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
457 
458 
459 #ifdef HAVE_NETX
460  WOLFSSL_LOCAL int NetX_Receive(WOLFSSL *ssl, char *buf, int sz, void *ctx);
461  WOLFSSL_LOCAL int NetX_Send(WOLFSSL *ssl, char *buf, int sz, void *ctx);
462 
463  WOLFSSL_API void wolfSSL_SetIO_NetX(WOLFSSL* ssl, NX_TCP_SOCKET* nxsocket,
464  ULONG waitoption);
465 #endif /* HAVE_NETX */
466 
467 #ifdef MICRIUM
468  WOLFSSL_LOCAL int MicriumSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
469  WOLFSSL_LOCAL int MicriumReceive(WOLFSSL* ssl, char* buf, int sz,
470  void* ctx);
471  WOLFSSL_LOCAL int MicriumReceiveFrom(WOLFSSL* ssl, char* buf, int sz,
472  void* ctx);
473  WOLFSSL_LOCAL int MicriumSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
474 #endif /* MICRIUM */
475 
476 #if defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
477  WOLFSSL_LOCAL int Mynewt_Receive(WOLFSSL *ssl, char *buf, int sz, void *ctx);
478  WOLFSSL_LOCAL int Mynewt_Send(WOLFSSL* ssl, char *buf, int sz, void *ctx);
479  WOLFSSL_API void wolfSSL_SetIO_Mynewt(WOLFSSL* ssl, struct mn_socket* mnSocket,
480  struct mn_sockaddr_in* mnSockAddrIn);
481 #endif /* defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) */
482 
483 #ifdef WOLFSSL_UIP
484 
487  struct tcp_socket tcp;
488  struct udp_socket udp;
489  } conn;
490  WOLFSSL_CTX *ctx;
491  WOLFSSL *ssl;
492  uint8_t *input_databuf;
493  uint8_t *output_databuf;
494  uint8_t *ssl_rx_databuf;
495  int ssl_rb_len;
496  int ssl_rb_off;
497  struct process *process;
498  tcp_socket_data_callback_t input_callback;
499  tcp_socket_event_callback_t event_callback;
500  int closing;
501  uip_ipaddr_t peer_addr;
502  uint16_t peer_port;
503  };
504 
505  typedef struct uip_wolfssl_ctx uip_wolfssl_ctx;
506 
507  WOLFSSL_LOCAL int uIPSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
508  WOLFSSL_LOCAL int uIPReceive(WOLFSSL* ssl, char* buf, int sz,
509  void* ctx);
510  WOLFSSL_LOCAL int uIPReceiveFrom(WOLFSSL* ssl, char* buf, int sz,
511  void* ctx);
512  WOLFSSL_LOCAL int uIPSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
513 
514 #endif
515 
516 #ifdef WOLFSSL_GNRC
517  #include <sock_types.h>
518  #include <net/gnrc.h>
519  #include <net/af.h>
520  #include <net/sock.h>
521  #include <net/gnrc/tcp.h>
522  #include <net/gnrc/udp.h>
523 
526  #ifdef MODULE_SOCK_TCP
527  sock_tcp_t tcp;
528  #endif
529  sock_udp_t udp;
530  } conn;
531  WOLFSSL_CTX *ctx;
532  WOLFSSL *ssl;
533 
534  int closing;
535  struct _sock_tl_ep peer_addr;
536  };
537 
538  typedef struct gnrc_wolfssl_ctx sock_tls_t;
539 
540  WOLFSSL_LOCAL int GNRC_ReceiveFrom(WOLFSSL* ssl, char* buf, int sz,
541  void* ctx);
542  WOLFSSL_LOCAL int GNRC_SendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
543 
544 #endif
545 
546 
547 #ifdef WOLFSSL_DTLS
548  typedef int (*CallbackGenCookie)(WOLFSSL* ssl, unsigned char* buf, int sz,
549  void* ctx);
550  WOLFSSL_API void wolfSSL_CTX_SetGenCookie(WOLFSSL_CTX*, CallbackGenCookie);
551  WOLFSSL_API void wolfSSL_SetCookieCtx(WOLFSSL* ssl, void *ctx);
552  WOLFSSL_API void* wolfSSL_GetCookieCtx(WOLFSSL* ssl);
553 
554  #ifdef WOLFSSL_SESSION_EXPORT
555  typedef int (*CallbackGetPeer)(WOLFSSL* ssl, char* ip, int* ipSz,
556  unsigned short* port, int* fam);
557  typedef int (*CallbackSetPeer)(WOLFSSL* ssl, char* ip, int ipSz,
558  unsigned short port, int fam);
559 
560  WOLFSSL_API void wolfSSL_CTX_SetIOGetPeer(WOLFSSL_CTX*, CallbackGetPeer);
561  WOLFSSL_API void wolfSSL_CTX_SetIOSetPeer(WOLFSSL_CTX*, CallbackSetPeer);
562  #endif /* WOLFSSL_SESSION_EXPORT */
563 #endif
564 
565 
566 
567 #ifndef XINET_NTOP
568  #define XINET_NTOP(a,b,c,d) inet_ntop((a),(b),(c),(d))
569  #ifdef USE_WINDOWS_API /* Windows-friendly definition */
570  #undef XINET_NTOP
571  #define XINET_NTOP(a,b,c,d) InetNtop((a),(b),(c),(d))
572  #endif
573 #endif
574 #ifndef XINET_PTON
575  #define XINET_PTON(a,b,c) inet_pton((a),(b),(c))
576  #ifdef USE_WINDOWS_API /* Windows-friendly definition */
577  #undef XINET_PTON
578  #define XINET_PTON(a,b,c) InetPton((a),(b),(c))
579  #endif
580 #endif
581 #ifndef XHTONS
582  #define XHTONS(a) htons((a))
583 #endif
584 #ifndef XNTOHS
585  #define XNTOHS(a) ntohs((a))
586 #endif
587 
588 #ifndef WOLFSSL_IP4
589  #define WOLFSSL_IP4 AF_INET
590 #endif
591 #ifndef WOLFSSL_IP6
592  #define WOLFSSL_IP6 AF_INET6
593 #endif
594 
595 
596 #ifdef __cplusplus
597  } /* extern "C" */
598 #endif
599 
600 #endif /* WOLFSSL_IO_H */
WOLFSSL_API void wolfSSL_CTX_SetGenCookie(WOLFSSL_CTX *, CallbackGenCookie)
This function sets the callback for the CBIOCookie member of the WOLFSSL_CTX structure. The CallbackGenCookie type is a function pointer and has the signature: int (CallbackGenCookie)(WOLFSSL ssl, unsigned char* buf, int sz, void* ctx);.
Definition: wolfio.c:1617
WOLFSSL_API int EmbedReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx)
This function is the receive embedded callback.
Definition: wolfio.c:215
WOLFSSL_API void wolfSSL_SetIOWriteCtx(WOLFSSL *ssl, void *ctx)
This function registers a context for the SSL session’s send callback function. By default...
Definition: wolfio.c:1576
WOLFSSL_API void * wolfSSL_GetIOReadCtx(WOLFSSL *ssl)
This function returns the IOCB_ReadCtx member of the WOLFSSL struct.
Definition: wolfio.c:1583
Definition: internal.h:1924
Definition: test.h:83
WOLFSSL_API int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *)
This function is the receive embedded callback.
Definition: wolfio.c:309
WOLFSSL_API void wolfSSL_SetIO_NetX(WOLFSSL *ssl, NX_TCP_SOCKET *nxsocket, ULONG waitoption)
This function sets the nxSocket and nxWait members of the nxCtx struct within the WOLFSSL structure...
Definition: wolfio.c:1760
Definition: wolfio.h:525
WOLFSSL_API int EmbedGenerateCookie(WOLFSSL *ssl, unsigned char *buf, int sz, void *)
This function is the DTLS Generate Cookie callback.
Definition: wolfio.c:493
Definition: internal.h:2595
WOLFSSL_API void wolfSSL_CTX_SetIORecv(WOLFSSL_CTX *, CallbackIORecv)
This function registers a receive callback for wolfSSL to get input data. By default, wolfSSL uses EmbedReceive() as the callback which uses the system’s TCP recv() function. The user can register a function to get input from memory, some other network module, or from anywhere. Please see the EmbedReceive() function in src/io.c as a guide for how the function should work and for error codes. In particular, IO_ERR_WANT_READ should be returned for non blocking receive when no data is ready.
Definition: wolfio.c:1523
Definition: wolfio.h:524
WOLFSSL_API int EmbedSend(WOLFSSL *ssl, char *buf, int sz, void *ctx)
This function is the send embedded callback.
Definition: wolfio.c:257
Definition: wolfio.h:486
WOLFSSL_API void wolfSSL_SetIOReadFlags(WOLFSSL *ssl, int flags)
This function sets the flags for the receive callback to use for the given SSL session. The receive callback could be either the default wolfSSL EmbedReceive callback, or a custom callback specified by the user (see wolfSSL_CTX_SetIORecv). The default flag value is set internally by wolfSSL to the value of 0. The default wolfSSL receive callback uses the recv() function to receive data from the socket. From the recv() man page: “The flags argument to a recv() function is formed by or&#39;ing one or more of the values: MSG_OOB process out-of-band data, MSG_PEEK peek at incoming message, MSG_WAITALL wait for full request or error. The MSG_OOB flag requests receipt of out-of-band data that would not be received in the normal data stream. Some protocols place expedited data at the head of the normal data queue, and thus this flag cannot be used with such protocols. The MSG_PEEK flag causes the receive operation to return data from the beginning of the receive queue without removing that data from the queue. Thus, a subsequent receive call will return the same data. The MSG_WAITALL flag requests that the operation block until the full request is satisfied. However, the call may still return less data than requested if a signal is caught, an error or disconnect occurs, or the next data to be received is of a different type than that returned.”
Definition: wolfio.c:1601
WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL *ssl, int flags)
This function sets the flags for the send callback to use for the given SSL session. The send callback could be either the default wolfSSL EmbedSend callback, or a custom callback specified by the user (see wolfSSL_CTX_SetIOSend). The default flag value is set internally by wolfSSL to the value of 0. The default wolfSSL send callback uses the send() function to send data from the socket. From the send() man page: “The flags parameter may include one or more of the following: #define MSG_OOB 0x1 // process out-of-band data, #define MSG_DONTROUTE 0x4 // bypass routing, use direct interface. The flag MSG_OOB is used to send `‘out-of-band’&#39; data on sockets that support this notion (e.g. SOCK_STREAM); the underlying protocol must also support `‘out-of-band’&#39; data. MSG_DONTROUTE is usually used only by diagnostic or routing programs.”
Definition: wolfio.c:1608
Definition: wolfio.h:485
WOLFSSL_API void * wolfSSL_GetCookieCtx(WOLFSSL *ssl)
This function returns the IOCB_CookieCtx member of the WOLFSSL structure.
Definition: wolfio.c:1631
WOLFSSL_API int EmbedSendTo(WOLFSSL *ssl, char *buf, int sz, void *ctx)
This function is the send embedded callback.
Definition: wolfio.c:390
WOLFSSL_API void EmbedOcspRespFree(void *, unsigned char *)
This function frees the response buffer.
Definition: wolfio.c:1418
WOLFSSL_API void * wolfSSL_GetIOWriteCtx(WOLFSSL *ssl)
This function returns the IOCB_WriteCtx member of the WOLFSSL structure.
Definition: wolfio.c:1592
WOLFSSL_API void wolfSSL_SetIOReadCtx(WOLFSSL *ssl, void *ctx)
This function registers a context for the SSL session’s receive callback function. By default, wolfSSL sets the file descriptor passed to wolfSSL_set_fd() as the context when wolfSSL is using the system’s TCP library. If you’ve registered your own receive callback you may want to set a specific context for the session. For example, if you’re using memory buffers the context may be a pointer to a structure describing where and how to access the memory buffers.
Definition: wolfio.c:1569
Definition: internal.h:3849