Skip to content

Commit

Permalink
Merge pull request #677 from julek-wolfssl/zephyr-nofs
Browse files Browse the repository at this point in the history
Add NO_FILESYSTEM to Zephyr port
  • Loading branch information
ejohnstown authored May 2, 2024
2 parents 4974096 + 2b23370 commit 2a139c9
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/zephyr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
zephyr-sdk: 0.16.1
runs-on: ubuntu-latest
# This should be a safe limit for the tests to run.
timeout-minutes: 15
timeout-minutes: 20
steps:
- name: Install dependencies
run: |
Expand Down Expand Up @@ -77,6 +77,8 @@ jobs:
run: |
./zephyr/scripts/twister --testsuite-root modules/lib/wolfssh --test zephyr/samples/tests/sample.lib.wolfssh_tests -vvv
rm -rf zephyr/twister-out
./zephyr/scripts/twister --testsuite-root modules/lib/wolfssh --test zephyr/samples/tests/sample.lib.wolfssh_nofs_tests -vvv
rm -rf zephyr/twister-out
- name: Zip failure logs
if: ${{ failure() && steps.wolfssh-test.outcome == 'failure' }}
Expand Down
3 changes: 2 additions & 1 deletion src/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ int WS_DeleteFileA(const char* fileName, void* heap)

#endif /* USE_WINDOWS_API WOLFSSH_SFTP WOLFSSH_SCP */

#if defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP))
#if !defined(NO_FILESYSTEM) && \
defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP))

int wssh_z_fstat(const char *p, struct fs_dirent *b)
{
Expand Down
6 changes: 4 additions & 2 deletions src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ int wolfSSH_Init(void)
#ifdef WC_RNG_SEED_CB
wc_SetSeed_Cb(wc_GenerateSeed);
#endif
#if defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP))
#if !defined(NO_FILESYSTEM) && defined(WOLFSSH_ZEPHYR) && \
(defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP))
if (wssh_z_fds_init() != 0)
ret = WS_CRYPTO_FAILED;
#endif
Expand All @@ -93,7 +94,8 @@ int wolfSSH_Cleanup(void)

if (wolfCrypt_Cleanup() != 0)
ret = WS_CRYPTO_FAILED;
#if defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP))
#if !defined(NO_FILESYSTEM) && defined(WOLFSSH_ZEPHYR) && \
(defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP))
if (wssh_z_fds_cleanup() != 0)
ret = WS_CRYPTO_FAILED;
#endif
Expand Down
9 changes: 6 additions & 3 deletions src/wolfscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2845,9 +2845,10 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath,
recvBuffer->mode = fileMode;
if (recvBuffer->status) {
if (recvBuffer->status(ssh, fileName, WOLFSSH_SCP_NEW_FILE,
recvBuffer) != WS_SUCCESS)
recvBuffer) != WS_SUCCESS) {
WLOG(WS_LOG_ERROR, "scp: status of new file failed, abort");
ret = WS_SCP_ABORT;
}
}
break;

Expand All @@ -2869,9 +2870,10 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath,
recvBuffer->fileSz += sz;
if (recvBuffer->status) {
if (recvBuffer->status(ssh, recvBuffer->name,
WOLFSSH_SCP_FILE_PART, recvBuffer) != WS_SUCCESS)
WOLFSSH_SCP_FILE_PART, recvBuffer) != WS_SUCCESS) {
WLOG(WS_LOG_ERROR, "scp: bad status, abort");
ret = WS_SCP_ABORT;
}
}
break;

Expand All @@ -2880,9 +2882,10 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath,
recvBuffer->mTime = 0; /* @TODO set time if wanted */
if (recvBuffer->status) {
if (recvBuffer->status(ssh, recvBuffer->name,
WOLFSSH_SCP_FILE_DONE, recvBuffer) != WS_SUCCESS)
WOLFSSH_SCP_FILE_DONE, recvBuffer) != WS_SUCCESS) {
WLOG(WS_LOG_ERROR, "scp: bad status, abort");
ret = WS_SCP_ABORT;
}
}
break;

Expand Down
66 changes: 66 additions & 0 deletions zephyr/samples/tests/prj_nofs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Kernel options
CONFIG_MAIN_STACK_SIZE=32768
CONFIG_ENTROPY_GENERATOR=y
CONFIG_INIT_STACKS=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072

# Enable wolfSSH
CONFIG_WOLFSSH=y
CONFIG_WOLFSSH_SETTINGS_FILE="samples/tests/wolfssh_user_settings_nofs.h"

# Pthreads
CONFIG_PTHREAD_IPC=y

