From 3b722bf66208d234a4326a5fbc55e64d4fd2c0a4 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Mon, 8 Apr 2019 13:22:36 -0600 Subject: [PATCH] maintain Nucleus port --- src/port.c | 2 +- src/wolfsftp.c | 6 +++-- wolfssh/port.h | 4 ++-- wolfssh/test.h | 64 +++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/src/port.c b/src/port.c index f6de2ca..c698b70 100644 --- a/src/port.c +++ b/src/port.c @@ -85,7 +85,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode) #if (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) && \ !defined(NO_WOLFSSH_SERVER) - #if defined(USE_WINDOWS_API) + #if defined(USE_WINDOWS_API) || defined(WOLFSSL_NUCLEUS) /* This is current inline in the source. */ diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 83029ae..f3ee822 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -3380,7 +3380,8 @@ int SFTP_GetAttributes(const char* fileName, WS_SFTP_FILEATRB* atr, byte link, } atr->flags |= WOLFSSH_FILEATRB_SIZE; - atr->sz = (word64)stats.fsize; + atr->sz[0] = (word32)(stats.fsize); + atr->sz[1] = (word32)(0); /* get additional attributes */ { @@ -3443,7 +3444,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz, WMEMSET(atr, 0, sizeof(WS_SFTP_FILEATRB)); atr->flags |= WOLFSSH_FILEATRB_SIZE; - atr->sz = (word64)stats.fsize; + atr->sz[0] = (word32)(stats.fsize); + atr->sz[1] = (word32)(0); { byte atrib = stats.fattribute; diff --git a/wolfssh/port.h b/wolfssh/port.h index 7358c8f..7998c29 100644 --- a/wolfssh/port.h +++ b/wolfssh/port.h @@ -349,7 +349,7 @@ extern "C" { static inline int wPwrite(WFD fd, unsigned char* buf, unsigned int sz, const unsigned int* shortOffset) { - long ofst = ((long)shortOffset[1] << 32) | shortOffset[0]; + INT32 ofst = shortOffset[0]; if (ofst > 0) { NU_Seek(fd, ofst, 0); } @@ -363,7 +363,7 @@ extern "C" { static inline int wPread(WFD fd, unsigned char* buf, unsigned int sz, const unsigned int* shortOffset) { - long ofst = ((long)shortOffset[1] << 32) | shortOffset[0]; + INT32 ofst = shortOffset[0]; if (ofst > 0) { NU_Seek(fd, ofst, 0); } diff --git a/wolfssh/test.h b/wolfssh/test.h index a128d54..97853d0 100644 --- a/wolfssh/test.h +++ b/wolfssh/test.h @@ -1,4 +1,22 @@ -/* test.h */ +/* test.h + * + * Copyright (C) 2014-2019 wolfSSL Inc. + * + * This file is part of wolfSSH. + * + * wolfSSH is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with wolfSSH. If not, see . + */ #pragma once @@ -572,26 +590,54 @@ enum { WS_SELECT_ERROR_READY }; +#ifdef WOLFSSL_NUCLEUS + #define WFD_SET_TYPE FD_SET + #define WFD_SET NU_FD_Set + #define WFD_ZERO NU_FD_Init + #define WFD_ISSET NU_FD_Check +#else + #define WFD_SET_TYPE fd_set + #define WFD_SET FD_SET + #define WFD_ZERO FD_ZERO + #define WFD_ISSET FD_ISSET +#endif + +/* returns 1 or greater when something is ready to be read */ +static INLINE int wSelect(int nfds, WFD_SET_TYPE* recvfds, + WFD_SET_TYPE *writefds, WFD_SET_TYPE *errfds, struct timeval* timeout) +{ +#ifdef WOLFSSL_NUCLEUS + int ret = NU_Select (nfds, recvfds, writefds, errfds, + (UNSIGNED)timeout->tv_sec); + if (ret == NU_SUCCESS) { + return 1; + } + return 0; +#else + return select(nfds, recvfds, writefds, errfds, timeout); +#endif +} + static INLINE int tcp_select(SOCKET_T socketfd, int to_sec) { - fd_set recvfds, errfds; + WFD_SET_TYPE recvfds, errfds; int nfds = (int)socketfd + 1; struct timeval timeout = {(to_sec > 0) ? to_sec : 0, 0}; int result; - FD_ZERO(&recvfds); - FD_SET(socketfd, &recvfds); - FD_ZERO(&errfds); - FD_SET(socketfd, &errfds); + WFD_ZERO(&recvfds); + WFD_SET(socketfd, &recvfds); + WFD_ZERO(&errfds); + WFD_SET(socketfd, &errfds); - result = select(nfds, &recvfds, NULL, &errfds, &timeout); + result = wSelect(nfds, &recvfds, NULL, &errfds, &timeout); if (result == 0) return WS_SELECT_TIMEOUT; else if (result > 0) { - if (FD_ISSET(socketfd, &recvfds)) + if (WFD_ISSET(socketfd, &recvfds)) return WS_SELECT_RECV_READY; - else if(FD_ISSET(socketfd, &errfds)) + else if(WFD_ISSET(socketfd, &errfds)) return WS_SELECT_ERROR_READY; }