Changeset 464 for azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/src/wolfio.c
- Timestamp:
- Jun 22, 2021, 9:00:19 PM (3 years ago)
- Location:
- azure_iot_hub_f767zi/trunk/wolfssl-4.7.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/src/wolfio.c
r457 r464 89 89 } 90 90 91 static WC_INLINE int wolfSSL_LastError(void) 92 { 91 static WC_INLINE int wolfSSL_LastError(int err) 92 { 93 (void)err; /* Suppress unused arg */ 94 93 95 #ifdef USE_WINDOWS_API 94 96 return WSAGetLastError(); 95 97 #elif defined(EBSNET) 96 98 return xn_getlasterror(); 99 #elif defined(WOLFSSL_LINUXKM) 100 return err; /* Return provided error value */ 101 #elif defined(FUSION_RTOS) 102 #include <fclerrno.h> 103 return FCL_GET_ERRNO; 97 104 #else 98 105 return errno; … … 104 111 105 112 #ifdef OPENSSL_EXTRA 113 #ifndef NO_BIO 106 114 /* Use the WOLFSSL read BIO for receiving data. This is set by the function 107 115 * wolfSSL_set_bio and can also be set by wolfSSL_CTX_SetIORecv. … … 182 190 WOLFSSL_MSG("Calling custom biowr"); 183 191 sent = ssl->biowr->method->writeCb(ssl->biowr, buf, sz); 184 if ( sent < 0) {192 if ((sent < 0) && (sent != WOLFSSL_CBIO_ERR_WANT_WRITE)) { 185 193 return WOLFSSL_CBIO_ERR_GENERAL; 186 194 } … … 205 213 return sent; 206 214 } 207 #endif 215 #endif /* !NO_BIO */ 216 #endif /* OPENSSL_EXTRA */ 208 217 209 218 … … 215 224 int EmbedReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx) 216 225 { 226 int recvd; 227 #ifndef WOLFSSL_LINUXKM 217 228 int sd = *(int*)ctx; 218 int recvd; 229 #else 230 struct socket *sd = (struct socket*)ctx; 231 #endif 219 232 220 233 recvd = wolfIO_Recv(sd, buf, sz, ssl->rflags); 221 234 if (recvd < 0) { 222 int err = wolfSSL_LastError( );235 int err = wolfSSL_LastError(recvd); 223 236 WOLFSSL_MSG("Embed Receive error"); 224 237 … … 257 270 int EmbedSend(WOLFSSL* ssl, char *buf, int sz, void *ctx) 258 271 { 272 int sent; 273 #ifndef WOLFSSL_LINUXKM 259 274 int sd = *(int*)ctx; 260 int sent; 275 #else 276 struct socket *sd = (struct socket*)ctx; 277 #endif 261 278 262 279 #ifdef WOLFSSL_MAX_SEND_SZ … … 267 284 sent = wolfIO_Send(sd, buf, sz, ssl->wflags); 268 285 if (sent < 0) { 269 int err = wolfSSL_LastError( );286 int err = wolfSSL_LastError(sent); 270 287 WOLFSSL_MSG("Embed Send error"); 271 288 … … 319 336 WOLFSSL_ENTER("EmbedReceiveFrom()"); 320 337 321 if (ssl->options.handShakeDone) 338 /* Don't use ssl->options.handShakeDone since it is true even if 339 * we are in the process of renegotiation */ 340 if (ssl->options.handShakeState == HANDSHAKE_DONE) 322 341 dtls_timeout = 0; 323 342 … … 335 354 } 336 355 } 356 #ifndef NO_ASN_TIME 357 else if(IsSCR(ssl)) { 358 if (ssl->dtls_start_timeout && 359 LowResTimer() - ssl->dtls_start_timeout > (word32)dtls_timeout) { 360 ssl->dtls_start_timeout = 0; 361 return WOLFSSL_CBIO_ERR_TIMEOUT; 362 } 363 else if (!ssl->dtls_start_timeout) { 364 ssl->dtls_start_timeout = LowResTimer(); 365 } 366 } 367 #endif /* !NO_ASN_TIME */ 337 368 338 369 recvd = (int)RECVFROM_FUNCTION(sd, buf, sz, ssl->rflags, … … 342 373 343 374 if (recvd < 0) { 344 err = wolfSSL_LastError( );375 err = wolfSSL_LastError(recvd); 345 376 WOLFSSL_MSG("Embed Receive From error"); 346 377 … … 380 411 } 381 412 } 413 #ifndef NO_ASN_TIME 414 ssl->dtls_start_timeout = 0; 415 #endif /* !NO_ASN_TIME */ 382 416 383 417 return recvd; … … 404 438 405 439 if (sent < 0) { 406 err = wolfSSL_LastError( );440 err = wolfSSL_LastError(sent); 407 441 WOLFSSL_MSG("Embed Send To error"); 408 442 … … 452 486 453 487 if (recvd < 0) { 454 err = wolfSSL_LastError( );488 err = wolfSSL_LastError(recvd); 455 489 WOLFSSL_MSG("Embed Receive From error"); 456 490 … … 636 670 #endif /* WOLFSSL_SESSION_EXPORT */ 637 671 #endif /* WOLFSSL_DTLS */ 672 673 #ifdef WOLFSSL_LINUXKM 674 static int linuxkm_send(struct socket *socket, void *buf, int size, 675 unsigned int flags) 676 { 677 int ret; 678 struct kvec vec = { .iov_base = buf, .iov_len = size }; 679 struct msghdr msg = { .msg_flags = flags }; 680 ret = kernel_sendmsg(socket, &msg, &vec, 1, size); 681 return ret; 682 } 683 684 static int linuxkm_recv(struct socket *socket, void *buf, int size, 685 unsigned int flags) 686 { 687 int ret; 688 struct kvec vec = { .iov_base = buf, .iov_len = size }; 689 struct msghdr msg = { .msg_flags = flags }; 690 ret = kernel_recvmsg(socket, &msg, &vec, 1, size, msg.msg_flags); 691 return ret; 692 } 693 #endif /* WOLFSSL_LINUXKM */ 638 694 639 695 … … 733 789 } 734 790 } 791 792 WOLFSSL_MSG("Select error"); 735 793 return SOCKET_ERROR_E; 736 794 } … … 780 838 #endif 781 839 840 if (sockfd == NULL || ip == NULL) { 841 return -1; 842 } 843 782 844 XMEMSET(&addr, 0, sizeof(addr)); 783 845 … … 822 884 823 885 *sockfd = (SOCKET_T)socket(addr.ss_family, SOCK_STREAM, 0); 824 825 886 #ifdef USE_WINDOWS_API 826 if (*sockfd == INVALID_SOCKET) { 887 if (*sockfd == SOCKET_INVALID) 888 #else 889 if (*sockfd <= SOCKET_INVALID) 890 #endif 891 { 827 892 WOLFSSL_MSG("bad socket fd, out of fds?"); 828 893 return -1; 829 894 } 830 #else831 if (*sockfd < 0) {832 WOLFSSL_MSG("bad socket fd, out of fds?");833 return -1;834 }835 #endif836 895 837 896 #ifdef HAVE_IO_TIMEOUT … … 858 917 if (ret != 0) { 859 918 WOLFSSL_MSG("Responder tcp connect failed"); 919 CloseSocket(*sockfd); 920 *sockfd = SOCKET_INVALID; 860 921 return -1; 861 922 } … … 1074 1135 } 1075 1136 else { 1137 result = TranslateReturnCode(result, sfd); 1138 result = wolfSSL_LastError(result); 1139 if (result == SOCKET_EWOULDBLOCK || result == SOCKET_EAGAIN) { 1140 return OCSP_WANT_READ; 1141 } 1142 1076 1143 WOLFSSL_MSG("wolfIO_HttpProcessResponse recv http from peer failed"); 1077 1144 return -1; … … 1339 1406 byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf) 1340 1407 { 1341 SOCKET_T sfd = 0;1408 SOCKET_T sfd = SOCKET_INVALID; 1342 1409 word16 port; 1343 1410 int ret = -1; … … 1386 1453 1387 1454 ret = wolfIO_TcpConnect(&sfd, domainName, port, io_timeout_sec); 1388 if ( (ret != 0) || ((int)sfd < 0)) {1455 if (ret != 0) { 1389 1456 WOLFSSL_MSG("OCSP Responder connection failed"); 1390 1457 } … … 1401 1468 HTTP_SCRATCH_BUFFER_SIZE, ctx); 1402 1469 } 1403 1404 CloseSocket(sfd);1470 if (sfd != SOCKET_INVALID) 1471 CloseSocket(sfd); 1405 1472 XFREE(httpBuf, ctx, DYNAMIC_TYPE_OCSP); 1406 1473 } … … 1460 1527 int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz) 1461 1528 { 1462 SOCKET_T sfd = 0;1529 SOCKET_T sfd = SOCKET_INVALID; 1463 1530 word16 port; 1464 1531 int ret = -1; … … 1492 1559 1493 1560 ret = wolfIO_TcpConnect(&sfd, domainName, port, io_timeout_sec); 1494 if ( (ret != 0) || (sfd < 0)) {1561 if (ret != 0) { 1495 1562 WOLFSSL_MSG("CRL connection failed"); 1496 1563 } … … 1503 1570 HTTP_SCRATCH_BUFFER_SIZE); 1504 1571 } 1505 1506 CloseSocket(sfd);1572 if (sfd != SOCKET_INVALID) 1573 CloseSocket(sfd); 1507 1574 XFREE(httpBuf, crl->heap, DYNAMIC_TYPE_CRL); 1508 1575 } … … 2031 2098 2032 2099 XMEMSET(mynewt_ctx, 0, sizeof(Mynewt_Ctx)); 2033 mynewt_ctx->mnMemBuffer = XMALLOC(mempool_bytes, 0, 0);2100 mynewt_ctx->mnMemBuffer = (void *)XMALLOC(mempool_bytes, 0, 0); 2034 2101 if(!mynewt_ctx->mnMemBuffer) { 2035 2102 mynewt_ctx_clear((void*)mynewt_ctx); … … 2082 2149 struct os_mbuf *m; 2083 2150 int read_sz = 0; 2084 uint16_ttotal;2151 word16 total; 2085 2152 2086 2153 if (mynewt_ctx == NULL || mynewt_ctx->mnSocket == NULL) { … … 2325 2392 sock_udp_ep_t ep; 2326 2393 int ret; 2327 uint32_ttimeout = wolfSSL_dtls_get_current_timeout(ssl) * 1000000;2394 word32 timeout = wolfSSL_dtls_get_current_timeout(ssl) * 1000000; 2328 2395 sock_tls_t *ctx = (sock_tls_t *)_ctx; 2329 2396 if (!ctx)
Note:
See TracChangeset
for help on using the changeset viewer.