Skip to content

Commit

Permalink
Misc zephyr fixes
Browse files Browse the repository at this point in the history
- Need to call fs_file_t_init() before calling fs_open()
- 0 is a valid POSIX socket number
- Include stdio.h when needed to simplify macro logic
- Define Zephyr specific macros in CMakeLists.txt to make for a better user experience
  • Loading branch information
julek-wolfssl committed Sep 22, 2023
1 parent 9442ec4 commit 470e839
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 30 deletions.
1 change: 1 addition & 0 deletions wolfcrypt/src/wc_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ XFILE z_fs_open(const char* filename, const char* mode)

file = (XFILE)XMALLOC(sizeof(*file), NULL, DYNAMIC_TYPE_FILE);
if (file != NULL) {
fs_file_t_init(file);
if (fs_open(file, filename, flags) != 0) {
XFREE(file, NULL, DYNAMIC_TYPE_FILE);
file = NULL;
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
#elif defined(WOLFSSL_TIRTOS)
#define WOLFSSL_SOCKET_INVALID ((SOCKET_T)-1)
#else
#define WOLFSSL_SOCKET_INVALID (SOCKET_T)(0)
#define WOLFSSL_SOCKET_INVALID (SOCKET_T)(-1)
#endif
#endif /* WOLFSSL_SOCKET_INVALID */

Expand Down
9 changes: 2 additions & 7 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,6 @@ typedef struct w64wrapper {
debugging is turned on */
#ifndef USE_WINDOWS_API
#ifndef XSNPRINTF
#if defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
(defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
defined(WOLFSSL_CERT_EXT) || defined(HAVE_PKCS7))
/* case where stdio is not included else where but is needed
for snprintf */
#include <stdio.h>
#endif
#if defined(WOLFSSL_ESPIDF) && \
(!defined(NO_ASN_TIME) && defined(HAVE_PKCS7))
#include<stdarg.h>
Expand Down Expand Up @@ -797,8 +790,10 @@ typedef struct w64wrapper {
}
#define XSNPRINTF _xsnprintf_
#elif defined(WOLF_C89)
#include <stdio.h>
#define XSPRINTF sprintf
#else
#include <stdio.h>
#define XSNPRINTF snprintf
#endif
#endif
Expand Down
9 changes: 6 additions & 3 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ if(CONFIG_WOLFSSL)
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/wolfcrypt/src/port/st/stm32.c)

zephyr_library_link_libraries(wolfSSL)

add_definitions(-DWOLFSSL_USER_SETTINGS)
add_definitions(-DWOLFSSL_ZEPHYR)

target_compile_definitions(wolfSSL INTERFACE WOLFSSL_ZEPHYR)
target_compile_definitions(wolfSSL INTERFACE WOLFSSL_USER_SETTINGS)
if(CONFIG_WOLFSSL_DEBUG)
target_compile_definitions(wolfSSL INTERFACE DEBUG_WOLFSSL)
endif()
else()
assert(CONFIG_WOLFSSL_LIBRARY "wolfSSL was enabled, but neither BUILTIN or LIBRARY was selected.")

Expand Down
3 changes: 0 additions & 3 deletions zephyr/samples/wolfssl_tls_sock/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ CONFIG_NET_SOCKETS_POSIX_NAMES=y

CONFIG_NET_TEST=y
CONFIG_NET_LOOPBACK=y
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_SERVER1="192.0.2.2"

# Network driver config
CONFIG_TEST_RANDOM_GENERATOR=y
Expand Down
8 changes: 0 additions & 8 deletions zephyr/user_settings-tls-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
extern "C" {
#endif

#undef WOLFSSL_ZEPHYR
#define WOLFSSL_ZEPHYR

#if 0
#undef SINGLE_THREADED
#define SINGLE_THREADED
Expand Down Expand Up @@ -147,11 +144,6 @@ extern "C" {
#define WOLFSSL_HAVE_SP_ECC
#endif

#if defined(CONFIG_WOLFSSL_DEBUG)
#undef DEBUG_WOLFSSL
#define DEBUG_WOLFSSL
#endif

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 0 additions & 8 deletions zephyr/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
extern "C" {
#endif

#undef WOLFSSL_ZEPHYR
#define WOLFSSL_ZEPHYR

#if 0
#undef SINGLE_THREADED
#define SINGLE_THREADED
Expand Down Expand Up @@ -140,11 +137,6 @@ extern "C" {
#define WOLFSSL_HAVE_SP_ECC
#endif

#if defined(CONFIG_WOLFSSL_DEBUG)
#undef DEBUG_WOLFSSL
#define DEBUG_WOLFSSL
#endif

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 470e839

Please sign in to comment.