From e89f093981e8e2086d9c91727b569e678f12d8cb Mon Sep 17 00:00:00 2001 From: yota Date: Thu, 5 Sep 2024 18:41:17 +0900 Subject: [PATCH 1/4] socket connection with FreeRTOS --- RPi-Pico/CMakeLists.txt | 202 ++------------ RPi-Pico/README.md | 82 +++++- RPi-Pico/benchmark/CMakeLists.txt | 21 ++ RPi-Pico/config/FreeRTOSConfig.h | 142 ++++++++++ RPi-Pico/config/lwipopts.h | 68 ++++- RPi-Pico/config/lwipopts_examples_common.h | 89 ------ RPi-Pico/config/user_settings.h | 82 ++---- RPi-Pico/include/wolf/blink.h | 7 +- RPi-Pico/include/wolf/common.h | 9 +- RPi-Pico/include/wolf/tcp.h | 61 +--- .../{wolf/blink.h => include/wolf/time.h} | 9 +- .../{src/wifi_main.c => include/wolf/tls.h} | 32 +-- RPi-Pico/include/wolf/wifi.h | 5 + RPi-Pico/src/bench_main.c | 3 + RPi-Pico/src/blink.c | 16 +- RPi-Pico/src/idleMemory.c | 74 +++++ RPi-Pico/src/tcp.c | 244 +++------------- RPi-Pico/src/tcpClient_main.c | 137 +++++---- RPi-Pico/src/tcpServer_main.c | 179 ++++++++++++ RPi-Pico/src/test_main.c | 4 +- RPi-Pico/src/time.c | 44 +++ RPi-Pico/src/tls.c | 135 +++++++++ RPi-Pico/src/tlsClient_main.c | 243 ++++++++-------- RPi-Pico/src/tlsServer_main.c | 262 ++++++++++++++++++ RPi-Pico/src/wifi.c | 4 +- RPi-Pico/src/wolfTcp.c | 246 ++++++++++++++++ RPi-Pico/tcp_client/CMakeLists.txt | 29 ++ RPi-Pico/tcp_server/CMakeLists.txt | 28 ++ RPi-Pico/testwolfcrypt/CMakeLists.txt | 17 ++ RPi-Pico/tls_client/CMakeLists.txt | 34 +++ RPi-Pico/tls_server/CMakeLists.txt | 33 +++ RPi-Pico/wolfssl_import.cmake | 34 +++ 32 files changed, 1746 insertions(+), 829 deletions(-) create mode 100644 RPi-Pico/benchmark/CMakeLists.txt create mode 100644 RPi-Pico/config/FreeRTOSConfig.h delete mode 100644 RPi-Pico/config/lwipopts_examples_common.h rename RPi-Pico/{wolf/blink.h => include/wolf/time.h} (92%) rename RPi-Pico/{src/wifi_main.c => include/wolf/tls.h} (57%) create mode 100644 RPi-Pico/src/idleMemory.c create mode 100644 RPi-Pico/src/tcpServer_main.c create mode 100644 RPi-Pico/src/time.c create mode 100644 RPi-Pico/src/tls.c create mode 100644 RPi-Pico/src/tlsServer_main.c create mode 100644 RPi-Pico/src/wolfTcp.c create mode 100644 RPi-Pico/tcp_client/CMakeLists.txt create mode 100644 RPi-Pico/tcp_server/CMakeLists.txt create mode 100644 RPi-Pico/testwolfcrypt/CMakeLists.txt create mode 100644 RPi-Pico/tls_client/CMakeLists.txt create mode 100644 RPi-Pico/tls_server/CMakeLists.txt create mode 100644 RPi-Pico/wolfssl_import.cmake diff --git a/RPi-Pico/CMakeLists.txt b/RPi-Pico/CMakeLists.txt index 5be3fba2..0c02f92a 100644 --- a/RPi-Pico/CMakeLists.txt +++ b/RPi-Pico/CMakeLists.txt @@ -1,13 +1,17 @@ cmake_minimum_required(VERSION 3.13) -# Pull in Pico and FreeRTOS -include(pico_sdk_import.cmake) -include(pico_extras_import_optional.cmake) -#include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) - - -if(PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0") - message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}") +# Pull in Pico, Pico-examples and FreeRTOS +# Pico Examples is only for referring ico_sdk_import.cmake and pico_extras_import_optional.cmake +set(PICO_BOARD pico_w) +include($ENV{PICO_EXAMPLES_PATH}/pico_sdk_import.cmake) +include($ENV{PICO_EXAMPLES_PATH}/pico_extras_import_optional.cmake) +include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) + +set(WOLFSSL_ROOT $ENV{WOLFSSL_ROOT}) +set(FREERTOS_KERNEL_PATH $ENV{FREERTOS-KERNEL_PATH}) + +if(PICO_SDK_VERSION_STRING VERSION_LESS " 1.3.0 ") + message(FATAL_ERROR " Raspberry Pi Pico SDK version 1.3.0(or later) required. Your version is ${PICO_SDK_VERSION_STRING} ") endif() project(wolf_pico_examples C CXX ASM) @@ -17,182 +21,26 @@ set(CMAKE_CXX_STANDARD 17) # Initialize the SDK pico_sdk_init() - ### Global Include Path include_directories(config) include_directories(include) include_directories(${PICO_SDK_PATH}/src/rp2_common/pico_lwip/include) + include_directories(${PICO_SDK_PATH}/src/rp2_common/hardware_rtc/include) include_directories(${PICO_SDK_PATH}/lib/lwip/contrib/ports/freertos/include) include_directories(${PICO_SDK_PATH}/lib/lwip/src/include) include_directories(${PICO_SDK_PATH}/src/rp2_common/pico_async_context/include) - - set(WOLFSSL_ROOT $ENV{WOLFSSL_ROOT}) + #include_directories(${PICO_SDK_PATH}/lib/btstack/test/embedded/) + include_directories(${FREERTOS_KERNEL_PATH}/include/) + include_directories(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/include) include_directories(${WOLFSSL_ROOT}) -### End of Global Include Path - - -### wolfSSL/wolfCrypt library - file(GLOB_RECURSE WOLFSSL_SRC - "${WOLFSSL_ROOT}/src/*.c" - "${WOLFSSL_ROOT}/wolfcrypt/src/*.c" - ) - list(REMOVE_ITEM WOLFSSL_SRC EXCLUDE REGEX - "${WOLFSSL_ROOT}/src/bio.c" - "${WOLFSSL_ROOT}/src/conf.c" - "${WOLFSSL_ROOT}/src/pk.c" - "${WOLFSSL_ROOT}/src/ssl_asn1.c" - "${WOLFSSL_ROOT}/src/ssl_bn.c" - "${WOLFSSL_ROOT}/src/ssl_misc.c" - "${WOLFSSL_ROOT}/src/x509.c" - "${WOLFSSL_ROOT}/src/x509_str.c" - "${WOLFSSL_ROOT}/wolfcrypt/src/evp.c" - "${WOLFSSL_ROOT}/wolfcrypt/src/misc.c" - ) - - add_library(wolfssl STATIC - ${WOLFSSL_SRC} - ) - - target_compile_definitions(wolfssl PUBLIC - WOLFSSL_USER_SETTINGS - ) -### End of wolfSSL/wolfCrypt library - - -### Test wolfCrypt algorithms - add_executable(testwolfcrypt - src/test_main.c - src/blink.c - ${WOLFSSL_ROOT}/wolfcrypt/test/test.c - ) - - target_link_libraries(testwolfcrypt - wolfssl - pico_stdlib - pico_cyw43_arch_none - pico_rand - ) - - pico_enable_stdio_usb(testwolfcrypt 1) - pico_enable_stdio_uart(testwolfcrypt 0) - - pico_add_extra_outputs(testwolfcrypt) -### End of Test wolfCrypt algorithms - - -### Benchmark wolfCrypt algorithms - add_executable(benchmark - src/bench_main.c - src/blink.c - ${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c - ) - - target_link_libraries(benchmark - wolfssl - pico_stdlib - pico_cyw43_arch_none - pico_rand - ) - - pico_enable_stdio_usb(benchmark 1) - pico_enable_stdio_uart(benchmark 0) - - pico_add_extra_outputs(benchmark) -### End of Benchmark wolfCrypt algorithms - - -### Wifi connection - add_executable(Wifi - src/blink.c - src/wifi.c - src/Wifi_main.c - ) - - target_compile_definitions(Wifi PRIVATE - WIFI_SSID=\"${WIFI_SSID}\" - WIFI_PASSWORD=\"${WIFI_PASSWORD}\" - PICO_CYW43_ARCH_POLL - NO_SYS=1 - ) - - target_link_libraries(Wifi - pico_stdlib - pico_rand - pico_lwip - pico_cyw43_arch - pico_lwip_nosys - pico_async_context_poll - ) - - - pico_enable_stdio_usb(Wifi 1) - pico_enable_stdio_uart(Wifi 0) - - pico_add_extra_outputs(Wifi) -### End of Wifi connection - - -### TCP Client - add_executable(tcp_Client - src/blink.c - src/wifi.c - src/tcp.c - src/tcpClient_main.c - ) - - target_compile_definitions(tcp_Client PRIVATE - WIFI_SSID=\"${WIFI_SSID}\" - WIFI_PASSWORD=\"${WIFI_PASSWORD}\" - TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\" - PICO_CYW43_ARCH_POLL - NO_SYS=1 - ) - - target_link_libraries(tcp_Client - pico_stdlib - pico_rand - pico_lwip - pico_cyw43_arch - pico_lwip_nosys - pico_async_context_poll - ) - - - pico_enable_stdio_usb(tcp_Client 1) - pico_enable_stdio_uart(tcp_Client 0) - - pico_add_extra_outputs(tcp_Client) -### End of TCP Client - - -### TLS Client - add_executable(tls_Client - src/blink.c - src/wifi.c - src/tcp.c - src/tlsClient_main.c - ) - - target_compile_definitions(tls_Client PRIVATE - WIFI_SSID=\"${WIFI_SSID}\" - WIFI_PASSWORD=\"${WIFI_PASSWORD}\" - TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\" - PICO_CYW43_ARCH_POLL - NO_SYS=1 - ) - - target_link_libraries(tls_Client - pico_stdlib - pico_rand - pico_lwip - pico_cyw43_arch - pico_lwip_nosys - pico_async_context_poll - wolfssl - ) +### End of Global Include Path + + include(wolfssl_import.cmake) - pico_enable_stdio_usb(tls_Client 1) - pico_enable_stdio_uart(tls_Client 0) + add_subdirectory(testwolfcrypt) + add_subdirectory(benchmark) + add_subdirectory(tcp_client) + add_subdirectory(tcp_server) + add_subdirectory(tls_client) + add_subdirectory(tls_server) - pico_add_extra_outputs(tls_Client) -### End of TLS Client \ No newline at end of file diff --git a/RPi-Pico/README.md b/RPi-Pico/README.md index 89ec6720..58ebdf2c 100644 --- a/RPi-Pico/README.md +++ b/RPi-Pico/README.md @@ -1,18 +1,76 @@ ## Getting Started -1. Put wolfSSL source files under this directory. - RPi-Pico/wolfssl +This example includes wolfSSL test, benchmark, Wifi, TCP/TLS client. -2. Setup pico-sdk and set PICO_SDK_PATH - export PICO_SDK_PATH=/your/pico-sdk/path -3. cmake and make - $ cd RPi-Pico - $ mkdir build - $ cd build - $ cmake -DPICO_BOARD=pico_w .. - $ make +### 1. Download files -4. Output is to USB serial +``` +$ git clone https://github.com/raspberrypi/pico-sdk +$ git clone https://github.com/raspberrypi/pico-examples +$ git clone hhttps://github.com/FreeRTOS +$ git clone https://github.com/wolfssl/wolfssl +$ git clone https://github.com/wolfssl-jp/RPi-pico-w +``` - \ No newline at end of file +### 2. Define path + +``` +$ export PICO_SDK_PATH=/your/pico-sdk/path +$ export PICO_EXAMPLES_PATH=/your/pico-examples/path +$ export FREERTOS_KERNEL_PATH=/your/FreeRTOS-kernel/path +$ export WOLFSSL_ROOT=/your/wolfssl-root/path +``` + +### 3. cmake and make + +``` +$ cd wolfssl-examples/RPi-Pico +$ cmake -DPICO_BOARD=pico_w -DWIFI_SSID=your-wifi-ssid\ + -DWIFI_PASSWORD=your-wifi-password\ + -DTCP_SERVER=ip-addr\ + -DDATETIME=yymmddhhmmss . +$ make +``` + +DATETIME is for certificate validity check. Not need to be very acurrate. + +### 4. Target files + +- testwolfcrypt.uf2 +- benchmark.uf2 +- tcp_Client.uf2 +- tls_Client.uf2 +- tcp_Server.uf2 +- tls_Server.uf2 + +Console output is to USB serial + + +### 5. Test server + +$ git clone https://github.com/wolfssl/wolfssl-examples +$ cd wolfssl-examples/tls +$ make + +TCP Server: +$ ./server-tcp + +TLS Server: +$ ./server-tls + +TCP Client: +$ ./client-tcp xxx.xxx.xxx.xxx + +TLS Client: +$ ./client-tls xxx.xxx.xxx.xxx + + + +### References + +- Raspberry Pi Pico and Pico W
+https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html + +- Connecting to the Internet with Raspberry Pi Pico W
+https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf diff --git a/RPi-Pico/benchmark/CMakeLists.txt b/RPi-Pico/benchmark/CMakeLists.txt new file mode 100644 index 00000000..9a3ee169 --- /dev/null +++ b/RPi-Pico/benchmark/CMakeLists.txt @@ -0,0 +1,21 @@ +add_executable(benchmark + ../src/bench_main.c + ../src/blink.c + ${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c +) + +target_link_libraries(benchmark + wolfssl + pico_stdlib + pico_cyw43_arch_none + pico_rand +) + +target_compile_definitions(benchmark PRIVATE + WOLFSSL_RPI_PICO +) + +pico_enable_stdio_usb(benchmark 1) +pico_enable_stdio_uart(benchmark 1) + +pico_add_extra_outputs(benchmark) \ No newline at end of file diff --git a/RPi-Pico/config/FreeRTOSConfig.h b/RPi-Pico/config/FreeRTOSConfig.h new file mode 100644 index 00000000..89b42fdf --- /dev/null +++ b/RPi-Pico/config/FreeRTOSConfig.h @@ -0,0 +1,142 @@ +/* + * FreeRTOS V202111.00 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* Scheduler Related */ +#define configUSE_PREEMPTION 1 +#define configUSE_TICKLESS_IDLE 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configTICK_RATE_HZ ((TickType_t)1000) +#define configMAX_PRIORITIES 32 +#define configMINIMAL_STACK_SIZE (configSTACK_DEPTH_TYPE)(256*3) +#define configUSE_16_BIT_TICKS 0 + +#define configIDLE_SHOULD_YIELD 1 + +/* Synchronization Related */ +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_QUEUE_SETS 1 +#define configUSE_TIME_SLICING 1 +#define configUSE_NEWLIB_REENTRANT 0 +// todo need this for lwip FreeRTOS sys_arch to compile +#define configENABLE_BACKWARD_COMPATIBILITY 1 +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 + +/* System */ +#define configSTACK_DEPTH_TYPE uint32_t +#define configMESSAGE_BUFFER_LENGTH_TYPE size_t + +/* Memory allocation related definitions. */ +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configSUPPORT_DYNAMIC_ALLOCATION 1 +#define configTOTAL_HEAP_SIZE (128 * 1024) +#define configAPPLICATION_ALLOCATED_HEAP 0 + +/* Hook function related definitions. */ +#define configCHECK_FOR_STACK_OVERFLOW 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 0 + +/* Run time and task stats gathering related definitions. */ +#define configGENERATE_RUN_TIME_STATS 0 +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 0 + +/* Co-routine related definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES 1 + +/* Software timer related definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH 1024 + +/* Interrupt nesting behaviour configuration. */ +/* +#define configKERNEL_INTERRUPT_PRIORITY [dependent of processor] +#define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application] +#define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application] +*/ + +#if FREE_RTOS_KERNEL_SMP // set by the RP2040 SMP port of FreeRTOS +/* SMP port only */ +#define configNUM_CORES 2 +#define configTICK_CORE 0 +#define configRUN_MULTIPLE_PRIORITIES 1 +#define configUSE_CORE_AFFINITY 1 +#endif + +/* RP2040 specific */ +#define configSUPPORT_PICO_SYNC_INTEROP 1 +#define configSUPPORT_PICO_TIME_INTEROP 1 + +#include +/* Define to trap errors during development. */ +#define configASSERT(x) assert(x) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTaskAbortDelay 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_xTaskResumeFromISR 1 +#define INCLUDE_xQueueGetMutexHolder 1 + +/* A header file that defines trace macro can be included here. */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/RPi-Pico/config/lwipopts.h b/RPi-Pico/config/lwipopts.h index 7c032ae2..355409cb 100644 --- a/RPi-Pico/config/lwipopts.h +++ b/RPi-Pico/config/lwipopts.h @@ -5,30 +5,78 @@ // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) // // This example uses a common include to avoid repetition -#include "lwipopts_examples_common.h" +//#include "lwipopts_examples_common.h" -#if !NO_SYS -#define TCPIP_THREAD_STACKSIZE 1024 -#define DEFAULT_THREAD_STACKSIZE 1024 +#define TCPIP_THREAD_STACKSIZE (1024*10) +#define DEFAULT_THREAD_STACKSIZE 1024*10 #define DEFAULT_RAW_RECVMBOX_SIZE 8 #define TCPIP_MBOX_SIZE 8 +#define DEFAULT_ACCEPTMBOX_SIZE 8 #define LWIP_TIMEVAL_PRIVATE 0 // not necessary, can be done either way -#define LWIP_TCPIP_CORE_LOCKING_INPUT 1 +#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 // ping_thread sets socket receive timeout, so enable this feature #define LWIP_SO_RCVTIMEO 1 -#endif - #define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_MPU_COMPATIBLE 0 -#define LWIP_PROVIDE_ERRNO + +#ifdef PICO_CYW43_ARCH_POLL #define LWIP_FREERTOS_SYS_ARCH_PROTECT_USES_MUTEX 1 +#endif + +#define MEMP_NUM_SYS_TIMEOUT 10 +#define DEFAULT_TCP_RECVMBOX_SIZE 10 +// Common settings used in most of the pico_w examples +// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) + +// allow override in some examples +//#if NO_SYS==0 +// #ifndef LWIP_SOCKET +// #define LWIP_SOCKET 1 +// #endif +//#endif +#if PICO_CYW43_ARCH_POLL +#define MEM_LIBC_MALLOC 1 +#else +// MEM_LIBC_MALLOC is incompatible with non polling versions +#define MEM_LIBC_MALLOC 0 +#endif +#define MEM_ALIGNMENT 4 +#define MEM_SIZE 4000 * 10 +#define MEMP_NUM_TCP_SEG 32 +#define MEMP_NUM_ARP_QUEUE 10 +#define PBUF_POOL_SIZE 24 +#define LWIP_ARP 1 +#define LWIP_ETHERNET 1 +#define LWIP_ICMP 1 +#define LWIP_RAW 1 +#define TCP_WND (8 * TCP_MSS) +#define TCP_MSS 1460 +#define TCP_SND_BUF (8 * TCP_MSS) +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) +#define LWIP_NETIF_STATUS_CALLBACK 1 +#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_HOSTNAME 1 +#define LWIP_NETCONN 0 +#define MEM_STATS 0 +#define SYS_STATS 0 +#define MEMP_STATS 0 +#define LINK_STATS 0 +// #define ETH_PAD_SIZE 2 +#define LWIP_CHKSUM_ALGORITHM 3 +#define LWIP_DHCP 1 +#define LWIP_IPV4 1 + +#define LWIP_TCP 1 +#define LWIP_DNS 1 +#define LWIP_TCP_KEEPALIVE 1 +#define LWIP_NETIF_TX_SINGLE_PBUF 1 +#define DHCP_DOES_ARP_CHECK 0 +#define LWIP_DHCP_DOES_ACD_CHECK 0 -/* wolfTCP config */ -#define WOLF_SOCKET 1 #endif diff --git a/RPi-Pico/config/lwipopts_examples_common.h b/RPi-Pico/config/lwipopts_examples_common.h deleted file mode 100644 index 891a5e38..00000000 --- a/RPi-Pico/config/lwipopts_examples_common.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H -#define _LWIPOPTS_EXAMPLE_COMMONH_H - -// Common settings used in most of the pico_w examples -// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) - -// allow override in some examples -#ifndef NO_SYS -#define NO_SYS 0 -#endif -// allow override in some examples -#ifndef LWIP_SOCKET -#define LWIP_SOCKET 0 -#endif -#if PICO_CYW43_ARCH_POLL -#define MEM_LIBC_MALLOC 1 -#else -// MEM_LIBC_MALLOC is incompatible with non polling versions -#define MEM_LIBC_MALLOC 0 -#endif -#define MEM_ALIGNMENT 4 -#define MEM_SIZE 4000 -#define MEMP_NUM_TCP_SEG 32 -#define MEMP_NUM_ARP_QUEUE 10 -#define PBUF_POOL_SIZE 24 -#define LWIP_ARP 1 -#define LWIP_ETHERNET 1 -#define LWIP_ICMP 1 -#define LWIP_RAW 1 -#define TCP_WND (8 * TCP_MSS) -#define TCP_MSS 1460 -#define TCP_SND_BUF (8 * TCP_MSS) -#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) -#define LWIP_NETIF_STATUS_CALLBACK 1 -#define LWIP_NETIF_LINK_CALLBACK 1 -#define LWIP_NETIF_HOSTNAME 1 -#define LWIP_NETCONN 0 -#define MEM_STATS 0 -#define SYS_STATS 0 -#define MEMP_STATS 0 -#define LINK_STATS 0 -// #define ETH_PAD_SIZE 2 -#define LWIP_CHKSUM_ALGORITHM 3 -#define LWIP_DHCP 1 -#define LWIP_IPV4 1 -#define LWIP_TCP 1 -#define LWIP_UDP 1 -#define LWIP_DNS 1 -#define LWIP_TCP_KEEPALIVE 1 -#define LWIP_NETIF_TX_SINGLE_PBUF 1 -#define DHCP_DOES_ARP_CHECK 0 -#define LWIP_DHCP_DOES_ACD_CHECK 0 - -#ifndef NDEBUG -#define LWIP_DEBUG 1 -#define LWIP_STATS 1 -#define LWIP_STATS_DISPLAY 1 -#endif - -#define ETHARP_DEBUG LWIP_DBG_OFF -#define NETIF_DEBUG LWIP_DBG_OFF -#define PBUF_DEBUG LWIP_DBG_OFF -#define API_LIB_DEBUG LWIP_DBG_OFF -#define API_MSG_DEBUG LWIP_DBG_OFF -#define SOCKETS_DEBUG LWIP_DBG_OFF -#define ICMP_DEBUG LWIP_DBG_OFF -#define INET_DEBUG LWIP_DBG_OFF -#define IP_DEBUG LWIP_DBG_OFF -#define IP_REASS_DEBUG LWIP_DBG_OFF -#define RAW_DEBUG LWIP_DBG_OFF -#define MEM_DEBUG LWIP_DBG_OFF -#define MEMP_DEBUG LWIP_DBG_OFF -#define SYS_DEBUG LWIP_DBG_OFF -#define TCP_DEBUG LWIP_DBG_OFF -#define TCP_INPUT_DEBUG LWIP_DBG_OFF -#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF -#define TCP_RTO_DEBUG LWIP_DBG_OFF -#define TCP_CWND_DEBUG LWIP_DBG_OFF -#define TCP_WND_DEBUG LWIP_DBG_OFF -#define TCP_FR_DEBUG LWIP_DBG_OFF -#define TCP_QLEN_DEBUG LWIP_DBG_OFF -#define TCP_RST_DEBUG LWIP_DBG_OFF -#define UDP_DEBUG LWIP_DBG_OFF -#define TCPIP_DEBUG LWIP_DBG_OFF -#define PPP_DEBUG LWIP_DBG_OFF -#define SLIP_DEBUG LWIP_DBG_OFF -#define DHCP_DEBUG LWIP_DBG_OFF - -#endif /* __LWIPOPTS_H__ */ diff --git a/RPi-Pico/config/user_settings.h b/RPi-Pico/config/user_settings.h index 3bec0624..98275312 100644 --- a/RPi-Pico/config/user_settings.h +++ b/RPi-Pico/config/user_settings.h @@ -38,38 +38,28 @@ extern "C" extern time_t myTime(time_t *); #define XTIME(t) myTime(t) +#define WOLFSSL_DEBUG + /* ------------------------------------------------------------------------- */ /* Platform */ /* ------------------------------------------------------------------------- */ #define WOLFSSL_GENERAL_ALIGNMENT 4 #define SIZEOF_LONG_LONG 8 -#if 0 -#define NO_64BIT /* disable use of 64-bit variables */ -#endif - -#ifdef TARGET_EMBEDDED -/* disable mutex locking */ -#define SINGLE_THREADED - -/* reduce stack use. For variables over 100 bytes allocate from heap */ -#define WOLFSSL_SMALL_STACK /* Disable the built-in socket support and use the IO callbacks. * Set IO callbacks with wolfSSL_CTX_SetIORecv/wolfSSL_CTX_SetIOSend */ #define WOLFSSL_USER_IO -#endif - +#define SINGLE_THREADED /* ------------------------------------------------------------------------- */ /* Math Configuration */ /* ------------------------------------------------------------------------- */ /* Wolf Single Precision Math */ -#if 1 #define WOLFSSL_HAVE_SP_RSA #define WOLFSSL_HAVE_SP_DH #define WOLFSSL_HAVE_SP_ECC -// #define WOLFSSL_SP_4096 /* Enable RSA/RH 4096-bit support */ -// #define WOLFSSL_SP_384 /* Enable ECC 384-bit SECP384R1 support */ +#define WOLFSSL_SP_4096 /* Enable RSA/RH 4096-bit support */ +#define WOLFSSL_SP_384 /* Enable ECC 384-bit SECP384R1 support */ // #define WOLFSSL_SP_CACHE_RESISTANT #define WOLFSSL_SP_MATH /* only SP math - disables integer.c/tfm.c */ @@ -78,38 +68,20 @@ extern time_t myTime(time_t *); // #define WOLFSSL_SP_NO_MALLOC // #define WOLFSSL_SP_DIV_32 /* do not use 64-bit divides */ -#ifdef TARGET_EMBEDDED -/* use smaller version of code */ -//#define WOLFSSL_SP_SMALL -#else /* SP Assembly Speedups - specific to chip type */ #define WOLFSSL_SP_ASM -#endif + // #define WOLFSSL_SP_X86_64 // #define WOLFSSL_SP_X86 // #define WOLFSSL_SP_ARM32_ASM // #define WOLFSSL_SP_ARM64_ASM #define WOLFSSL_SP_ARM_THUMB_ASM // #define WOLFSSL_SP_ARM_CORTEX_M_ASM -#elif 1 + +#if 0 /* Fast Math (tfm.c) (stack based and timing resistant) */ #define USE_FAST_MATH #define TFM_TIMING_RESISTANT -#else -/* Normal (integer.c) (heap based, not timing resistant) - not recommended*/ -#define USE_INTEGER_HEAP_MATH -#endif - -/* ------------------------------------------------------------------------- */ -/* Crypto */ -/* ------------------------------------------------------------------------- */ -/* RSA */ -#undef NO_RSA -#if 0 -#ifdef USE_FAST_MATH -/* Maximum math bits (Max RSA key bits * 2) */ -#define FP_MAX_BITS 4096 -#endif #endif #if 1 @@ -150,11 +122,11 @@ extern time_t myTime(time_t *); #ifdef ECC_USER_CURVES /* Manual Curve Selection */ -// #define HAVE_ECC192 -// #define HAVE_ECC224 -#undef NO_ECC256 - // #define HAVE_ECC384 - // #define HAVE_ECC521 + #define HAVE_ECC192 + #define HAVE_ECC224 + #undef NO_ECC256 + #define HAVE_ECC384 + #define HAVE_ECC521 #endif /* Fixed point cache (speeds repeated operations against same private key) */ @@ -174,26 +146,6 @@ extern time_t myTime(time_t *); /* Compressed ECC Key Support */ // #define HAVE_COMP_KEY - -/* Use alternate ECC size for ECC math */ -#ifdef USE_FAST_MATH -/* MAX ECC BITS = ROUND8(MAX ECC) * 2 */ -#if defined(NO_RSA) && defined(NO_DH) -/* Custom fastmath size if not using RSA/DH */ -#define FP_MAX_BITS (256 * 2) -#else -/* use heap allocation for ECC points */ -#define ALT_ECC_SIZE - - /* wolfSSL will compute the FP_MAX_BITS_ECC, but it can be overridden */ - // #define FP_MAX_BITS_ECC (256 * 2) -#endif - -/* Speedups specific to curve */ -#ifndef NO_ECC256 -#define TFM_ECC256 -#endif -#endif #endif /* AES */ @@ -209,10 +161,10 @@ extern time_t myTime(time_t *); #define GCM_TABLE_4BIT #endif - // #define WOLFSSL_AES_DIRECT + #define WOLFSSL_AES_DIRECT // #define HAVE_AES_ECB - // #define WOLFSSL_AES_COUNTER - // #define HAVE_AESCCM + #define WOLFSSL_AES_COUNTER + #define HAVE_AESCCM #else #define NO_AES #endif @@ -515,7 +467,7 @@ extern int my_rng_gen_block(unsigned char *output, unsigned int sz); // #define WOLFCRYPT_ONLY /* do not warm when file is included to be built and not required to be */ -#//define WOLFSSL_IGNORE_FILE_WARN +//define WOLFSSL_IGNORE_FILE_WARN /* In-lining of misc.c functions */ /* If defined, must include wolfcrypt/src/misc.c in build */ diff --git a/RPi-Pico/include/wolf/blink.h b/RPi-Pico/include/wolf/blink.h index 0139dba2..bf3c2693 100644 --- a/RPi-Pico/include/wolf/blink.h +++ b/RPi-Pico/include/wolf/blink.h @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#ifndef BLINK_H +#define BLINK_H + void blink(int n, int init); -#define WOLF_BLINK_INIT 1 \ No newline at end of file +#define WOLF_BLINK_INIT 1 + +#endif \ No newline at end of file diff --git a/RPi-Pico/include/wolf/common.h b/RPi-Pico/include/wolf/common.h index 61520e41..473f7c6f 100644 --- a/RPi-Pico/include/wolf/common.h +++ b/RPi-Pico/include/wolf/common.h @@ -1,4 +1,4 @@ -/* wolf_common.h +/* common.h * * Copyright (C) 2006-2023 wolfSSL Inc. * @@ -19,5 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#ifndef COMMON_H +#define COMMON_H + #define WOLF_SUCCESS 0 -#define WOLF_FAIL -1 \ No newline at end of file +#define WOLF_FAIL -1 + +#endif \ No newline at end of file diff --git a/RPi-Pico/include/wolf/tcp.h b/RPi-Pico/include/wolf/tcp.h index 25b87b15..c21acc0c 100644 --- a/RPi-Pico/include/wolf/tcp.h +++ b/RPi-Pico/include/wolf/tcp.h @@ -1,4 +1,4 @@ -/* tcp.c +/* tcp.h * * Copyright (C) 2006-2023 wolfSSL Inc. * @@ -19,63 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ -#include -#include "pico/cyw43_arch.h" -#include "pico/stdlib.h" +#ifndef TCP_H +#define TCP_H -#include "lwip/ip_addr.h" - -#include "wolf/blink.h" -#include "wolf/common.h" - -/* This is just for, inet_pton, sockaddr_in */ -#undef LWIP_SOCKET -#define LWIP_SOCKET 1 -#define LWIP_IPV4 1 - -#include "lwip/sockets.h" -#include "lwip/inet.h" - -#if WOLF_SOCKET - -#undef SOCKET_T -#undef socket -#undef close -#undef inet_pton -#undef connect -#undef recv -#undef send -#define SOCKET_T WOLF_SOCKET_T -#define socket wolf_TCPsocket -#define close wolf_TCPclose -#define inet_pton wolf_inet_pton -#define connect wolf_TCPconnect -#define recv wolf_TCPread -#define send wolf_TCPwrite +void tcp_initThread(void); #endif -#define DEBUG_printf printf -#define BUF_SIZE (4096*2) - -typedef u32_t socklen_t; - -typedef struct { - struct tcp_pcb *tcp_pcb; - ip_addr_t remote_addr; - uint8_t buffer[BUF_SIZE]; - int buffer_len; - int sent_len; - bool complete; - int run_count; - bool connected; -} *WOLF_SOCKET_T; - - - -WOLF_SOCKET_T wolf_TCPsocket(void); -int wolf_inet_pton(int af, const char *ip_str, void *ip_dst); -int wolf_TCPclose(WOLF_SOCKET_T sock); -int wolf_TCPconnect(WOLF_SOCKET_T, const struct sockaddr *addr, socklen_t addrlen); -int wolf_TCPread (WOLF_SOCKET_T, unsigned char *, unsigned long); -int wolf_TCPwrite(WOLF_SOCKET_T, const unsigned char *, unsigned long); \ No newline at end of file diff --git a/RPi-Pico/wolf/blink.h b/RPi-Pico/include/wolf/time.h similarity index 92% rename from RPi-Pico/wolf/blink.h rename to RPi-Pico/include/wolf/time.h index 0139dba2..1e0f90e1 100644 --- a/RPi-Pico/wolf/blink.h +++ b/RPi-Pico/include/wolf/time.h @@ -1,4 +1,4 @@ -/* blink.h +/* time.h * * Copyright (C) 2006-2023 wolfSSL Inc. * @@ -19,6 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ -void blink(int n, int init); +#ifndef TIME_H +#define TIME_H -#define WOLF_BLINK_INIT 1 \ No newline at end of file +int time_init(void); + +#endif diff --git a/RPi-Pico/src/wifi_main.c b/RPi-Pico/include/wolf/tls.h similarity index 57% rename from RPi-Pico/src/wifi_main.c rename to RPi-Pico/include/wolf/tls.h index c5bc0c62..cfbac1b3 100644 --- a/RPi-Pico/src/wifi_main.c +++ b/RPi-Pico/include/wolf/tls.h @@ -1,4 +1,4 @@ -/* wifi_main.c +/* tls.h * * Copyright (C) 2006-2023 wolfSSL Inc. * @@ -19,30 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ -#include -#include "pico/stdlib.h" -#include "pico/cyw43_arch.h" +#ifndef TLS_H +#define TLS_H -#include "wolf/common.h" -#include "wolf/wifi.h" -#include "wolf/blink.h" +int my_IORecv(WOLFSSL *ssl, char *buff, int sz, void *ctx); +int my_IOSend(WOLFSSL *ssl, char *buff, int sz, void *ctx); -void lwip_example_app_platform_assert(const char *msg, int line, const char *file) -{ - printf("Assertion \"%s\" failed at line %d in %s\n", msg, line, file); - fflush(NULL); - abort(); -} - -int main(int argc, char **argv) -{ - stdio_init_all(); - - blink(10, WOLF_BLINK_INIT); - wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000); - - blink(10, 0); - wolf_wifiDisconnect(); - - return 0; -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/RPi-Pico/include/wolf/wifi.h b/RPi-Pico/include/wolf/wifi.h index cabf5c5a..eb498374 100644 --- a/RPi-Pico/include/wolf/wifi.h +++ b/RPi-Pico/include/wolf/wifi.h @@ -19,5 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#ifndef WIFI_H +#define WIFI_H + int wolf_wifiConnect(const char *ssid, const char *pw, uint32_t auth, uint32_t timeout); int wolf_wifiDisconnect(void); + +#endif \ No newline at end of file diff --git a/RPi-Pico/src/bench_main.c b/RPi-Pico/src/bench_main.c index eed0d33b..34314f18 100644 --- a/RPi-Pico/src/bench_main.c +++ b/RPi-Pico/src/bench_main.c @@ -38,6 +38,9 @@ int main(int argc, char **argv) int ret; blink(10, WOLF_BLINK_INIT); + printf("\nHit any key to start\n"); + getchar(); + printf("\nSystem clock = %dMHz\n\n", clock_get_hz(clk_sys)/1000000); ret = benchmark_test(NULL); printf("End: %d\n", ret); diff --git a/RPi-Pico/src/blink.c b/RPi-Pico/src/blink.c index bb4d0ae9..a814ab8f 100644 --- a/RPi-Pico/src/blink.c +++ b/RPi-Pico/src/blink.c @@ -22,6 +22,14 @@ #include "pico/stdlib.h" #include "pico/cyw43_arch.h" +#ifdef PICO_CYW43_ARCH_FREERTOS +#include "FreeRTOS.h" +#include "task.h" +#define SLEEP_MS vTaskDelay +#else +#define SLEEP_MS sleep_ms +#endif + void blink(int n, int init) { int i; @@ -34,17 +42,17 @@ void blink(int n, int init) while (1) { cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); - sleep_ms(25); + SLEEP_MS(25); cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); - sleep_ms(25); + SLEEP_MS(25); } } } for (i = 0; i < n; i++) { cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); - sleep_ms(250); + SLEEP_MS(250); cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); - sleep_ms(250); + SLEEP_MS(250); } } \ No newline at end of file diff --git a/RPi-Pico/src/idleMemory.c b/RPi-Pico/src/idleMemory.c new file mode 100644 index 00000000..615db56e --- /dev/null +++ b/RPi-Pico/src/idleMemory.c @@ -0,0 +1,74 @@ +#include "FreeRTOS.h" +#include +#include +/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an +implementation of vApplicationGetIdleTaskMemory() to provide the memory that is +used by the Idle task. */ +void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, + StackType_t **ppxIdleTaskStackBuffer, + uint32_t *pulIdleTaskStackSize) +{ + /* If the buffers to be provided to the Idle task are declared inside this + function then they must be declared static – otherwise they will be allocated on + the stack and so not exists after this function exits. */ + static StaticTask_t xIdleTaskTCB; + static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; + + /* Pass out a pointer to the StaticTask_t structure in which the Idle task’s + state will be stored. */ + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + + /* Pass out the array that will be used as the Idle task’s stack. */ + *ppxIdleTaskStackBuffer = uxIdleTaskStack; + + /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} +/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the +application must provide an implementation of vApplicationGetTimerTaskMemory() +to provide the memory that is used by the Timer service task. */ +void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, + StackType_t **ppxTimerTaskStackBuffer, + uint32_t *pulTimerTaskStackSize) +{ + /* If the buffers to be provided to the Timer task are declared inside this + function then they must be declared static – otherwise they will be allocated on + the stack and so not exists after this function exits. */ + static StaticTask_t xTimerTaskTCB; + static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; + + /* Pass out a pointer to the StaticTask_t structure in which the Timer + task’s state will be stored. */ + *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; + + /* Pass out the array that will be used as the Timer task’s stack. */ + *ppxTimerTaskStackBuffer = uxTimerTaskStack; + + /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */ + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; +} + +void vApplicationStackOverflowHook(TaskHandle_t xTask, + char *pcTaskName) +{ + printf("----------------------------------------------\n"); + printf("STACK OVERFLOW on %s\n", pcTaskName); + printf("----------------------------------------------\n"); + taskDISABLE_INTERRUPTS(); + for (;;) + ; +} + +void vAssertCalled(const char *pcFile, uint32_t ulLine) +{ + printf("----------------------------------------------\n"); + printf("ASSERT FAILED %s line: %d\n", pcFile, ulLine); + printf("----------------------------------------------\n"); + taskDISABLE_INTERRUPTS(); + for (;;) + ; +} diff --git a/RPi-Pico/src/tcp.c b/RPi-Pico/src/tcp.c index 14854645..75722294 100644 --- a/RPi-Pico/src/tcp.c +++ b/RPi-Pico/src/tcp.c @@ -19,228 +19,62 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ -#include -#include "pico/cyw43_arch.h" -#include "pico/stdlib.h" +#include "lwip/init.h" +#include "lwip/tcpip.h" +#include "lwip/netif.h" +#include "lwip/ip_addr.h" +#include "lwip/ip4_addr.h" -#include "wolf/tcp.h" +#include "lwip/init.h" +#include "lwip/sockets.h" -#include "lwip/pbuf.h" -#include "lwip/tcp.h" +#include "FreeRTOS.h" +#include "task.h" -#define TEST_ITERATIONS 10 -#define POLL_TIME_S 5 +static int tcpip_initialized = 0; -static void dump_bytes(const uint8_t *p, uint32_t len) +static void my_tcpip_init_done(void *arg) { - for (; len; len--, p++) { - if (((unsigned long)p & 0x07) == 0) { - DEBUG_printf("\n"); - } - DEBUG_printf("%02x ", *p); - } - DEBUG_printf("\n"); -} - - -int wolf_TCPclose(WOLF_SOCKET_T sock) -{ - err_t err = ERR_OK; - if (sock->tcp_pcb != NULL) - { - tcp_arg(sock->tcp_pcb, NULL); - tcp_poll(sock->tcp_pcb, NULL, 0); - tcp_sent(sock->tcp_pcb, NULL); - tcp_recv(sock->tcp_pcb, NULL); - tcp_err(sock->tcp_pcb, NULL); - err = tcp_close(sock->tcp_pcb); - if (err != ERR_OK) { - DEBUG_printf("close failed %d, calling abort\n", err); - tcp_abort(sock->tcp_pcb); - err = ERR_ABRT; - } - sock->tcp_pcb = NULL; - } - free(sock); - return err; -} - -static err_t tcp_result(WOLF_SOCKET_T sock, int status) -{ - if (status == 0) { - DEBUG_printf("test success\n"); - } else { - DEBUG_printf("test failed %d\n", status); - } - sock->complete = true; - return 0; -} - -static err_t lwip_cb_client_sent(void *arg, struct tcp_pcb *tpcb, u16_t len) -{ - WOLF_SOCKET_T sock = (WOLF_SOCKET_T)arg; - - sock->sent_len += len; - - if (sock->sent_len >= BUF_SIZE) - { - - sock->run_count++; - if (sock->run_count >= TEST_ITERATIONS) - { - tcp_result(arg, 0); - return ERR_OK; - } - - // We should receive a new buffer from the server - sock->buffer_len = 0; - sock->sent_len = 0; - } - - return ERR_OK; -} - -static err_t lwip_cb_client_connected(void *arg, struct tcp_pcb *tpcb, err_t err) -{ - WOLF_SOCKET_T sock = (WOLF_SOCKET_T)arg; - - if (err != ERR_OK) - { - DEBUG_printf("connect failed %d\n", err); - return tcp_result(arg, err); - } - sock->connected = true; - return ERR_OK; -} - -static err_t lwip_cb_client_poll(void *arg, struct tcp_pcb *tpcb) -{ - return tcp_result(arg, 0); + tcpip_initialized = 1; + printf("\ntcpip_thread initialized!\n"); } -static void lwip_cb_client_err(void *arg, err_t err) +void print_netinfo(void) { - if (err != ERR_ABRT) { - DEBUG_printf("tcp_client_err %d\n", err); - tcp_result(arg, err); + struct netif *netif = netif_list; + if (netif != NULL) { + ip4_addr_t ip = netif->ip_addr; + ip4_addr_t netmask = netif->netmask; + ip4_addr_t gw = netif->gw; + + printf("IP Addr: %s\n", ip4addr_ntoa(&ip)); + printf("Netmask: %s\n", ip4addr_ntoa(&netmask)); + printf("Gateway: %s\n", ip4addr_ntoa(&gw)); } -} - -static err_t lwip_cb_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) -{ - WOLF_SOCKET_T sock = (WOLF_SOCKET_T)arg; - if (!p) { - return ERR_OK; + else { + printf("Network interface not found.\n"); } - - cyw43_arch_lwip_check(); - if (p->tot_len > 0) { - const uint16_t buffer_left = BUF_SIZE - sock->buffer_len; - sock->buffer_len += pbuf_copy_partial(p, sock->buffer + sock->buffer_len, - p->tot_len > buffer_left ? buffer_left : p->tot_len, 0); - tcp_recved(tpcb, p->tot_len); - } - pbuf_free(p); - return ERR_OK; -} - -int wolf_inet_pton(int af, const char *ip_str, void *ip_dst) -{ - (void)af; - struct sockaddr_in *addr = (struct sockaddr_in *)ip_dst; - - return ip4addr_aton(ip_str, ip_dst); } -static u32_t swapBytes(u16_t a) +void tcp_initThread(void) { - u8_t *p = (u8_t *)&a; - return p[0] << 8 | p[1]; -} + static struct netif netif; + static ip4_addr_t ipaddr, netmask, gw; -int wolf_TCPconnect(WOLF_SOCKET_T sock, const struct sockaddr *addr, socklen_t addrlen) -{ - int err; - struct sockaddr_in *addr_in = (struct sockaddr_in *)addr; + tcpip_init(my_tcpip_init_done, NULL); - sock->tcp_pcb = tcp_new_ip_type(IP_GET_TYPE(&addr_in->sin_addr)); - if (!sock->tcp_pcb) { - DEBUG_printf("failed to create pcb\n"); - return false; + while (tcpip_initialized == 0) { + printf("."); + vTaskDelay(1000); /* need to wait for initializing TCPIP */ } - tcp_arg(sock->tcp_pcb, sock); - tcp_poll(sock->tcp_pcb, lwip_cb_client_poll, POLL_TIME_S * 2); - tcp_sent(sock->tcp_pcb, lwip_cb_client_sent); - tcp_recv(sock->tcp_pcb, lwip_cb_client_recv); - tcp_err(sock->tcp_pcb, lwip_cb_client_err); - - sock->buffer_len = 0; - - cyw43_arch_lwip_begin(); - err = tcp_connect(sock->tcp_pcb, (const ip_addr_t *)&addr_in->sin_addr, - swapBytes(addr_in->sin_port), lwip_cb_client_connected); - cyw43_arch_lwip_end(); - if (err != ERR_OK) { - DEBUG_printf("wolf_TCPconnect: Failed"); - return WOLF_FAIL; - } - sock->connected = false; + IP4_ADDR(&ipaddr, 192, 168, 10, 79); + IP4_ADDR(&netmask, 255, 255, 255, 0); + IP4_ADDR(&gw, 192, 168, 10, 1); - while (sock->connected != true) - { - cyw43_arch_poll(); - cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000)); - } - return WOLF_SUCCESS; -} + netif_add(&netif, &ipaddr, &netmask, &gw, NULL, NULL, tcpip_input); + netif_set_default(&netif); + netif_set_up(&netif); -// get a new TCP client -WOLF_SOCKET_T wolf_TCPsocket() -{ - WOLF_SOCKET_T sock = calloc(1, sizeof(*sock)); - if (!sock) { - DEBUG_printf("failed to allocate state\n"); - return NULL; - } - return sock; + print_netinfo(); } - -int wolf_TCPwrite(WOLF_SOCKET_T sock, const unsigned char *buff, long unsigned int len) -{ - int ret; - int i; - - sock->sent_len = 0; - ret = tcp_write(sock->tcp_pcb, buff, len, TCP_WRITE_FLAG_COPY); - - if (ret == ERR_OK) { - tcp_output(sock->tcp_pcb); - } - sock->sent_len = 0; - return (int)len; -} - -int wolf_TCPread(WOLF_SOCKET_T sock, unsigned char *buff, long unsigned int len) -{ - int recv_len; - int remained; - int i; - - while (1) { /* no timeout for now */ - if(sock->buffer_len > 0) { - recv_len = len <= sock->buffer_len ? len : sock->buffer_len; - memcpy(buff, sock->buffer, recv_len); - if(recv_len >= len) { - remained = sock->buffer_len - recv_len; - sock->buffer_len = remained; - for(i=0; ibuffer[i] = sock->buffer[i+recv_len]; - } else - sock->buffer_len = 0; - return recv_len; - } - cyw43_arch_poll(); - cyw43_arch_wait_for_work_until(make_timeout_time_ms(10)); - } -} \ No newline at end of file diff --git a/RPi-Pico/src/tcpClient_main.c b/RPi-Pico/src/tcpClient_main.c index 7fc14243..ee6d7850 100644 --- a/RPi-Pico/src/tcpClient_main.c +++ b/RPi-Pico/src/tcpClient_main.c @@ -23,59 +23,92 @@ #include "pico/stdlib.h" #include "pico/cyw43_arch.h" -#include "wolf/common.h" -#include "wolf/tcp.h" +#include "FreeRTOS.h" +#include "task.h" + +#include "lwip/init.h" +#include "lwip/sockets.h" + #include "wolf/wifi.h" #include "wolf/blink.h" +#include "wolf/tcp.h" -#define TCP_PORT 1111 +#define TCP_PORT 11111 -void tcpClient_test(void) +void tcpClient_test(void *arg) { + (void)arg; int i; int ret; #define BUFF_SIZE 2048 char buffer[BUFF_SIZE]; - #define SIZE_OF_CLIENT_HELLO 815 - char msg[SIZE_OF_CLIENT_HELLO] = "\026\003\003\003\052\001\000\003\046 Fake Client Hello"; + #define SIZE_OF_CLIENT_HELLO 16 + char msg[SIZE_OF_CLIENT_HELLO] = "Client Hello"; - SOCKET_T sock; + int sock; struct sockaddr_in servAddr; - sock = socket(); - if (!sock) - { - printf("ERROR:wolf_TCPsocke()\n"); + cyw43_arch_init(); + + printf("Connecting to Wi-Fi...\n"); + if (wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 5000)) { + printf("failed to connect.\n"); return; } + else { + printf("Wifi connected.\n"); + } - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; /* using IPv4 */ - servAddr.sin_port = htons(TCP_PORT); /* on DEFAULT_PORT */ + lwip_init(); + tcp_initThread(); - if (inet_pton(AF_INET, TEST_TCP_SERVER_IP, &servAddr.sin_addr) != 1) { - fprintf(stderr, "ERROR: invalid address\n"); - goto exit; - } + printf("Starting TCP client\n"); - if (connect(sock,(struct sockaddr*) &servAddr, sizeof(servAddr)) != WOLF_SUCCESS) { - printf("ERROR:wolf_TCPconnect()\n"); - goto exit; + for(i=0; i< 3; i++) { + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + printf("ERROR:socke()\n"); + return; + } + + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; /* using IPv4 */ + servAddr.sin_port = htons(TCP_PORT); /* on DEFAULT_PORT */ + + printf("Connecting to the server(%s)\n", TCP_SERVER); + if (inet_pton(AF_INET, TCP_SERVER, &servAddr.sin_addr) != 1) { + fprintf(stderr, "ERROR: invalid address\n"); + goto exit; + } + + if ((ret = connect(sock,(struct sockaddr*) &servAddr, + sizeof(servAddr))) != EXIT_SUCCESS) { + printf("ERROR:connect(%d)\n", ret); + goto exit; + } + + printf("Writing to server: %s\n", msg); + ret = write(sock, msg, sizeof(msg)); + if (ret < 0) { + printf("Failed to write data. err=%d\n", ret); + goto exit; + } + + ret = read(sock, buffer, BUFF_SIZE); + if (ret < 0) { + printf("Failed to read data. err=%d\n", ret); + goto exit; + } + buffer[ret] = '\0'; + printf("Received message[%d]: %s\n", i, buffer); + close(sock); } - printf("Writing to server: %s\n", msg); - ret = send(sock, msg, sizeof(msg)); - if (ret < 0) { - DEBUG_printf("Failed to write data. err=%d\n", ret); - goto exit; - } - - ret = recv(sock, buffer, BUFF_SIZE); - if (ret < 0) { - DEBUG_printf("Failed to read data. err=%d\n", ret); - goto exit; - } - printf("Message: %s\n", buffer); + printf("End of TCP client\n"); + + cyw43_arch_deinit(); + + printf("Wifi disconnected\n"); exit: close(sock); @@ -83,32 +116,20 @@ void tcpClient_test(void) void main(void) { - blink(20, 1); - - cyw43_arch_enable_sta_mode(); - printf("Connecting to Wi-Fi...\n"); - printf("WIFI_SSID=%s, WIFI_PASSWORD=%s\n", WIFI_SSID, WIFI_PASSWORD); - if (wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000)) { - printf("failed to connect.\n"); - return; - } else { - printf("Wifi connected.\n"); - } - cyw43_arch_lwip_begin(); + TaskHandle_t task_tcpClient; +#define STACK_SIZE (1024 * 16) - printf("Starting TCP client\n"); - tcpClient_test(); - printf("End of TCP client\n"); + int i; - cyw43_arch_lwip_end(); - cyw43_arch_deinit(); + stdio_init_all(); + for(i=0; i<10; i++) { + printf("Starting in %dSec.\n", 10 - i); + sleep_ms(1000); + } - printf("Wifi disconnected\n"); -} + printf("Creating tlsClient task, stack = %d\n", STACK_SIZE); + xTaskCreate(tcpClient_test, "WifiMainThread", STACK_SIZE, NULL, + CYW43_TASK_PRIORITY+1, &task_tcpClient); + vTaskStartScheduler(); -void lwip_example_app_platform_assert(const char *msg, int line, const char *file) -{ - printf("Assertion \"%s\" failed at line %d in %s\n", msg, line, file); - fflush(NULL); } - diff --git a/RPi-Pico/src/tcpServer_main.c b/RPi-Pico/src/tcpServer_main.c new file mode 100644 index 00000000..3888cb9e --- /dev/null +++ b/RPi-Pico/src/tcpServer_main.c @@ -0,0 +1,179 @@ +/* server-tcp.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. (formerly known as CyaSSL) + * + * wolfSSL 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 2 of the License, or + * (at your option) any later version. + * + * wolfSSL 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include "pico/stdlib.h" +#include "pico/cyw43_arch.h" + +#include "FreeRTOS.h" +#include "task.h" + +#include "lwip/init.h" +#include "lwip/sockets.h" + +#include "wolf/wifi.h" +#include "wolf/blink.h" +#include "wolf/tcp.h" + +#define DEFAULT_PORT 11111 + +void tcpServer_test(void *arg) +{ + (void)arg; + int ret; + int sockfd; + int connd; + struct sockaddr_in servAddr; + struct sockaddr_in clientAddr; + socklen_t size = sizeof(clientAddr); + char buff[256]; + size_t len; + int shutdown = 0; + const char *reply = "I hear ya fa shizzle!\n"; + + cyw43_arch_init(); + + printf("Connecting to Wi-Fi...\n"); + if (wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 5000)) { + printf("failed to connect.\n"); + return; + } + else { + printf("Wifi connected.\n"); + } + + lwip_init(); + tcp_initThread(); + + /* Create a socket that uses an internet IPv4 address, + * Sets the socket to be stream based (TCP), + * 0 means choose the default protocol. */ + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + fprintf(stderr, "ERROR: failed to create the socket\n"); + ret = -1; + goto end; + } + printf("sockfd = %d\n", sockfd); + /* Initialize the server address struct with zeros */ + memset(&servAddr, 0, sizeof(servAddr)); + + /* Fill in the server address */ + servAddr.sin_family = AF_INET; /* using IPv4 */ + servAddr.sin_port = htons(DEFAULT_PORT); /* on DEFAULT_PORT */ + servAddr.sin_addr.s_addr = INADDR_ANY; /* from anywhere */ + printf("binding\n"); + /* Bind the server socket to our port */ + if (bind(sockfd, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) + { + fprintf(stderr, "ERROR: failed to bind\n"); + ret = -1; + goto servsocket_cleanup; + } + printf("listening\n"); + /* Listen for a new connection, allow 5 pending connections */ + if (listen(sockfd, 5) < 0) + { + fprintf(stderr, "ERROR: failed to listen\n"); + ret = -1; + goto servsocket_cleanup; + } + + /* Continue to accept clients until shutdown is issued */ + while (!shutdown) + { + printf("Waiting for a connection...\n"); + + /* Accept client connections */ + if ((connd = accept(sockfd, (struct sockaddr *)&clientAddr, &size)) < 0) + { + fprintf(stderr, "ERROR: failed to accept the connection\n\n"); + ret = -1; + goto servsocket_cleanup; + } + + printf("Client connected successfully\n"); + + /* Read the client data into our buff array */ + memset(buff, 0, sizeof(buff)); + if ((ret = read(connd, buff, sizeof(buff) - 1)) < 0) + { + fprintf(stderr, "ERROR: failed to read\n"); + goto clientsocket_cleanup; + } + + /* Print to stdout any data the client sends */ + printf("Client: %s\n", buff); + + /* Check for server shutdown command */ + if (strncmp(buff, "shutdown", 8) == 0) + { + printf("Shutdown command issued!\n"); + shutdown = 1; + } + + /* Write our reply into buff */ + memset(buff, 0, sizeof(buff)); + memcpy(buff, reply, strlen(reply)); + len = strnlen(buff, sizeof(buff)); + + /* Reply back to the client */ + if ((ret = write(connd, buff, len)) != len) + { + fprintf(stderr, "ERROR: failed to write\n"); + goto clientsocket_cleanup; + } + + /* Cleanup after this connection */ + close(connd); /* Close the connection to the client */ + } + + printf("Shutdown complete\n"); + + /* Cleanup and return */ +clientsocket_cleanup: + close(connd); /* Close the connection to the client */ +servsocket_cleanup: + close(sockfd); /* Close the socket listening for clients */ +end: + return; /* Return reporting a success */ + +} + +void main(void) +{ + TaskHandle_t task_tcpServer; +#define STACK_SIZE (1024 * 16) + + int i; + + stdio_init_all(); + for (i = 0; i < 10; i++) + { + printf("Starting in %dSec.\n", 10 - i); + sleep_ms(1000); + } + + printf("Creating tcpServer task, stack = %d\n", STACK_SIZE); + xTaskCreate(tcpServer_test, "WifiMainThread", STACK_SIZE, NULL, + CYW43_TASK_PRIORITY + 1, &task_tcpServer); + vTaskStartScheduler(); +} \ No newline at end of file diff --git a/RPi-Pico/src/test_main.c b/RPi-Pico/src/test_main.c index 8c224a6a..60e1435d 100644 --- a/RPi-Pico/src/test_main.c +++ b/RPi-Pico/src/test_main.c @@ -36,7 +36,9 @@ int main(int argc, char **argv) int ret; blink(10, WOLF_BLINK_INIT); - + printf("\nHit any key to start\n"); + getchar(); + wolfSSL_Init(); wolfSSL_Debugging_ON(); diff --git a/RPi-Pico/src/time.c b/RPi-Pico/src/time.c new file mode 100644 index 00000000..6866b9e8 --- /dev/null +++ b/RPi-Pico/src/time.c @@ -0,0 +1,44 @@ + +#include +#include +#include "pico/stdlib.h" + +#include +#include "FreeRTOS.h" +#include "task.h" + +static long epoch_base; + +time_t myTime(time_t *tt) +{ + return epoch_base + (xTaskGetTickCount() / configTICK_RATE_HZ); +} + +int time_init() +{ + char datetime[] = DATETIME; + struct tm t; + + printf("Date/Time = %s\n", datetime); + + if(strlen(datetime) != 12) { + printf("Invalid Date/Time length(%s)\n", datetime); + return -1; + } + if (sscanf(datetime, "%02d%02d%02d%02d%02d%02d", + &t.tm_year, &t.tm_mon, &t.tm_mday, + &t.tm_hour, &t.tm_min, &t.tm_sec) != 6) { + printf("Invalid Date/Time(%s)\n", datetime); + return -1; + } + printf("%d, %d, %d, %d, %d, %d\n", + t.tm_year, t.tm_mon, t.tm_mday, + t.tm_hour, t.tm_min, &t.tm_sec); + if (t.tm_year < 70) + t.tm_year += 100; /* base year of 1900 */ + t.tm_mon--; + epoch_base = mktime(&t); + printf("epoch base = %d\n", epoch_base); + return 0; + +} diff --git a/RPi-Pico/src/tls.c b/RPi-Pico/src/tls.c new file mode 100644 index 00000000..b3aa87f1 --- /dev/null +++ b/RPi-Pico/src/tls.c @@ -0,0 +1,135 @@ +/* tls.c + * + * Copyright (C) 2006-2023 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL 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 2 of the License, or + * (at your option) any later version. + * + * wolfSSL 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include "lwip/init.h" +#include "lwip/sockets.h" + +#include "wolfssl/wolfcrypt/settings.h" +#include "wolfssl/ssl.h" + +int my_IORecv(WOLFSSL *ssl, char *buff, int sz, void *ctx) +{ + /* By default, ctx will be a pointer to the file descriptor to read from. + * This can be changed by calling wolfSSL_SetIOReadCtx(). */ + int sockfd = *(int *)ctx; + int recvd; + + /* Receive message from socket */ + if ((recvd = recv(sockfd, buff, sz, 0)) == -1) + { + /* error encountered. Be responsible and report it in wolfSSL terms */ + + fprintf(stderr, "IO RECEIVE ERROR: "); + switch (errno) + { +#if EAGAIN != EWOULDBLOCK + case EAGAIN: /* EAGAIN == EWOULDBLOCK on some systems, but not others */ +#endif + case EWOULDBLOCK: + if (!wolfSSL_dtls(ssl) || wolfSSL_get_using_nonblock(ssl)) + { + fprintf(stderr, "would block\n"); + return WOLFSSL_CBIO_ERR_WANT_READ; + } + else + { + fprintf(stderr, "socket timeout\n"); + return WOLFSSL_CBIO_ERR_TIMEOUT; + } + case ECONNRESET: + fprintf(stderr, "connection reset\n"); + return WOLFSSL_CBIO_ERR_CONN_RST; + case EINTR: + fprintf(stderr, "socket interrupted\n"); + return WOLFSSL_CBIO_ERR_ISR; + case ECONNREFUSED: + fprintf(stderr, "connection refused\n"); + return WOLFSSL_CBIO_ERR_WANT_READ; + case ECONNABORTED: + fprintf(stderr, "connection aborted\n"); + return WOLFSSL_CBIO_ERR_CONN_CLOSE; + default: + fprintf(stderr, "general error\n"); + return WOLFSSL_CBIO_ERR_GENERAL; + } + } + else if (recvd == 0) + { + printf("Connection closed\n"); + return WOLFSSL_CBIO_ERR_CONN_CLOSE; + } + + /* successful receive */ + #ifdef WOLFSSL_DEBUG + printf("my_IORecv: received %d bytes from %d\n", sz, sockfd); + #endif + + return recvd; +} + +int my_IOSend(WOLFSSL *ssl, char *buff, int sz, void *ctx) +{ + /* By default, ctx will be a pointer to the file descriptor to write to. + * This can be changed by calling wolfSSL_SetIOWriteCtx(). */ + int sockfd = *(int *)ctx; + int sent; + + /* Receive message from socket */ + if ((sent = send(sockfd, buff, sz, 0)) == -1) + { + /* error encountered. Be responsible and report it in wolfSSL terms */ + + fprintf(stderr, "IO SEND ERROR: "); + switch (errno) + { +#if EAGAIN != EWOULDBLOCK + case EAGAIN: /* EAGAIN == EWOULDBLOCK on some systems, but not others */ +#endif + case EWOULDBLOCK: + fprintf(stderr, "would block\n"); + return WOLFSSL_CBIO_ERR_WANT_WRITE; + case ECONNRESET: + fprintf(stderr, "connection reset\n"); + return WOLFSSL_CBIO_ERR_CONN_RST; + case EINTR: + fprintf(stderr, "socket interrupted\n"); + return WOLFSSL_CBIO_ERR_ISR; + case EPIPE: + fprintf(stderr, "socket EPIPE\n"); + return WOLFSSL_CBIO_ERR_CONN_CLOSE; + default: + fprintf(stderr, "general error\n"); + return WOLFSSL_CBIO_ERR_GENERAL; + } + } + else if (sent == 0) + { + printf("Connection closed\n"); + return 0; + } + + /* successful send */ + #ifdef WOLFSSL_DEBUG + printf("my_IOSend: sent %d bytes to %d\n", sz, sockfd); + #endif + + return sent; +} diff --git a/RPi-Pico/src/tlsClient_main.c b/RPi-Pico/src/tlsClient_main.c index 7b384ea4..657d8aa2 100644 --- a/RPi-Pico/src/tlsClient_main.c +++ b/RPi-Pico/src/tlsClient_main.c @@ -23,173 +23,182 @@ #include "pico/stdlib.h" #include "pico/cyw43_arch.h" +#include "FreeRTOS.h" +#include "task.h" + +#include "lwip/init.h" +#include "lwip/sockets.h" + #include "wolfssl/wolfcrypt/settings.h" #include "wolfssl/ssl.h" -#include "wolf/common.h" -#include "wolf/tcp.h" #include "wolf/wifi.h" #include "wolf/blink.h" -#include "lwip/tcp.h" - -#include "wolfssl/wolfcrypt/settings.h" -#include "wolfssl/ssl.h" +#include "wolf/tcp.h" +#include "wolf/tls.h" +#include "wolf/time.h" #define USE_CERT_BUFFERS_256 #define USE_CERT_BUFFERS_2048 #include -#define TCP_PORT 1111 +#define TCP_PORT 11111 +#define WIFI_TASK_PRIORITY (tskIDLE_PRIORITY + 2UL) -int wolf_cb_TCPwrite(WOLFSSL *ssl, const unsigned char *buff, long unsigned int len, void *ctx) -{ - (void)ssl; - unsigned long ret; - SOCKET_T sock = (SOCKET_T)ctx; - ret = send(sock, buff, len); - return ret; -} - -int wolf_cb_TCPread(WOLFSSL *ssl, unsigned char *buff, long unsigned int len, void *ctx) -{ - (void)ssl; - SOCKET_T sock = (SOCKET_T)ctx; - int ret; - - ret = recv(sock, buff, len); - return ret; -} - -void tlsClient_test(void) +void tlsClient_test(void *arg) { + (void)arg; int i; int ret; #define BUFF_SIZE 2048 static char buffer[BUFF_SIZE]; char msg[] = "Hello Server"; - SOCKET_T sock; + int sock; struct sockaddr_in servAddr; WOLFSSL_CTX *ctx = NULL; WOLFSSL *ssl = NULL; - /* Initialize wolfSSL */ - wolfSSL_Init(); - wolfSSL_Debugging_ON(); + cyw43_arch_init(); - if ((ctx = wolfSSL_CTX_new((wolfTLSv1_2_client_method()))) == NULL) { - printf("ERROR:wolfSSL_CTX_new()\n"); + printf("Connecting to Wi-Fi...\n"); + if (wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, + CYW43_AUTH_WPA2_AES_PSK, 5000)) { + printf("failed to connect.\n"); return; } - /* Load client certificates into WOLFSSL_CTX */ - if ((ret = wolfSSL_CTX_load_verify_buffer(ctx, ca_cert_der_2048, - sizeof_ca_cert_der_2048, SSL_FILETYPE_ASN1)) != WOLFSSL_SUCCESS) { - printf("ERROR: failed to load CA cert. %d\n", ret); - goto exit; + else { + printf("Wifi connected.\n"); } - wolfSSL_SetIORecv(ctx, (CallbackIORecv)wolf_cb_TCPread); - wolfSSL_SetIOSend(ctx, (CallbackIOSend)wolf_cb_TCPwrite); - - sock = socket(); - if (!sock) - { - printf("ERROR:wolf_TCPsocke()\n"); - return; - } + lwip_init(); + tcp_initThread(); - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; /* using IPv4 */ - servAddr.sin_port = htons(TCP_PORT); /* on DEFAULT_PORT */ + /* Initialize wolfSSL */ + wolfSSL_Init(); + wolfSSL_Debugging_ON(); - if (inet_pton(AF_INET, TEST_TCP_SERVER_IP, &servAddr.sin_addr) != 1) { - fprintf(stderr, "ERROR: invalid address\n"); - goto exit; - } + printf("\nStarting tlsClient_test\n"); - if (connect(sock,(struct sockaddr*) &servAddr, sizeof(servAddr)) != WOLF_SUCCESS) { - printf("ERROR:wolf_TCPconnect()\n"); - goto exit; + if(time_init() < 0) { + printf("ERROR:time_init()\n"); + return; } - - if ((ssl = wolfSSL_new(ctx)) == NULL) { - fprintf(stderr, "ERROR: failed to create WOLFSSL object\n"); - ret = -1; - goto exit; + if ((ctx = wolfSSL_CTX_new((wolfTLSv1_2_client_method()))) == NULL) { + printf("ERROR:wolfSSL_CTX_new()\n"); + return; } - wolfSSL_SetIOReadCtx(ssl, sock); - wolfSSL_SetIOWriteCtx(ssl, sock); - - printf("TLS Connecting\n"); - if ((ret = wolfSSL_connect(ssl)) != WOLFSSL_SUCCESS) { - fprintf(stderr, "ERROR: failed to connect to wolfSSL(%d)\n", - wolfSSL_get_error(ssl, ret)); - goto exit; - } + printf("wolfSSL_CTX_new\n"); + /* Register callbacks */ + wolfSSL_CTX_SetIORecv(ctx, my_IORecv); + wolfSSL_CTX_SetIOSend(ctx, my_IOSend); - printf("Writing to server: %s\n", msg); - ret = wolfSSL_write(ssl, msg, strlen(msg)); - if (ret < 0) { - DEBUG_printf("Failed to write data. err=%d\n", ret); + /* Load client certificates into WOLFSSL_CTX */ + if ((ret = wolfSSL_CTX_load_verify_buffer(ctx, ca_cert_der_2048, + sizeof_ca_cert_der_2048, SSL_FILETYPE_ASN1)) != WOLFSSL_SUCCESS) { + printf("ERROR: failed to load CA cert. %d\n", ret); goto exit; } - ret = wolfSSL_read(ssl, buffer, BUFF_SIZE); - if (ret < 0) { - DEBUG_printf("Failed to read data. err=%d\n", ret); - goto exit; + printf("wolfSSL_CTX_load_verify_buffer\n"); + + for(i=0; i<10; i++) { + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + printf("ERROR:wolf_TCPsocke()\n"); + return; + } + + printf("Retured from socket\n"); + + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; /* using IPv4 */ + servAddr.sin_port = htons(TCP_PORT); /* on DEFAULT_PORT */ + + printf("Connecting to the server(%s)\n", TCP_SERVER); + if (inet_pton(AF_INET, TCP_SERVER, &servAddr.sin_addr) != 1) { + fprintf(stderr, "ERROR: invalid address\n"); + goto exit; + } + + if ((ret = connect(sock, (struct sockaddr *)&servAddr, + sizeof(servAddr))) != EXIT_SUCCESS) { + printf("ERROR:connect(%d)\n", ret); + goto exit; + } + + printf("TCP connected\n"); + + if ((ssl = wolfSSL_new(ctx)) == NULL) { + fprintf(stderr, "ERROR: failed to create WOLFSSL object\n"); + ret = -1; + goto exit; + } + + if ((ret = wolfSSL_set_fd(ssl, sock)) != WOLFSSL_SUCCESS) { + fprintf(stderr, "ERROR: Failed to set the file descriptor\n"); + goto exit; + } + + printf("TLS Connecting\n"); + if ((ret = wolfSSL_connect(ssl)) != WOLFSSL_SUCCESS) { + fprintf(stderr, "ERROR: failed to connect to wolfSSL(%d)\n", + wolfSSL_get_error(ssl, ret)); + goto exit; + } + + printf("Writing to server: %s\n", msg); + ret = wolfSSL_write(ssl, msg, strlen(msg)); + if (ret < 0) { + printf("Failed to write data. err=%d\n", ret); + goto exit; + } + + ret = wolfSSL_read(ssl, buffer, BUFF_SIZE); + if (ret < 0) { + printf("Failed to read data. err=%d\n", ret); + goto exit; + } + printf("Message: %s\n", buffer); + + wolfSSL_free(ssl); + close(sock); } - printf("Message: %s\n", buffer); - + printf("End of TLS Client\n"); exit: if (ssl) - wolfSSL_free(ssl); /* Free the wolfSSL object */ - if (sock) - free(sock); /* Close the connection to the server */ + wolfSSL_free(ssl); + if (sock >= 0) + close(sock); if (ctx) - wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */ - wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */ + wolfSSL_CTX_free(ctx); + wolfSSL_Cleanup(); + while(1) + vTaskDelay(1000); } void main(void) { - blink(20, 1); - - cyw43_arch_enable_sta_mode(); - printf("Connecting to Wi-Fi...\n"); - printf("WIFI_SSID=%s, WIFI_PASSWORD=%s\n", WIFI_SSID, WIFI_PASSWORD); - if (wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000)) { - printf("failed to connect.\n"); - return; - } else { - printf("Wifi connected.\n"); - } - cyw43_arch_lwip_begin(); - - printf("Starting TLS client\n"); - tlsClient_test(); - printf("End of TLS client\n"); + TaskHandle_t task_tlsClient; +#define STACK_SIZE (1024 * 16) - cyw43_arch_lwip_end(); - cyw43_arch_deinit(); - - printf("Wifi disconnected\n"); -} + int i; -void lwip_example_app_platform_assert(const char *msg, int line, const char *file) -{ - printf("Assertion \"%s\" failed at line %d in %s\n", msg, line, file); - fflush(NULL); -} + stdio_init_all(); + for (i = 0; i < 10; i++) + { + printf("Starting in %dSec.\n", 10 - i); + sleep_ms(1000); + } -#include -time_t myTime(time_t *t) -{ - *t = (((2023 - 1970) * 365 + (8 * 30)) * 24 * 60 * 60); - return *t; + printf("Creating tlsClient task, stack = %d\n", STACK_SIZE); + xTaskCreate(tlsClient_test, "TLS_MainThread", STACK_SIZE, NULL, + CYW43_TASK_PRIORITY + 1, &task_tlsClient); + vTaskStartScheduler(); } \ No newline at end of file diff --git a/RPi-Pico/src/tlsServer_main.c b/RPi-Pico/src/tlsServer_main.c new file mode 100644 index 00000000..a1935fe8 --- /dev/null +++ b/RPi-Pico/src/tlsServer_main.c @@ -0,0 +1,262 @@ +/* server-tls.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. (formerly known as CyaSSL) + * + * wolfSSL 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 2 of the License, or + * (at your option) any later version. + * + * wolfSSL 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include "pico/stdlib.h" +#include "pico/cyw43_arch.h" + +#include "FreeRTOS.h" +#include "task.h" + +#include "lwip/init.h" +#include "lwip/sockets.h" + +#include "wolfssl/wolfcrypt/settings.h" +#include "wolfssl/ssl.h" + +#include "wolf/wifi.h" +#include "wolf/blink.h" +#include "wolf/tcp.h" +#include "wolf/tls.h" +#include "wolf/time.h" + +#define USE_CERT_BUFFERS_256 +#define USE_CERT_BUFFERS_2048 +#include + +#define DEFAULT_PORT 11111 + +void tlsServer_test(void *arg) +{ + (void) arg; + int sockfd = SOCKET_INVALID; + int connd = SOCKET_INVALID; + struct sockaddr_in servAddr; + struct sockaddr_in clientAddr; + socklen_t size = sizeof(clientAddr); + char buff[256]; + size_t len; + int shutdown = 0; + int ret; + const char *reply = "I hear ya fa shizzle!\n"; + + /* declare wolfSSL objects */ + WOLFSSL_CTX *ctx = NULL; + WOLFSSL *ssl = NULL; + WOLFSSL_CIPHER *cipher; + + cyw43_arch_init(); + + printf("Connecting to Wi-Fi...\n"); + if (wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, + CYW43_AUTH_WPA2_AES_PSK, 5000)) { + printf("failed to connect.\n"); + return; + } + else { + printf("Wifi connected.\n"); + } + + lwip_init(); + tcp_initThread(); + + /* Initialize wolfSSL */ + wolfSSL_Init(); + wolfSSL_Debugging_ON(); + if(time_init() < 0) { + printf("ERROR:time_init()\n"); + return; + } + + printf("\nStarting tlsClient_test\n"); +#if 0 + wolfSSL_Debugging_ON(); +#endif + + /* Create a socket that uses an internet IPv4 address, + * Sets the socket to be stream based (TCP), + * 0 means choose the default protocol. */ + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) + { + fprintf(stderr, "ERROR: failed to create the socket\n"); + ret = -1; + goto exit; + } + + /* Create and initialize WOLFSSL_CTX */ +#ifdef USE_TLSV13 + ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()); +#else + ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()); +#endif + if (ctx == NULL) { + fprintf(stderr, "ERROR: failed to create WOLFSSL_CTX\n"); + ret = -1; + goto exit; + } + + /* Register callbacks */ + wolfSSL_CTX_SetIORecv(ctx, my_IORecv); + wolfSSL_CTX_SetIOSend(ctx, my_IOSend); + + /* Load server certificates into WOLFSSL_CTX */ + if ((ret = wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048, + sizeof_server_cert_der_2048, SSL_FILETYPE_ASN1)) != WOLFSSL_SUCCESS) { + fprintf(stderr, "ERROR: failed to loadserver_cert_der_2048.\n"); + goto exit; + } + + /* Load server key into WOLFSSL_CTX */ + if ((ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048, + sizeof_server_key_der_2048, SSL_FILETYPE_ASN1)) != WOLFSSL_SUCCESS) { + fprintf(stderr, "ERROR: failed to load server_key_der_2048\n"); + goto exit; + } + + /* Initialize the server address struct with zeros */ + memset(&servAddr, 0, sizeof(servAddr)); + + /* Fill in the server address */ + servAddr.sin_family = AF_INET; /* using IPv4 */ + servAddr.sin_port = htons(DEFAULT_PORT); /* on DEFAULT_PORT */ + servAddr.sin_addr.s_addr = INADDR_ANY; /* from anywhere */ + + /* Bind the server socket to our port */ + if (bind(sockfd, (struct sockaddr *)&servAddr, sizeof(servAddr)) == -1) { + fprintf(stderr, "ERROR: failed to bind\n"); + ret = -1; + goto exit; + } + + /* Listen for a new connection, allow 5 pending connections */ + if (listen(sockfd, 5) == -1) { + fprintf(stderr, "ERROR: failed to listen\n"); + ret = -1; + goto exit; + } + + /* Continue to accept clients until shutdown is issued */ + while (!shutdown) { + printf("Waiting for a connection...\n"); + + /* Accept client connections */ + if ((connd = accept(sockfd, (struct sockaddr *)&clientAddr, &size)) == -1) { + fprintf(stderr, "ERROR: failed to accept the connection\n\n"); + ret = -1; + goto exit; + } + + /* Create a WOLFSSL object */ + if ((ssl = wolfSSL_new(ctx)) == NULL) { + fprintf(stderr, "ERROR: failed to create WOLFSSL object\n"); + ret = -1; + goto exit; + } + + /* Attach wolfSSL to the socket */ + wolfSSL_set_fd(ssl, connd); + + /* Establish TLS connection */ + ret = wolfSSL_accept(ssl); + if (ret != WOLFSSL_SUCCESS) { + fprintf(stderr, "wolfSSL_accept error = %d\n", + wolfSSL_get_error(ssl, ret)); + goto exit; + } + + printf("Client connected successfully\n"); + + cipher = wolfSSL_get_current_cipher(ssl); + printf("SSL cipher suite is %s\n", wolfSSL_CIPHER_get_name(cipher)); + + /* Read the client data into our buff array */ + memset(buff, 0, sizeof(buff)); + if ((ret = wolfSSL_read(ssl, buff, sizeof(buff) - 1)) == -1) { + fprintf(stderr, "ERROR: failed to read\n"); + goto exit; + } + + /* Print to stdout any data the client sends */ + printf("Client: %s\n", buff); + + /* Check for server shutdown command */ + if (strncmp(buff, "shutdown", 8) == 0) { + printf("Shutdown command issued!\n"); + shutdown = 1; + } + + /* Write our reply into buff */ + memset(buff, 0, sizeof(buff)); + memcpy(buff, reply, strlen(reply)); + len = strnlen(buff, sizeof(buff)); + + /* Reply back to the client */ + if ((ret = wolfSSL_write(ssl, buff, len)) != len) { + fprintf(stderr, "ERROR: failed to write\n"); + goto exit; + } + + /* Notify the client that the connection is ending */ + wolfSSL_shutdown(ssl); + printf("Shutdown complete\n"); + + /* Cleanup after this connection */ + wolfSSL_free(ssl); /* Free the wolfSSL object */ + ssl = NULL; + close(connd); /* Close the connection to the client */ + } + + ret = 0; + +exit: + /* Cleanup and return */ + if (ssl) + wolfSSL_free(ssl); /* Free the wolfSSL object */ + if (connd != SOCKET_INVALID) + close(connd); /* Close the connection to the client */ + if (sockfd != SOCKET_INVALID) + close(sockfd); /* Close the socket listening for clients */ + if (ctx) + wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */ + wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */ + + return; /* Return reporting a success */ +} + +void main(void) +{ + TaskHandle_t task_tlsServer; +#define STACK_SIZE (1024 * 16) + + int i; + + stdio_init_all(); + for (i = 0; i < 10; i++) + { + printf("Starting in %dSec.\n", 10 - i); + sleep_ms(1000); + } + + printf("Creating tlsServer task, stack = %d\n", STACK_SIZE); + xTaskCreate(tlsServer_test, "TLS_MainThread", STACK_SIZE, NULL, + CYW43_TASK_PRIORITY + 1, &task_tlsServer); + vTaskStartScheduler(); +} \ No newline at end of file diff --git a/RPi-Pico/src/wifi.c b/RPi-Pico/src/wifi.c index c1642433..93a1c7c4 100644 --- a/RPi-Pico/src/wifi.c +++ b/RPi-Pico/src/wifi.c @@ -29,9 +29,9 @@ int wolf_wifiConnect(const char *ssid, const char *pw, uint32_t auth, uint32_t t { int retry; #define MAX_RETRY 5 - printf("Initializing Wi-Fi...\n"); + printf("Initializing Wi-Fi... %s, %s, %d\n", ssid, pw, auth); cyw43_arch_enable_sta_mode(); - + printf("Connecting to Wifi\n"); for(retry = 0; retry < MAX_RETRY; retry++) { if (cyw43_arch_wifi_connect_timeout_ms(ssid, pw, auth, timeout)) { fprintf(stderr, "failed to connect. Retrying\n"); diff --git a/RPi-Pico/src/wolfTcp.c b/RPi-Pico/src/wolfTcp.c new file mode 100644 index 00000000..14854645 --- /dev/null +++ b/RPi-Pico/src/wolfTcp.c @@ -0,0 +1,246 @@ +/* tcp.c + * + * Copyright (C) 2006-2023 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL 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 2 of the License, or + * (at your option) any later version. + * + * wolfSSL 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include +#include "pico/cyw43_arch.h" +#include "pico/stdlib.h" + +#include "wolf/tcp.h" + +#include "lwip/pbuf.h" +#include "lwip/tcp.h" + +#define TEST_ITERATIONS 10 +#define POLL_TIME_S 5 + +static void dump_bytes(const uint8_t *p, uint32_t len) +{ + for (; len; len--, p++) { + if (((unsigned long)p & 0x07) == 0) { + DEBUG_printf("\n"); + } + DEBUG_printf("%02x ", *p); + } + DEBUG_printf("\n"); +} + + +int wolf_TCPclose(WOLF_SOCKET_T sock) +{ + err_t err = ERR_OK; + if (sock->tcp_pcb != NULL) + { + tcp_arg(sock->tcp_pcb, NULL); + tcp_poll(sock->tcp_pcb, NULL, 0); + tcp_sent(sock->tcp_pcb, NULL); + tcp_recv(sock->tcp_pcb, NULL); + tcp_err(sock->tcp_pcb, NULL); + err = tcp_close(sock->tcp_pcb); + if (err != ERR_OK) { + DEBUG_printf("close failed %d, calling abort\n", err); + tcp_abort(sock->tcp_pcb); + err = ERR_ABRT; + } + sock->tcp_pcb = NULL; + } + free(sock); + return err; +} + +static err_t tcp_result(WOLF_SOCKET_T sock, int status) +{ + if (status == 0) { + DEBUG_printf("test success\n"); + } else { + DEBUG_printf("test failed %d\n", status); + } + sock->complete = true; + return 0; +} + +static err_t lwip_cb_client_sent(void *arg, struct tcp_pcb *tpcb, u16_t len) +{ + WOLF_SOCKET_T sock = (WOLF_SOCKET_T)arg; + + sock->sent_len += len; + + if (sock->sent_len >= BUF_SIZE) + { + + sock->run_count++; + if (sock->run_count >= TEST_ITERATIONS) + { + tcp_result(arg, 0); + return ERR_OK; + } + + // We should receive a new buffer from the server + sock->buffer_len = 0; + sock->sent_len = 0; + } + + return ERR_OK; +} + +static err_t lwip_cb_client_connected(void *arg, struct tcp_pcb *tpcb, err_t err) +{ + WOLF_SOCKET_T sock = (WOLF_SOCKET_T)arg; + + if (err != ERR_OK) + { + DEBUG_printf("connect failed %d\n", err); + return tcp_result(arg, err); + } + sock->connected = true; + return ERR_OK; +} + +static err_t lwip_cb_client_poll(void *arg, struct tcp_pcb *tpcb) +{ + return tcp_result(arg, 0); +} + +static void lwip_cb_client_err(void *arg, err_t err) +{ + if (err != ERR_ABRT) { + DEBUG_printf("tcp_client_err %d\n", err); + tcp_result(arg, err); + } +} + +static err_t lwip_cb_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) +{ + WOLF_SOCKET_T sock = (WOLF_SOCKET_T)arg; + if (!p) { + return ERR_OK; + } + + cyw43_arch_lwip_check(); + if (p->tot_len > 0) { + const uint16_t buffer_left = BUF_SIZE - sock->buffer_len; + sock->buffer_len += pbuf_copy_partial(p, sock->buffer + sock->buffer_len, + p->tot_len > buffer_left ? buffer_left : p->tot_len, 0); + tcp_recved(tpcb, p->tot_len); + } + pbuf_free(p); + return ERR_OK; +} + +int wolf_inet_pton(int af, const char *ip_str, void *ip_dst) +{ + (void)af; + struct sockaddr_in *addr = (struct sockaddr_in *)ip_dst; + + return ip4addr_aton(ip_str, ip_dst); +} + +static u32_t swapBytes(u16_t a) +{ + u8_t *p = (u8_t *)&a; + return p[0] << 8 | p[1]; +} + +int wolf_TCPconnect(WOLF_SOCKET_T sock, const struct sockaddr *addr, socklen_t addrlen) +{ + int err; + struct sockaddr_in *addr_in = (struct sockaddr_in *)addr; + + sock->tcp_pcb = tcp_new_ip_type(IP_GET_TYPE(&addr_in->sin_addr)); + if (!sock->tcp_pcb) { + DEBUG_printf("failed to create pcb\n"); + return false; + } + + tcp_arg(sock->tcp_pcb, sock); + tcp_poll(sock->tcp_pcb, lwip_cb_client_poll, POLL_TIME_S * 2); + tcp_sent(sock->tcp_pcb, lwip_cb_client_sent); + tcp_recv(sock->tcp_pcb, lwip_cb_client_recv); + tcp_err(sock->tcp_pcb, lwip_cb_client_err); + + sock->buffer_len = 0; + + cyw43_arch_lwip_begin(); + err = tcp_connect(sock->tcp_pcb, (const ip_addr_t *)&addr_in->sin_addr, + swapBytes(addr_in->sin_port), lwip_cb_client_connected); + cyw43_arch_lwip_end(); + if (err != ERR_OK) { + DEBUG_printf("wolf_TCPconnect: Failed"); + return WOLF_FAIL; + } + sock->connected = false; + + while (sock->connected != true) + { + cyw43_arch_poll(); + cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000)); + } + return WOLF_SUCCESS; +} + +// get a new TCP client +WOLF_SOCKET_T wolf_TCPsocket() +{ + WOLF_SOCKET_T sock = calloc(1, sizeof(*sock)); + if (!sock) { + DEBUG_printf("failed to allocate state\n"); + return NULL; + } + return sock; +} + +int wolf_TCPwrite(WOLF_SOCKET_T sock, const unsigned char *buff, long unsigned int len) +{ + int ret; + int i; + + sock->sent_len = 0; + ret = tcp_write(sock->tcp_pcb, buff, len, TCP_WRITE_FLAG_COPY); + + if (ret == ERR_OK) { + tcp_output(sock->tcp_pcb); + } + sock->sent_len = 0; + return (int)len; +} + +int wolf_TCPread(WOLF_SOCKET_T sock, unsigned char *buff, long unsigned int len) +{ + int recv_len; + int remained; + int i; + + while (1) { /* no timeout for now */ + if(sock->buffer_len > 0) { + recv_len = len <= sock->buffer_len ? len : sock->buffer_len; + memcpy(buff, sock->buffer, recv_len); + if(recv_len >= len) { + remained = sock->buffer_len - recv_len; + sock->buffer_len = remained; + for(i=0; ibuffer[i] = sock->buffer[i+recv_len]; + } else + sock->buffer_len = 0; + return recv_len; + } + cyw43_arch_poll(); + cyw43_arch_wait_for_work_until(make_timeout_time_ms(10)); + } +} \ No newline at end of file diff --git a/RPi-Pico/tcp_client/CMakeLists.txt b/RPi-Pico/tcp_client/CMakeLists.txt new file mode 100644 index 00000000..28957a7e --- /dev/null +++ b/RPi-Pico/tcp_client/CMakeLists.txt @@ -0,0 +1,29 @@ +add_executable(tcp_Client + ../src/blink.c + ../src/wifi.c + ../src/tcp.c + ../src/tcpClient_main.c + ../src/idleMemory.c +) + +target_compile_definitions(tcp_Client PRIVATE + WIFI_SSID=\"${WIFI_SSID}\" + WIFI_PASSWORD=\"${WIFI_PASSWORD}\" + TCP_SERVER=\"${TCP_SERVER}\" + NO_SYS=0 + LWIP_SOCKET + LWIP_COMPAT_SOCKETS + PING_USE_SOCKETS=1 +) + +target_link_libraries(tcp_Client + pico_stdlib + pico_rand + pico_cyw43_arch_lwip_sys_freertos + FreeRTOS-Kernel-Heap4 +) + +pico_enable_stdio_usb(tcp_Client 1) +pico_enable_stdio_uart(tcp_Client 1) + +pico_add_extra_outputs(tcp_Client) \ No newline at end of file diff --git a/RPi-Pico/tcp_server/CMakeLists.txt b/RPi-Pico/tcp_server/CMakeLists.txt new file mode 100644 index 00000000..8aac8eb9 --- /dev/null +++ b/RPi-Pico/tcp_server/CMakeLists.txt @@ -0,0 +1,28 @@ +add_executable(tcp_Server + ../src/blink.c + ../src/wifi.c + ../src/tcp.c + ../src/tcpServer_main.c + ../src/idleMemory.c + ) + +target_compile_definitions(tcp_Server PRIVATE + WIFI_SSID=\"${WIFI_SSID}\" + WIFI_PASSWORD=\"${WIFI_PASSWORD}\" + NO_SYS=0 + LWIP_SOCKET + LWIP_COMPAT_SOCKETS + PING_USE_SOCKETS=1 +) + +target_link_libraries(tcp_Server + pico_stdlib + pico_rand + pico_cyw43_arch_lwip_sys_freertos + FreeRTOS-Kernel-Heap4 +) + +pico_enable_stdio_usb(tcp_Server 1) +pico_enable_stdio_uart(tcp_Server 1) + +pico_add_extra_outputs(tcp_Server) \ No newline at end of file diff --git a/RPi-Pico/testwolfcrypt/CMakeLists.txt b/RPi-Pico/testwolfcrypt/CMakeLists.txt new file mode 100644 index 00000000..1c0c1bc4 --- /dev/null +++ b/RPi-Pico/testwolfcrypt/CMakeLists.txt @@ -0,0 +1,17 @@ +add_executable(testwolfcrypt + ../src/test_main.c + ../src/blink.c + ${WOLFSSL_ROOT}/wolfcrypt/test/test.c +) + +target_link_libraries(testwolfcrypt + wolfssl + pico_stdlib + pico_cyw43_arch_none + pico_rand +) + +pico_enable_stdio_usb(testwolfcrypt 1) +pico_enable_stdio_uart(testwolfcrypt 1) + +pico_add_extra_outputs(testwolfcrypt) \ No newline at end of file diff --git a/RPi-Pico/tls_client/CMakeLists.txt b/RPi-Pico/tls_client/CMakeLists.txt new file mode 100644 index 00000000..1dacba14 --- /dev/null +++ b/RPi-Pico/tls_client/CMakeLists.txt @@ -0,0 +1,34 @@ +add_executable(tls_Client + ../src/blink.c + ../src/wifi.c + ../src/tcp.c + ../src/tls.c + ../src/time.c + ../src/idleMemory.c + ../src/tlsClient_main.c +) + +target_compile_definitions(tls_Client PRIVATE + WIFI_SSID=\"${WIFI_SSID}\" + WIFI_PASSWORD=\"${WIFI_PASSWORD}\" + TCP_SERVER=\"${TCP_SERVER}\" + NO_SYS=0 + LWIP_SOCKET=1 + LWIP_COMPAT_SOCKETS=1 + PING_USE_SOCKETS=1 + DATETIME=\"${DATETIME}\" + WOLFSSL_USER_SETTINGS +) + +target_link_libraries(tls_Client + pico_stdlib + pico_rand + pico_cyw43_arch_lwip_sys_freertos + FreeRTOS-Kernel-Heap4 + wolfssl +) + +pico_enable_stdio_usb(tls_Client 1) +pico_enable_stdio_uart(tls_Client 1) + +pico_add_extra_outputs(tls_Client) \ No newline at end of file diff --git a/RPi-Pico/tls_server/CMakeLists.txt b/RPi-Pico/tls_server/CMakeLists.txt new file mode 100644 index 00000000..dc37d26f --- /dev/null +++ b/RPi-Pico/tls_server/CMakeLists.txt @@ -0,0 +1,33 @@ +add_executable(tls_Server + ../src/blink.c + ../src/wifi.c + ../src/tcp.c + ../src/tls.c + ../src/time.c + ../src/idleMemory.c + ../src/tlsServer_main.c +) + +target_compile_definitions(tls_Server PRIVATE + WIFI_SSID=\"${WIFI_SSID}\" + WIFI_PASSWORD=\"${WIFI_PASSWORD}\" + NO_SYS=0 + LWIP_SOCKET=1 + LWIP_COMPAT_SOCKETS=1 + PING_USE_SOCKETS=1 + DATETIME=\"${DATETIME}\" + WOLFSSL_USER_SETTINGS +) + +target_link_libraries(tls_Server + pico_stdlib + pico_rand + pico_cyw43_arch_lwip_sys_freertos + FreeRTOS-Kernel-Heap4 + wolfssl +) + +pico_enable_stdio_usb(tls_Server 1) +pico_enable_stdio_uart(tls_Server 1) + +pico_add_extra_outputs(tls_Server) \ No newline at end of file diff --git a/RPi-Pico/wolfssl_import.cmake b/RPi-Pico/wolfssl_import.cmake new file mode 100644 index 00000000..48c3e840 --- /dev/null +++ b/RPi-Pico/wolfssl_import.cmake @@ -0,0 +1,34 @@ + +set(WOLFSSL_ROOT $ENV{WOLFSSL_ROOT}) + +# ## wolfSSL/wolfCrypt library +file(GLOB WOLFSSL_SRC + "${WOLFSSL_ROOT}/src/*.c" + "${WOLFSSL_ROOT}/wolfcrypt/src/*.c" +) + +file(GLOB WOLFSSL_EXCLUDE + "${WOLFSSL_ROOT}/src/bio.c" + "${WOLFSSL_ROOT}/src/conf.c" + "${WOLFSSL_ROOT}/src/pk.c" + "${WOLFSSL_ROOT}/src/x509.c" + "${WOLFSSL_ROOT}/src/ssl_*.c" + "${WOLFSSL_ROOT}/src/x509_*.c" + "${WOLFSSL_ROOT}/wolfcrypt/src/misc.c" + "${WOLFSSL_ROOT}/wolfcrypt/src/evp.c" +) + +foreach(WOLFSSL_EXCLUDE ${WOLFSSL_EXCLUDE}) + list(REMOVE_ITEM WOLFSSL_SRC ${WOLFSSL_EXCLUDE}) +endforeach() + +add_library(wolfssl STATIC + ${WOLFSSL_SRC} +) + +include_directories(${WOLFSSL_ROOT}) + +target_compile_definitions(wolfssl PUBLIC + WOLFSSL_USER_SETTINGS +) +### End of wolfSSL/wolfCrypt library From a81f9393a2dd5dc72d46b8f93171e08ea81aa1a1 Mon Sep 17 00:00:00 2001 From: yota Date: Thu, 5 Sep 2024 19:06:28 +0900 Subject: [PATCH 2/4] Fix detail fix config Fix detail --- RPi-Pico/README.md | 1 + RPi-Pico/config/FreeRTOSConfig.h | 60 --------------- RPi-Pico/config/lwipopts.h | 53 +------------ RPi-Pico/config/lwipopts_examples_common.h | 90 ++++++++++++++++++++++ RPi-Pico/src/bench_main.c | 2 +- RPi-Pico/src/blink.c | 2 +- RPi-Pico/src/freertos_cb.c | 72 +++++++++++++++++ RPi-Pico/src/idleMemory.c | 74 ------------------ RPi-Pico/src/tcp.c | 2 +- RPi-Pico/src/tcpClient_main.c | 3 +- RPi-Pico/src/tcpServer_main.c | 3 +- RPi-Pico/src/test_main.c | 2 +- RPi-Pico/src/tls.c | 2 +- RPi-Pico/src/tlsClient_main.c | 3 +- RPi-Pico/src/tlsServer_main.c | 3 +- RPi-Pico/src/wifi.c | 2 +- RPi-Pico/src/wolfTcp.c | 2 +- RPi-Pico/tcp_client/CMakeLists.txt | 3 +- RPi-Pico/tcp_server/CMakeLists.txt | 3 +- RPi-Pico/tls_client/CMakeLists.txt | 3 +- RPi-Pico/tls_server/CMakeLists.txt | 3 +- 21 files changed, 180 insertions(+), 208 deletions(-) create mode 100644 RPi-Pico/config/lwipopts_examples_common.h create mode 100644 RPi-Pico/src/freertos_cb.c delete mode 100644 RPi-Pico/src/idleMemory.c diff --git a/RPi-Pico/README.md b/RPi-Pico/README.md index 58ebdf2c..abd128a0 100644 --- a/RPi-Pico/README.md +++ b/RPi-Pico/README.md @@ -13,6 +13,7 @@ $ git clone https://github.com/wolfssl/wolfssl $ git clone https://github.com/wolfssl-jp/RPi-pico-w ``` + ### 2. Define path ``` diff --git a/RPi-Pico/config/FreeRTOSConfig.h b/RPi-Pico/config/FreeRTOSConfig.h index 89b42fdf..e95f1afe 100644 --- a/RPi-Pico/config/FreeRTOSConfig.h +++ b/RPi-Pico/config/FreeRTOSConfig.h @@ -1,45 +1,6 @@ -/* - * FreeRTOS V202111.00 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ - #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H -/*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. - * - * See http://www.freertos.org/a00110.html - *----------------------------------------------------------*/ - /* Scheduler Related */ #define configUSE_PREEMPTION 1 #define configUSE_TICKLESS_IDLE 0 @@ -80,28 +41,12 @@ #define configUSE_MALLOC_FAILED_HOOK 0 #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 -/* Run time and task stats gathering related definitions. */ -#define configGENERATE_RUN_TIME_STATS 0 -#define configUSE_TRACE_FACILITY 1 -#define configUSE_STATS_FORMATTING_FUNCTIONS 0 - -/* Co-routine related definitions. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES 1 - /* Software timer related definitions. */ #define configUSE_TIMERS 1 #define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) #define configTIMER_QUEUE_LENGTH 10 #define configTIMER_TASK_STACK_DEPTH 1024 -/* Interrupt nesting behaviour configuration. */ -/* -#define configKERNEL_INTERRUPT_PRIORITY [dependent of processor] -#define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application] -#define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application] -*/ - #if FREE_RTOS_KERNEL_SMP // set by the RP2040 SMP port of FreeRTOS /* SMP port only */ #define configNUM_CORES 2 @@ -110,10 +55,6 @@ #define configUSE_CORE_AFFINITY 1 #endif -/* RP2040 specific */ -#define configSUPPORT_PICO_SYNC_INTEROP 1 -#define configSUPPORT_PICO_TIME_INTEROP 1 - #include /* Define to trap errors during development. */ #define configASSERT(x) assert(x) @@ -137,6 +78,5 @@ to exclude the API function. */ #define INCLUDE_xTaskResumeFromISR 1 #define INCLUDE_xQueueGetMutexHolder 1 -/* A header file that defines trace macro can be included here. */ #endif /* FREERTOS_CONFIG_H */ diff --git a/RPi-Pico/config/lwipopts.h b/RPi-Pico/config/lwipopts.h index 355409cb..28afb551 100644 --- a/RPi-Pico/config/lwipopts.h +++ b/RPi-Pico/config/lwipopts.h @@ -5,7 +5,7 @@ // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) // // This example uses a common include to avoid repetition -//#include "lwipopts_examples_common.h" +#include "lwipopts_examples_common.h" #define TCPIP_THREAD_STACKSIZE (1024*10) #define DEFAULT_THREAD_STACKSIZE 1024*10 @@ -14,13 +14,9 @@ #define DEFAULT_ACCEPTMBOX_SIZE 8 #define LWIP_TIMEVAL_PRIVATE 0 -// not necessary, can be done either way -#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 - // ping_thread sets socket receive timeout, so enable this feature #define LWIP_SO_RCVTIMEO 1 - #define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_MPU_COMPATIBLE 0 @@ -30,53 +26,8 @@ #define MEMP_NUM_SYS_TIMEOUT 10 #define DEFAULT_TCP_RECVMBOX_SIZE 10 -// Common settings used in most of the pico_w examples -// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) -// allow override in some examples -//#if NO_SYS==0 -// #ifndef LWIP_SOCKET -// #define LWIP_SOCKET 1 -// #endif -//#endif -#if PICO_CYW43_ARCH_POLL -#define MEM_LIBC_MALLOC 1 -#else -// MEM_LIBC_MALLOC is incompatible with non polling versions -#define MEM_LIBC_MALLOC 0 -#endif -#define MEM_ALIGNMENT 4 +#undef MEM_SIZE #define MEM_SIZE 4000 * 10 -#define MEMP_NUM_TCP_SEG 32 -#define MEMP_NUM_ARP_QUEUE 10 -#define PBUF_POOL_SIZE 24 -#define LWIP_ARP 1 -#define LWIP_ETHERNET 1 -#define LWIP_ICMP 1 -#define LWIP_RAW 1 -#define TCP_WND (8 * TCP_MSS) -#define TCP_MSS 1460 -#define TCP_SND_BUF (8 * TCP_MSS) -#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) -#define LWIP_NETIF_STATUS_CALLBACK 1 -#define LWIP_NETIF_LINK_CALLBACK 1 -#define LWIP_NETIF_HOSTNAME 1 -#define LWIP_NETCONN 0 -#define MEM_STATS 0 -#define SYS_STATS 0 -#define MEMP_STATS 0 -#define LINK_STATS 0 -// #define ETH_PAD_SIZE 2 -#define LWIP_CHKSUM_ALGORITHM 3 -#define LWIP_DHCP 1 -#define LWIP_IPV4 1 - -#define LWIP_TCP 1 -#define LWIP_DNS 1 -#define LWIP_TCP_KEEPALIVE 1 -#define LWIP_NETIF_TX_SINGLE_PBUF 1 -#define DHCP_DOES_ARP_CHECK 0 -#define LWIP_DHCP_DOES_ACD_CHECK 0 - #endif diff --git a/RPi-Pico/config/lwipopts_examples_common.h b/RPi-Pico/config/lwipopts_examples_common.h new file mode 100644 index 00000000..496f7881 --- /dev/null +++ b/RPi-Pico/config/lwipopts_examples_common.h @@ -0,0 +1,90 @@ +#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H +#define _LWIPOPTS_EXAMPLE_COMMONH_H + + +// Common settings used in most of the pico_w examples +// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) + +// allow override in some examples +#ifndef NO_SYS +#define NO_SYS 1 +#endif +// allow override in some examples +#ifndef LWIP_SOCKET +#define LWIP_SOCKET 0 +#endif +#if PICO_CYW43_ARCH_POLL +#define MEM_LIBC_MALLOC 1 +#else +// MEM_LIBC_MALLOC is incompatible with non polling versions +#define MEM_LIBC_MALLOC 0 +#endif +#define MEM_ALIGNMENT 4 +#define MEM_SIZE 4000 +#define MEMP_NUM_TCP_SEG 32 +#define MEMP_NUM_ARP_QUEUE 10 +#define PBUF_POOL_SIZE 24 +#define LWIP_ARP 1 +#define LWIP_ETHERNET 1 +#define LWIP_ICMP 1 +#define LWIP_RAW 1 +#define TCP_WND (8 * TCP_MSS) +#define TCP_MSS 1460 +#define TCP_SND_BUF (8 * TCP_MSS) +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) +#define LWIP_NETIF_STATUS_CALLBACK 1 +#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_HOSTNAME 1 +#define LWIP_NETCONN 0 +#define MEM_STATS 0 +#define SYS_STATS 0 +#define MEMP_STATS 0 +#define LINK_STATS 0 +// #define ETH_PAD_SIZE 2 +#define LWIP_CHKSUM_ALGORITHM 3 +#define LWIP_DHCP 1 +#define LWIP_IPV4 1 +#define LWIP_TCP 1 +#define LWIP_UDP 1 +#define LWIP_DNS 1 +#define LWIP_TCP_KEEPALIVE 1 +#define LWIP_NETIF_TX_SINGLE_PBUF 1 +#define DHCP_DOES_ARP_CHECK 0 +#define LWIP_DHCP_DOES_ACD_CHECK 0 + +#ifndef NDEBUG +#define LWIP_DEBUG 1 +#define LWIP_STATS 1 +#define LWIP_STATS_DISPLAY 1 +#endif + +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define PPP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF + +#endif /* __LWIPOPTS_H__ */ \ No newline at end of file diff --git a/RPi-Pico/src/bench_main.c b/RPi-Pico/src/bench_main.c index 34314f18..c55e4b22 100644 --- a/RPi-Pico/src/bench_main.c +++ b/RPi-Pico/src/bench_main.c @@ -1,6 +1,6 @@ /* bench_main.c * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/RPi-Pico/src/blink.c b/RPi-Pico/src/blink.c index a814ab8f..7b8d978b 100644 --- a/RPi-Pico/src/blink.c +++ b/RPi-Pico/src/blink.c @@ -1,6 +1,6 @@ /* blink.c * - * Copyright (C) 2006-2023 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/RPi-Pico/src/freertos_cb.c b/RPi-Pico/src/freertos_cb.c new file mode 100644 index 00000000..3441ab14 --- /dev/null +++ b/RPi-Pico/src/freertos_cb.c @@ -0,0 +1,72 @@ +/* freertos-cb.c + * + * Copyright (C) 2006-2024 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL 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 2 of the License, or + * (at your option) any later version. + * + * wolfSSL 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include "FreeRTOS.h" +#include +#include + +void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, + StackType_t **ppxIdleTaskStackBuffer, + uint32_t *pulIdleTaskStackSize) +{ + + static StaticTask_t xIdleTaskTCB; + static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; + + + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + *ppxIdleTaskStackBuffer = uxIdleTaskStack; + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} + +void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, + StackType_t **ppxTimerTaskStackBuffer, + uint32_t *pulTimerTaskStackSize) +{ + + static StaticTask_t xTimerTaskTCB; + static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; + + *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; + *ppxTimerTaskStackBuffer = uxTimerTaskStack; + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; +} + +void vApplicationStackOverflowHook(TaskHandle_t xTask, + char *pcTaskName) +{ + printf("----------------------------------------------\n"); + printf("STACK OVERFLOW on %s\n", pcTaskName); + printf("----------------------------------------------\n"); + taskDISABLE_INTERRUPTS(); + for (;;) + ; +} + +void vAssertCalled(const char *pcFile, uint32_t ulLine) +{ + printf("----------------------------------------------\n"); + printf("ASSERT FAILED %s line: %d\n", pcFile, ulLine); + printf("----------------------------------------------\n"); + taskDISABLE_INTERRUPTS(); + for (;;) + ; +} diff --git a/RPi-Pico/src/idleMemory.c b/RPi-Pico/src/idleMemory.c deleted file mode 100644 index 615db56e..00000000 --- a/RPi-Pico/src/idleMemory.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "FreeRTOS.h" -#include -#include -/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an -implementation of vApplicationGetIdleTaskMemory() to provide the memory that is -used by the Idle task. */ -void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, - StackType_t **ppxIdleTaskStackBuffer, - uint32_t *pulIdleTaskStackSize) -{ - /* If the buffers to be provided to the Idle task are declared inside this - function then they must be declared static – otherwise they will be allocated on - the stack and so not exists after this function exits. */ - static StaticTask_t xIdleTaskTCB; - static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; - - /* Pass out a pointer to the StaticTask_t structure in which the Idle task’s - state will be stored. */ - *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; - - /* Pass out the array that will be used as the Idle task’s stack. */ - *ppxIdleTaskStackBuffer = uxIdleTaskStack; - - /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. - Note that, as the array is necessarily of type StackType_t, - configMINIMAL_STACK_SIZE is specified in words, not bytes. */ - *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; -} -/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the -application must provide an implementation of vApplicationGetTimerTaskMemory() -to provide the memory that is used by the Timer service task. */ -void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, - StackType_t **ppxTimerTaskStackBuffer, - uint32_t *pulTimerTaskStackSize) -{ - /* If the buffers to be provided to the Timer task are declared inside this - function then they must be declared static – otherwise they will be allocated on - the stack and so not exists after this function exits. */ - static StaticTask_t xTimerTaskTCB; - static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH]; - - /* Pass out a pointer to the StaticTask_t structure in which the Timer - task’s state will be stored. */ - *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; - - /* Pass out the array that will be used as the Timer task’s stack. */ - *ppxTimerTaskStackBuffer = uxTimerTaskStack; - - /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. - Note that, as the array is necessarily of type StackType_t, - configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */ - *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; -} - -void vApplicationStackOverflowHook(TaskHandle_t xTask, - char *pcTaskName) -{ - printf("----------------------------------------------\n"); - printf("STACK OVERFLOW on %s\n", pcTaskName); - printf("----------------------------------------------\n"); - taskDISABLE_INTERRUPTS(); - for (;;) - ; -} - -void vAssertCalled(const char *pcFile, uint32_t ulLine) -{ - printf("----------------------------------------------\n"); - printf("ASSERT FAILED %s line: %d\n", pcFile, ulLine); - printf("----------------------------------------------\n"); - taskDISABLE_INTERRUPTS(); - for (;;) - ; -} diff --git a/RPi-Pico/src/tcp.c b/RPi-Pico/src/tcp.c index 75722294..abff1a1f 100644 --- a/RPi-Pico/src/tcp.c +++ b/RPi-Pico/src/tcp.c @@ -1,6 +1,6 @@ /* tcp.c * - * Copyright (C) 2006-2023 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/RPi-Pico/src/tcpClient_main.c b/RPi-Pico/src/tcpClient_main.c index ee6d7850..f2bea020 100644 --- a/RPi-Pico/src/tcpClient_main.c +++ b/RPi-Pico/src/tcpClient_main.c @@ -1,6 +1,6 @@ /* tcpClient_main.c * - * Copyright (C) 2006-2023 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -30,7 +30,6 @@ #include "lwip/sockets.h" #include "wolf/wifi.h" -#include "wolf/blink.h" #include "wolf/tcp.h" #define TCP_PORT 11111 diff --git a/RPi-Pico/src/tcpServer_main.c b/RPi-Pico/src/tcpServer_main.c index 3888cb9e..a88c7412 100644 --- a/RPi-Pico/src/tcpServer_main.c +++ b/RPi-Pico/src/tcpServer_main.c @@ -1,6 +1,6 @@ /* server-tcp.c * - * Copyright (C) 2006-2020 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. (formerly known as CyaSSL) * @@ -30,7 +30,6 @@ #include "lwip/sockets.h" #include "wolf/wifi.h" -#include "wolf/blink.h" #include "wolf/tcp.h" #define DEFAULT_PORT 11111 diff --git a/RPi-Pico/src/test_main.c b/RPi-Pico/src/test_main.c index 60e1435d..e3be773c 100644 --- a/RPi-Pico/src/test_main.c +++ b/RPi-Pico/src/test_main.c @@ -1,6 +1,6 @@ /* bench_main.c * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/RPi-Pico/src/tls.c b/RPi-Pico/src/tls.c index b3aa87f1..7ff016e2 100644 --- a/RPi-Pico/src/tls.c +++ b/RPi-Pico/src/tls.c @@ -1,6 +1,6 @@ /* tls.c * - * Copyright (C) 2006-2023 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/RPi-Pico/src/tlsClient_main.c b/RPi-Pico/src/tlsClient_main.c index 657d8aa2..e4eb2ccf 100644 --- a/RPi-Pico/src/tlsClient_main.c +++ b/RPi-Pico/src/tlsClient_main.c @@ -1,6 +1,6 @@ /* tcpClient_main.c * - * Copyright (C) 2006-2023 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -33,7 +33,6 @@ #include "wolfssl/ssl.h" #include "wolf/wifi.h" -#include "wolf/blink.h" #include "wolf/tcp.h" #include "wolf/tls.h" #include "wolf/time.h" diff --git a/RPi-Pico/src/tlsServer_main.c b/RPi-Pico/src/tlsServer_main.c index a1935fe8..0c05aeea 100644 --- a/RPi-Pico/src/tlsServer_main.c +++ b/RPi-Pico/src/tlsServer_main.c @@ -1,6 +1,6 @@ /* server-tls.c * - * Copyright (C) 2006-2020 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. (formerly known as CyaSSL) * @@ -33,7 +33,6 @@ #include "wolfssl/ssl.h" #include "wolf/wifi.h" -#include "wolf/blink.h" #include "wolf/tcp.h" #include "wolf/tls.h" #include "wolf/time.h" diff --git a/RPi-Pico/src/wifi.c b/RPi-Pico/src/wifi.c index 93a1c7c4..69e57ac2 100644 --- a/RPi-Pico/src/wifi.c +++ b/RPi-Pico/src/wifi.c @@ -1,6 +1,6 @@ /* wifi.c * - * Copyright (C) 2006-2023 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/RPi-Pico/src/wolfTcp.c b/RPi-Pico/src/wolfTcp.c index 14854645..24442822 100644 --- a/RPi-Pico/src/wolfTcp.c +++ b/RPi-Pico/src/wolfTcp.c @@ -1,6 +1,6 @@ /* tcp.c * - * Copyright (C) 2006-2023 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/RPi-Pico/tcp_client/CMakeLists.txt b/RPi-Pico/tcp_client/CMakeLists.txt index 28957a7e..ededd412 100644 --- a/RPi-Pico/tcp_client/CMakeLists.txt +++ b/RPi-Pico/tcp_client/CMakeLists.txt @@ -1,9 +1,8 @@ add_executable(tcp_Client - ../src/blink.c ../src/wifi.c ../src/tcp.c ../src/tcpClient_main.c - ../src/idleMemory.c + ../src/freertos_cb.c ) target_compile_definitions(tcp_Client PRIVATE diff --git a/RPi-Pico/tcp_server/CMakeLists.txt b/RPi-Pico/tcp_server/CMakeLists.txt index 8aac8eb9..94f39823 100644 --- a/RPi-Pico/tcp_server/CMakeLists.txt +++ b/RPi-Pico/tcp_server/CMakeLists.txt @@ -1,9 +1,8 @@ add_executable(tcp_Server - ../src/blink.c ../src/wifi.c ../src/tcp.c ../src/tcpServer_main.c - ../src/idleMemory.c + ../src/freertos_cb.c ) target_compile_definitions(tcp_Server PRIVATE diff --git a/RPi-Pico/tls_client/CMakeLists.txt b/RPi-Pico/tls_client/CMakeLists.txt index 1dacba14..9e36b2c0 100644 --- a/RPi-Pico/tls_client/CMakeLists.txt +++ b/RPi-Pico/tls_client/CMakeLists.txt @@ -1,10 +1,9 @@ add_executable(tls_Client - ../src/blink.c ../src/wifi.c ../src/tcp.c ../src/tls.c ../src/time.c - ../src/idleMemory.c + ../src/freertos_cb.c ../src/tlsClient_main.c ) diff --git a/RPi-Pico/tls_server/CMakeLists.txt b/RPi-Pico/tls_server/CMakeLists.txt index dc37d26f..9a49465c 100644 --- a/RPi-Pico/tls_server/CMakeLists.txt +++ b/RPi-Pico/tls_server/CMakeLists.txt @@ -1,10 +1,9 @@ add_executable(tls_Server - ../src/blink.c ../src/wifi.c ../src/tcp.c ../src/tls.c ../src/time.c - ../src/idleMemory.c + ../src/freertos_cb.c ../src/tlsServer_main.c ) From b035b3a731eabca2f16143ec1ed11b7d356f02f8 Mon Sep 17 00:00:00 2001 From: yota Date: Wed, 18 Sep 2024 15:25:59 +0900 Subject: [PATCH 3/4] fixed typo and details & added macro Added new line --- RPi-Pico/benchmark/CMakeLists.txt | 2 +- RPi-Pico/config/lwipopts_examples_common.h | 2 +- RPi-Pico/config/user_settings.h | 14 +++++++------- RPi-Pico/include/wolf/blink.h | 2 +- RPi-Pico/include/wolf/common.h | 2 +- RPi-Pico/include/wolf/tls.h | 4 +++- RPi-Pico/include/wolf/wifi.h | 2 +- RPi-Pico/src/blink.c | 2 +- RPi-Pico/src/tcpServer_main.c | 2 +- RPi-Pico/src/test_main.c | 2 +- RPi-Pico/src/tlsClient_main.c | 2 +- RPi-Pico/src/tlsServer_main.c | 2 +- RPi-Pico/src/wolfTcp.c | 2 +- RPi-Pico/tcp_client/CMakeLists.txt | 2 +- RPi-Pico/tcp_server/CMakeLists.txt | 2 +- RPi-Pico/testwolfcrypt/CMakeLists.txt | 2 +- RPi-Pico/tls_client/CMakeLists.txt | 2 +- RPi-Pico/tls_server/CMakeLists.txt | 2 +- 18 files changed, 26 insertions(+), 24 deletions(-) diff --git a/RPi-Pico/benchmark/CMakeLists.txt b/RPi-Pico/benchmark/CMakeLists.txt index 9a3ee169..77e70cb7 100644 --- a/RPi-Pico/benchmark/CMakeLists.txt +++ b/RPi-Pico/benchmark/CMakeLists.txt @@ -18,4 +18,4 @@ target_compile_definitions(benchmark PRIVATE pico_enable_stdio_usb(benchmark 1) pico_enable_stdio_uart(benchmark 1) -pico_add_extra_outputs(benchmark) \ No newline at end of file +pico_add_extra_outputs(benchmark) diff --git a/RPi-Pico/config/lwipopts_examples_common.h b/RPi-Pico/config/lwipopts_examples_common.h index 496f7881..217cb135 100644 --- a/RPi-Pico/config/lwipopts_examples_common.h +++ b/RPi-Pico/config/lwipopts_examples_common.h @@ -87,4 +87,4 @@ #define SLIP_DEBUG LWIP_DBG_OFF #define DHCP_DEBUG LWIP_DBG_OFF -#endif /* __LWIPOPTS_H__ */ \ No newline at end of file +#endif /* __LWIPOPTS_H__ */ diff --git a/RPi-Pico/config/user_settings.h b/RPi-Pico/config/user_settings.h index 98275312..bd955c06 100644 --- a/RPi-Pico/config/user_settings.h +++ b/RPi-Pico/config/user_settings.h @@ -294,9 +294,9 @@ extern time_t myTime(time_t *); #define USE_CERT_BUFFERS_2048 #endif - /* ------------------------------------------------------------------------- */ - /* Debugging */ - /* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ +/* Debugging */ +/* ------------------------------------------------------------------------- */ #undef DEBUG_WOLFSSL #undef NO_ERROR_STRINGS @@ -436,9 +436,9 @@ extern int my_rng_gen_block(unsigned char *output, unsigned int sz); #define XSNPRINTF snprintf #endif - /* ------------------------------------------------------------------------- */ - /* Enable Features */ - /* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ +/* Enable Features */ +/* ------------------------------------------------------------------------- */ #define WOLFSSL_TLS13 #define WOLFSSL_OLD_PRIME_CHECK /* Use faster DH prime checking */ @@ -466,7 +466,7 @@ extern int my_rng_gen_block(unsigned char *output, unsigned int sz); // #define NO_CRYPT_BENCHMARK // #define WOLFCRYPT_ONLY -/* do not warm when file is included to be built and not required to be */ +/* do not warn when file is included to be built and not required to be */ //define WOLFSSL_IGNORE_FILE_WARN /* In-lining of misc.c functions */ diff --git a/RPi-Pico/include/wolf/blink.h b/RPi-Pico/include/wolf/blink.h index bf3c2693..dbc3e86e 100644 --- a/RPi-Pico/include/wolf/blink.h +++ b/RPi-Pico/include/wolf/blink.h @@ -26,4 +26,4 @@ void blink(int n, int init); #define WOLF_BLINK_INIT 1 -#endif \ No newline at end of file +#endif diff --git a/RPi-Pico/include/wolf/common.h b/RPi-Pico/include/wolf/common.h index 473f7c6f..9a614518 100644 --- a/RPi-Pico/include/wolf/common.h +++ b/RPi-Pico/include/wolf/common.h @@ -25,4 +25,4 @@ #define WOLF_SUCCESS 0 #define WOLF_FAIL -1 -#endif \ No newline at end of file +#endif diff --git a/RPi-Pico/include/wolf/tls.h b/RPi-Pico/include/wolf/tls.h index cfbac1b3..810be473 100644 --- a/RPi-Pico/include/wolf/tls.h +++ b/RPi-Pico/include/wolf/tls.h @@ -22,7 +22,9 @@ #ifndef TLS_H #define TLS_H +#define SOCKET_INVALID -1 + int my_IORecv(WOLFSSL *ssl, char *buff, int sz, void *ctx); int my_IOSend(WOLFSSL *ssl, char *buff, int sz, void *ctx); -#endif \ No newline at end of file +#endif diff --git a/RPi-Pico/include/wolf/wifi.h b/RPi-Pico/include/wolf/wifi.h index eb498374..e858215c 100644 --- a/RPi-Pico/include/wolf/wifi.h +++ b/RPi-Pico/include/wolf/wifi.h @@ -25,4 +25,4 @@ int wolf_wifiConnect(const char *ssid, const char *pw, uint32_t auth, uint32_t timeout); int wolf_wifiDisconnect(void); -#endif \ No newline at end of file +#endif diff --git a/RPi-Pico/src/blink.c b/RPi-Pico/src/blink.c index 7b8d978b..fee8af47 100644 --- a/RPi-Pico/src/blink.c +++ b/RPi-Pico/src/blink.c @@ -55,4 +55,4 @@ void blink(int n, int init) cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); SLEEP_MS(250); } -} \ No newline at end of file +} diff --git a/RPi-Pico/src/tcpServer_main.c b/RPi-Pico/src/tcpServer_main.c index a88c7412..d499adce 100644 --- a/RPi-Pico/src/tcpServer_main.c +++ b/RPi-Pico/src/tcpServer_main.c @@ -175,4 +175,4 @@ void main(void) xTaskCreate(tcpServer_test, "WifiMainThread", STACK_SIZE, NULL, CYW43_TASK_PRIORITY + 1, &task_tcpServer); vTaskStartScheduler(); -} \ No newline at end of file +} diff --git a/RPi-Pico/src/test_main.c b/RPi-Pico/src/test_main.c index e3be773c..b814dd43 100644 --- a/RPi-Pico/src/test_main.c +++ b/RPi-Pico/src/test_main.c @@ -52,4 +52,4 @@ time_t myTime(time_t *t) { *t = (((2023 - 1970) * 12 + 8) * 30 * 24 * 60 * 60); return *t; -} \ No newline at end of file +} diff --git a/RPi-Pico/src/tlsClient_main.c b/RPi-Pico/src/tlsClient_main.c index e4eb2ccf..6567a051 100644 --- a/RPi-Pico/src/tlsClient_main.c +++ b/RPi-Pico/src/tlsClient_main.c @@ -200,4 +200,4 @@ void main(void) xTaskCreate(tlsClient_test, "TLS_MainThread", STACK_SIZE, NULL, CYW43_TASK_PRIORITY + 1, &task_tlsClient); vTaskStartScheduler(); -} \ No newline at end of file +} diff --git a/RPi-Pico/src/tlsServer_main.c b/RPi-Pico/src/tlsServer_main.c index 0c05aeea..0afbcde8 100644 --- a/RPi-Pico/src/tlsServer_main.c +++ b/RPi-Pico/src/tlsServer_main.c @@ -258,4 +258,4 @@ void main(void) xTaskCreate(tlsServer_test, "TLS_MainThread", STACK_SIZE, NULL, CYW43_TASK_PRIORITY + 1, &task_tlsServer); vTaskStartScheduler(); -} \ No newline at end of file +} diff --git a/RPi-Pico/src/wolfTcp.c b/RPi-Pico/src/wolfTcp.c index 24442822..589d00c1 100644 --- a/RPi-Pico/src/wolfTcp.c +++ b/RPi-Pico/src/wolfTcp.c @@ -243,4 +243,4 @@ int wolf_TCPread(WOLF_SOCKET_T sock, unsigned char *buff, long unsigned int len) cyw43_arch_poll(); cyw43_arch_wait_for_work_until(make_timeout_time_ms(10)); } -} \ No newline at end of file +} diff --git a/RPi-Pico/tcp_client/CMakeLists.txt b/RPi-Pico/tcp_client/CMakeLists.txt index ededd412..416de65d 100644 --- a/RPi-Pico/tcp_client/CMakeLists.txt +++ b/RPi-Pico/tcp_client/CMakeLists.txt @@ -25,4 +25,4 @@ target_link_libraries(tcp_Client pico_enable_stdio_usb(tcp_Client 1) pico_enable_stdio_uart(tcp_Client 1) -pico_add_extra_outputs(tcp_Client) \ No newline at end of file +pico_add_extra_outputs(tcp_Client) diff --git a/RPi-Pico/tcp_server/CMakeLists.txt b/RPi-Pico/tcp_server/CMakeLists.txt index 94f39823..5197a4bb 100644 --- a/RPi-Pico/tcp_server/CMakeLists.txt +++ b/RPi-Pico/tcp_server/CMakeLists.txt @@ -24,4 +24,4 @@ target_link_libraries(tcp_Server pico_enable_stdio_usb(tcp_Server 1) pico_enable_stdio_uart(tcp_Server 1) -pico_add_extra_outputs(tcp_Server) \ No newline at end of file +pico_add_extra_outputs(tcp_Server) diff --git a/RPi-Pico/testwolfcrypt/CMakeLists.txt b/RPi-Pico/testwolfcrypt/CMakeLists.txt index 1c0c1bc4..bdc6e481 100644 --- a/RPi-Pico/testwolfcrypt/CMakeLists.txt +++ b/RPi-Pico/testwolfcrypt/CMakeLists.txt @@ -14,4 +14,4 @@ target_link_libraries(testwolfcrypt pico_enable_stdio_usb(testwolfcrypt 1) pico_enable_stdio_uart(testwolfcrypt 1) -pico_add_extra_outputs(testwolfcrypt) \ No newline at end of file +pico_add_extra_outputs(testwolfcrypt) diff --git a/RPi-Pico/tls_client/CMakeLists.txt b/RPi-Pico/tls_client/CMakeLists.txt index 9e36b2c0..ab365cc4 100644 --- a/RPi-Pico/tls_client/CMakeLists.txt +++ b/RPi-Pico/tls_client/CMakeLists.txt @@ -30,4 +30,4 @@ target_link_libraries(tls_Client pico_enable_stdio_usb(tls_Client 1) pico_enable_stdio_uart(tls_Client 1) -pico_add_extra_outputs(tls_Client) \ No newline at end of file +pico_add_extra_outputs(tls_Client) diff --git a/RPi-Pico/tls_server/CMakeLists.txt b/RPi-Pico/tls_server/CMakeLists.txt index 9a49465c..aef5e287 100644 --- a/RPi-Pico/tls_server/CMakeLists.txt +++ b/RPi-Pico/tls_server/CMakeLists.txt @@ -29,4 +29,4 @@ target_link_libraries(tls_Server pico_enable_stdio_usb(tls_Server 1) pico_enable_stdio_uart(tls_Server 1) -pico_add_extra_outputs(tls_Server) \ No newline at end of file +pico_add_extra_outputs(tls_Server) From 8473b61de34a0066598f3f4802233040fc313438 Mon Sep 17 00:00:00 2001 From: yota Date: Wed, 18 Sep 2024 16:51:17 +0900 Subject: [PATCH 4/4] Added final newline --- RPi-Pico/src/bench_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RPi-Pico/src/bench_main.c b/RPi-Pico/src/bench_main.c index c55e4b22..a670323a 100644 --- a/RPi-Pico/src/bench_main.c +++ b/RPi-Pico/src/bench_main.c @@ -52,4 +52,4 @@ time_t myTime(time_t *t) { *t = (((2023 - 1970) * 12 + 8) * 30 * 24 * 60 * 60); return *t; -} \ No newline at end of file +}