# Clock for time()
CONFIG_POSIX_CLOCK=y

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_TCP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

CONFIG_NET_TEST=y
CONFIG_NET_LOOPBACK=y

# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y

# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"

CONFIG_NET_PKT_TX_COUNT=10

# Logging
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
#CONFIG_WOLFSSH_DEBUG=y
#CONFIG_WOLFSSL_DEBUG=y
#CONFIG_DEBUG=y

# Enable logging using RTT and UART
#CONFIG_CBPRINTF_LIBC_SUBSTS=y
#CONFIG_CBPRINTF_FP_SUPPORT=y
#CONFIG_CONSOLE=y
#CONFIG_LOG_BACKEND_UART=y
#CONFIG_LOG_BUFFER_SIZE=15360

# TLS configuration
CONFIG_WOLFSSL=y
CONFIG_WOLFSSL_BUILTIN=y
CONFIG_WOLFSSL_SETTINGS_FILE="samples/tests/wolfssl_user_settings_nofs.h"

CONFIG_WOLFSSL_TLS_VERSION_1_2=y
CONFIG_WOLFSSL_KEY_EXCHANGE_ALL_ENABLED=y
CONFIG_WOLFSSL_CIPHER_ALL_ENABLED=y
CONFIG_WOLFSSL_MAC_ALL_ENABLED=y
CONFIG_WOLFSSL_HMAC_DRBG_ENABLED=y

6 changes: 6 additions & 0 deletions zephyr/samples/tests/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ tests:
platform_allow: qemu_x86
integration_platforms:
- qemu_x86
sample.lib.wolfssh_nofs_tests:
timeout: 200
platform_allow: qemu_x86
extra_args: CONF_FILE="prj_nofs.conf"
integration_platforms:
- qemu_x86
11 changes: 7 additions & 4 deletions zephyr/samples/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
#include <stdio.h>
#include <wolfssh/settings.h>
#include <wolfssh/ssh.h>
#include <zephyr/fs/fs.h>
#include <zephyr/storage/disk_access.h>
#include <ff.h>


#ifndef NO_FILESYSTEM
#ifndef CONFIG_FAT_FILESYSTEM_ELM
#error "This test is designed for FAT FS"
#endif
#include <zephyr/fs/fs.h>
#include <zephyr/storage/disk_access.h>
#include <ff.h>
#endif

#define CHECK_TEST_RETURN(func) do { \
printf("\tRunning %s... ", #func); \
Expand All @@ -60,6 +61,7 @@
int main(void)
{
int ret = 0;
#ifndef NO_FILESYSTEM
static FATFS fat_fs;
static struct fs_mount_t mnt_point = {
.type = FS_FATFS,
Expand Down Expand Up @@ -89,6 +91,7 @@ int main(void)
< 0);

CHECK_TEST_RETURN(fs_close(&zfp));
#endif

CHECK_TEST_RETURN(wolfSSH_UnitTest(0, NULL));
CHECK_TEST_RETURN(wolfSSH_TestsuiteTest(0, NULL));
Expand Down
68 changes: 68 additions & 0 deletions zephyr/samples/tests/wolfssh_user_settings_nofs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* user_settings.h
*
* Copyright (C) 2014-2024 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 <http://www.gnu.org/licenses/>.
*/

#ifndef WOLFSSH_USER_SETTINGS_H
#define WOLFSSH_USER_SETTINGS_H


#ifdef __cplusplus
extern "C" {
#endif

#include <wolfssl/wolfcrypt/types.h>

#undef WOLFSSH_SCP
#define WOLFSSH_SCP

#undef NO_APITEST_MAIN_DRIVER
#define NO_APITEST_MAIN_DRIVER

#undef NO_TESTSUITE_MAIN_DRIVER
#define NO_TESTSUITE_MAIN_DRIVER

#undef NO_UNITTEST_MAIN_DRIVER
#define NO_UNITTEST_MAIN_DRIVER

#undef NO_MAIN_DRIVER
#define NO_MAIN_DRIVER

#undef WS_NO_SIGNAL
#define WS_NO_SIGNAL

#undef WS_USE_TEST_BUFFERS
#define WS_USE_TEST_BUFFERS

#undef NO_WOLFSSL_DIR
#define NO_WOLFSSL_DIR

#undef WOLFSSH_NO_NONBLOCKING
#define WOLFSSH_NO_NONBLOCKING

#define DEFAULT_WINDOW_SZ (128 * 128)
#define WOLFSSH_MAX_SFTP_RW 8192

#undef NO_FILESYSTEM
#define NO_FILESYSTEM

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 2a139c9

Please sign in to comment.