source: asp3_tinet_ecnl_rx/trunk/wolfssl-3.12.2/wolfssl/io.h@ 337

Last change on this file since 337 was 337, checked in by coas-nagasima, 6 years ago

ASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 14.1 KB
Line 
1/* io.h
2 *
3 * Copyright (C) 2006-2016 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#ifndef WOLFSSL_IO_H
24#define WOLFSSL_IO_H
25
26#ifdef __cplusplus
27 extern "C" {
28#endif
29
30/* OCSP and CRL_IO require HTTP client */
31#if defined(HAVE_OCSP) || defined(HAVE_CRL_IO)
32 #ifndef HAVE_HTTP_CLIENT
33 #define HAVE_HTTP_CLIENT
34 #endif
35#endif
36
37#if !defined(WOLFSSL_USER_IO)
38 #ifndef USE_WOLFSSL_IO
39 #define USE_WOLFSSL_IO
40 #endif
41#endif
42
43
44#if defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT)
45
46#ifdef HAVE_LIBZ
47 #include "zlib.h"
48#endif
49
50#ifndef USE_WINDOWS_API
51 #ifdef WOLFSSL_LWIP
52 /* lwIP needs to be configured to use sockets API in this mode */
53 /* LWIP_SOCKET 1 in lwip/opt.h or in build */
54 #include "lwip/sockets.h"
55 #include <errno.h>
56 #ifndef LWIP_PROVIDE_ERRNO
57 #define LWIP_PROVIDE_ERRNO 1
58 #endif
59 #elif defined(FREESCALE_MQX)
60 #include <posix.h>
61 #include <rtcs.h>
62 #elif defined(FREESCALE_KSDK_MQX)
63 #include <rtcs.h>
64 #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
65 #if !defined(WOLFSSL_MDK_ARM)
66 #include "cmsis_os.h"
67 #include "rl_net.h"
68 #else
69 #include <rtl.h>
70 #endif
71 #include "errno.h"
72 #define SOCKET_T int
73 #elif defined(WOLFSSL_TIRTOS)
74 #include <sys/socket.h>
75 #elif defined(FREERTOS_TCP)
76 #include "FreeRTOS_Sockets.h"
77 #elif defined(WOLFSSL_IAR_ARM)
78 /* nothing */
79 #elif defined(WOLFSSL_VXWORKS)
80 #include <sockLib.h>
81 #include <errno.h>
82 #elif defined(WOLFSSL_ATMEL)
83 #include "socket/include/socket.h"
84 #elif defined(INTIME_RTOS)
85 #undef MIN
86 #undef MAX
87 #include <rt.h>
88 #include <sys/types.h>
89 #include <sys/socket.h>
90 #include <netdb.h>
91 #include <netinet/in.h>
92 #include <io.h>
93 /* <sys/socket.h> defines these, to avoid conflict, do undef */
94 #undef SOCKADDR
95 #undef SOCKADDR_IN
96 #elif defined(WOLFSSL_PRCONNECT_PRO)
97 #include <prconnect_pro/prconnect_pro.h>
98 #include <sys/types.h>
99 #include <errno.h>
100 #include <unistd.h>
101 #include <fcntl.h>
102 #include <netdb.h>
103 #include <sys/ioctl.h>
104 #elif !defined(WOLFSSL_NO_SOCK)
105 #include <sys/types.h>
106 #include <errno.h>
107 #ifndef EBSNET
108 #include <unistd.h>
109 #endif
110 #include <fcntl.h>
111
112 #if defined(HAVE_RTP_SYS)
113 #include <socket.h>
114 #elif defined(EBSNET)
115 #include "rtipapi.h" /* errno */
116 #include "socket.h"
117 #elif !defined(DEVKITPRO) && !defined(WOLFSSL_PICOTCP)
118 #include <sys/socket.h>
119 #include <arpa/inet.h>
120 #include <netinet/in.h>
121 #include <netdb.h>
122 #ifdef __PPU
123 #include <netex/errno.h>
124 #else
125 #include <sys/ioctl.h>
126 #endif
127 #endif
128 #endif
129#endif /* USE_WINDOWS_API */
130
131#ifdef __sun
132 #include <sys/filio.h>
133#endif
134
135#ifdef USE_WINDOWS_API
136 /* no epipe yet */
137 #ifndef WSAEPIPE
138 #define WSAEPIPE -12345
139 #endif
140 #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
141 #define SOCKET_EAGAIN WSAETIMEDOUT
142 #define SOCKET_ECONNRESET WSAECONNRESET
143 #define SOCKET_EINTR WSAEINTR
144 #define SOCKET_EPIPE WSAEPIPE
145 #define SOCKET_ECONNREFUSED WSAENOTCONN
146 #define SOCKET_ECONNABORTED WSAECONNABORTED
147 #define close(s) closesocket(s)
148#elif defined(__PPU)
149 #define SOCKET_EWOULDBLOCK SYS_NET_EWOULDBLOCK
150 #define SOCKET_EAGAIN SYS_NET_EAGAIN
151 #define SOCKET_ECONNRESET SYS_NET_ECONNRESET
152 #define SOCKET_EINTR SYS_NET_EINTR
153 #define SOCKET_EPIPE SYS_NET_EPIPE
154 #define SOCKET_ECONNREFUSED SYS_NET_ECONNREFUSED
155 #define SOCKET_ECONNABORTED SYS_NET_ECONNABORTED
156#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
157 #if MQX_USE_IO_OLD
158 /* RTCS old I/O doesn't have an EWOULDBLOCK */
159 #define SOCKET_EWOULDBLOCK EAGAIN
160 #define SOCKET_EAGAIN EAGAIN
161 #define SOCKET_ECONNRESET RTCSERR_TCP_CONN_RESET
162 #define SOCKET_EINTR EINTR
163 #define SOCKET_EPIPE EPIPE
164 #define SOCKET_ECONNREFUSED RTCSERR_TCP_CONN_REFUSED
165 #define SOCKET_ECONNABORTED RTCSERR_TCP_CONN_ABORTED
166 #else
167 #define SOCKET_EWOULDBLOCK NIO_EWOULDBLOCK
168 #define SOCKET_EAGAIN NIO_EAGAIN
169 #define SOCKET_ECONNRESET NIO_ECONNRESET
170 #define SOCKET_EINTR NIO_EINTR
171 #define SOCKET_EPIPE NIO_EPIPE
172 #define SOCKET_ECONNREFUSED NIO_ECONNREFUSED
173 #define SOCKET_ECONNABORTED NIO_ECONNABORTED
174 #endif
175#elif defined(WOLFSSL_MDK_ARM)|| defined(WOLFSSL_KEIL_TCP_NET)
176 #if !defined(WOLFSSL_MDK_ARM)
177 #define SOCKET_EWOULDBLOCK BSD_ERROR_WOULDBLOCK
178 #define SOCKET_EAGAIN BSD_ERROR_LOCKED
179 #define SOCKET_ECONNRESET BSD_ERROR_CLOSED
180 #define SOCKET_EINTR BSD_ERROR
181 #define SOCKET_EPIPE BSD_ERROR
182 #define SOCKET_ECONNREFUSED BSD_ERROR
183 #define SOCKET_ECONNABORTED BSD_ERROR
184 #else
185 #define SOCKET_EWOULDBLOCK SCK_EWOULDBLOCK
186 #define SOCKET_EAGAIN SCK_ELOCKED
187 #define SOCKET_ECONNRESET SCK_ECLOSED
188 #define SOCKET_EINTR SCK_ERROR
189 #define SOCKET_EPIPE SCK_ERROR
190 #define SOCKET_ECONNREFUSED SCK_ERROR
191 #define SOCKET_ECONNABORTED SCK_ERROR
192 #endif
193#elif defined(WOLFSSL_PICOTCP)
194 #define SOCKET_EWOULDBLOCK PICO_ERR_EAGAIN
195 #define SOCKET_EAGAIN PICO_ERR_EAGAIN
196 #define SOCKET_ECONNRESET PICO_ERR_ECONNRESET
197 #define SOCKET_EINTR PICO_ERR_EINTR
198 #define SOCKET_EPIPE PICO_ERR_EIO
199 #define SOCKET_ECONNREFUSED PICO_ERR_ECONNREFUSED
200 #define SOCKET_ECONNABORTED PICO_ERR_ESHUTDOWN
201#elif defined(FREERTOS_TCP)
202 #define SOCKET_EWOULDBLOCK FREERTOS_EWOULDBLOCK
203 #define SOCKET_EAGAIN FREERTOS_EWOULDBLOCK
204 #define SOCKET_ECONNRESET FREERTOS_SOCKET_ERROR
205 #define SOCKET_EINTR FREERTOS_SOCKET_ERROR
206 #define SOCKET_EPIPE FREERTOS_SOCKET_ERROR
207 #define SOCKET_ECONNREFUSED FREERTOS_SOCKET_ERROR
208 #define SOCKET_ECONNABORTED FREERTOS_SOCKET_ERROR
209#else
210 #define SOCKET_EWOULDBLOCK EWOULDBLOCK
211 #define SOCKET_EAGAIN EAGAIN
212 #define SOCKET_ECONNRESET ECONNRESET
213 #define SOCKET_EINTR EINTR
214 #define SOCKET_EPIPE EPIPE
215 #define SOCKET_ECONNREFUSED ECONNREFUSED
216 #define SOCKET_ECONNABORTED ECONNABORTED
217#endif /* USE_WINDOWS_API */
218
219
220#ifdef DEVKITPRO
221 /* from network.h */
222 int net_send(int, const void*, int, unsigned int);
223 int net_recv(int, void*, int, unsigned int);
224 #define SEND_FUNCTION net_send
225 #define RECV_FUNCTION net_recv
226#elif defined(WOLFSSL_LWIP)
227 #define SEND_FUNCTION lwip_send
228 #define RECV_FUNCTION lwip_recv
229#elif defined(WOLFSSL_PICOTCP)
230 #define SEND_FUNCTION pico_send
231 #define RECV_FUNCTION pico_recv
232#elif defined(FREERTOS_TCP)
233 #define RECV_FUNCTION(a,b,c,d) FreeRTOS_recv((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d))
234 #define SEND_FUNCTION(a,b,c,d) FreeRTOS_send((Socket_t)(a),(void*)(b), (size_t)(c), (BaseType_t)(d))
235#else
236 #define SEND_FUNCTION send
237 #define RECV_FUNCTION recv
238 #if !defined(HAVE_SOCKADDR) && !defined(WOLFSSL_NO_SOCK)
239 #define HAVE_SOCKADDR
240 #endif
241#endif
242
243#ifdef USE_WINDOWS_API
244 typedef unsigned int SOCKET_T;
245#else
246 typedef int SOCKET_T;
247#endif
248
249#ifndef WOLFSSL_NO_SOCK
250 #ifndef XSOCKLENT
251 #ifdef USE_WINDOWS_API
252 #define XSOCKLENT int
253 #else
254 #define XSOCKLENT socklen_t
255 #endif
256 #endif
257
258 /* Socket Addr Support */
259 #ifdef HAVE_SOCKADDR
260 typedef struct sockaddr SOCKADDR;
261 typedef struct sockaddr_storage SOCKADDR_S;
262 typedef struct sockaddr_in SOCKADDR_IN;
263 #ifdef WOLFSSL_IPV6
264 typedef struct sockaddr_in6 SOCKADDR_IN6;
265 #endif
266 typedef struct hostent HOSTENT;
267 #endif /* HAVE_SOCKADDR */
268
269 #ifdef HAVE_GETADDRINFO
270 typedef struct addrinfo ADDRINFO;
271 #endif
272#endif /* WOLFSSL_NO_SOCK */
273
274
275/* IO API's */
276#ifdef HAVE_IO_TIMEOUT
277 WOLFSSL_API int wolfIO_SetBlockingMode(SOCKET_T sockfd, int non_blocking);
278 WOLFSSL_API void wolfIO_SetTimeout(int to_sec);;
279 WOLFSSL_API int wolfIO_Select(SOCKET_T sockfd, int to_sec);
280#endif
281WOLFSSL_API int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip,
282 unsigned short port, int to_sec);
283WOLFSSL_API int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags);
284WOLFSSL_API int wolfIO_Recv(SOCKET_T sd, char *buf, int sz, int rdFlags);
285
286#endif /* USE_WOLFSSL_IO || HAVE_HTTP_CLIENT */
287
288
289#if defined(USE_WOLFSSL_IO)
290 /* default IO callbacks */
291 WOLFSSL_API int EmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
292 WOLFSSL_API int EmbedSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
293
294 #ifdef WOLFSSL_DTLS
295 WOLFSSL_API int EmbedReceiveFrom(WOLFSSL* ssl, char* buf, int sz, void*);
296 WOLFSSL_API int EmbedSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
297 WOLFSSL_API int EmbedGenerateCookie(WOLFSSL* ssl, unsigned char* buf,
298 int sz, void*);
299 #ifdef WOLFSSL_SESSION_EXPORT
300 WOLFSSL_API int EmbedGetPeer(WOLFSSL* ssl, char* ip, int* ipSz,
301 unsigned short* port, int* fam);
302 WOLFSSL_API int EmbedSetPeer(WOLFSSL* ssl, char* ip, int ipSz,
303 unsigned short port, int fam);
304 #endif /* WOLFSSL_SESSION_EXPORT */
305 #endif /* WOLFSSL_DTLS */
306#endif /* USE_WOLFSSL_IO */
307
308#ifdef HAVE_OCSP
309 WOLFSSL_API int wolfIO_HttpBuildRequestOcsp(const char* domainName,
310 const char* path, int ocspReqSz, unsigned char* buf, int bufSize);
311 WOLFSSL_API int wolfIO_HttpProcessResponseOcsp(int sfd,
312 unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz,
313 void* heap);
314
315 WOLFSSL_API int EmbedOcspLookup(void*, const char*, int, unsigned char*,
316 int, unsigned char**);
317 WOLFSSL_API void EmbedOcspRespFree(void*, unsigned char*);
318#endif
319
320#ifdef HAVE_CRL_IO
321 WOLFSSL_API int wolfIO_HttpBuildRequestCrl(const char* url, int urlSz,
322 const char* domainName, unsigned char* buf, int bufSize);
323 WOLFSSL_API int wolfIO_HttpProcessResponseCrl(WOLFSSL_CRL* crl, int sfd,
324 unsigned char* httpBuf, int httpBufSz);
325
326 WOLFSSL_API int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url,
327 int urlSz);
328#endif
329
330
331#if defined(HAVE_HTTP_CLIENT)
332 WOLFSSL_API int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName,
333 char* outPath, unsigned short* outPort);
334
335 WOLFSSL_API int wolfIO_HttpBuildRequest(const char* reqType,
336 const char* domainName, const char* path, int pathLen, int reqSz,
337 const char* contentType, unsigned char* buf, int bufSize);
338 WOLFSSL_API int wolfIO_HttpProcessResponse(int sfd, const char* appStr,
339 unsigned char** respBuf, unsigned char* httpBuf, int httpBufSz,
340 int dynType, void* heap);
341#endif /* HAVE_HTTP_CLIENT */
342
343
344/* I/O callbacks */
345typedef int (*CallbackIORecv)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
346typedef int (*CallbackIOSend)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
347WOLFSSL_API void wolfSSL_SetIORecv(WOLFSSL_CTX*, CallbackIORecv);
348WOLFSSL_API void wolfSSL_SetIOSend(WOLFSSL_CTX*, CallbackIOSend);
349
350WOLFSSL_API void wolfSSL_SetIOReadCtx( WOLFSSL* ssl, void *ctx);
351WOLFSSL_API void wolfSSL_SetIOWriteCtx(WOLFSSL* ssl, void *ctx);
352
353WOLFSSL_API void* wolfSSL_GetIOReadCtx( WOLFSSL* ssl);
354WOLFSSL_API void* wolfSSL_GetIOWriteCtx(WOLFSSL* ssl);
355
356WOLFSSL_API void wolfSSL_SetIOReadFlags( WOLFSSL* ssl, int flags);
357WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
358
359
360#ifdef HAVE_NETX
361 WOLFSSL_LOCAL int NetX_Receive(WOLFSSL *ssl, char *buf, int sz, void *ctx);
362 WOLFSSL_LOCAL int NetX_Send(WOLFSSL *ssl, char *buf, int sz, void *ctx);
363
364 WOLFSSL_API void wolfSSL_SetIO_NetX(WOLFSSL* ssl, NX_TCP_SOCKET* nxsocket,
365 ULONG waitoption);
366#endif /* HAVE_NETX */
367
368#ifdef WOLFSSL_DTLS
369 typedef int (*CallbackGenCookie)(WOLFSSL* ssl, unsigned char* buf, int sz,
370 void* ctx);
371 WOLFSSL_API void wolfSSL_CTX_SetGenCookie(WOLFSSL_CTX*, CallbackGenCookie);
372 WOLFSSL_API void wolfSSL_SetCookieCtx(WOLFSSL* ssl, void *ctx);
373 WOLFSSL_API void* wolfSSL_GetCookieCtx(WOLFSSL* ssl);
374
375 #ifdef WOLFSSL_SESSION_EXPORT
376 typedef int (*CallbackGetPeer)(WOLFSSL* ssl, char* ip, int* ipSz,
377 unsigned short* port, int* fam);
378 typedef int (*CallbackSetPeer)(WOLFSSL* ssl, char* ip, int ipSz,
379 unsigned short port, int fam);
380
381 WOLFSSL_API void wolfSSL_CTX_SetIOGetPeer(WOLFSSL_CTX*, CallbackGetPeer);
382 WOLFSSL_API void wolfSSL_CTX_SetIOSetPeer(WOLFSSL_CTX*, CallbackSetPeer);
383 #endif /* WOLFSSL_SESSION_EXPORT */
384#endif
385
386
387
388#ifndef XINET_NTOP
389 #define XINET_NTOP(a,b,c,d) inet_ntop((a),(b),(c),(d))
390#endif
391#ifndef XINET_PTON
392 #define XINET_PTON(a,b,c) inet_pton((a),(b),(c))
393#endif
394#ifndef XHTONS
395 #define XHTONS(a) htons((a))
396#endif
397#ifndef XNTOHS
398 #define XNTOHS(a) ntohs((a))
399#endif
400
401#ifndef WOLFSSL_IP4
402 #define WOLFSSL_IP4 AF_INET
403#endif
404#ifndef WOLFSSL_IP6
405 #define WOLFSSL_IP6 AF_INET6
406#endif
407
408
409#ifdef __cplusplus
410 } /* extern "C" */
411#endif
412
413#endif /* WOLFSSL_IO_H */
Note: See TracBrowser for help on using the repository browser.