source: asp3_tinet_ecnl_arm/trunk/wolfssl-3.12.2/wolfssl/wolfio.h@ 352

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

arm向けASP3版ECNLを追加

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