Refator CMakelists.txt
parent
3724feec1f
commit
2c423825ff
|
@ -13,182 +13,186 @@ endif()
|
|||
project(wolf_pico_examples C CXX ASM)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
|
||||
|
||||
# Initialize the SDK
|
||||
pico_sdk_init()
|
||||
|
||||
include_directories(config)
|
||||
include_directories(include)
|
||||
include_directories(${PICO_SDK_PATH}/src/rp2_common/pico_lwip/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(${WOLFSSL_ROOT})
|
||||
### 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}/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)
|
||||
|
||||
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"
|
||||
)
|
||||
set(WOLFSSL_ROOT $ENV{WOLFSSL_ROOT})
|
||||
include_directories(${WOLFSSL_ROOT})
|
||||
### End of Global Include Path
|
||||
|
||||
add_library(wolfssl STATIC
|
||||
${WOLFSSL_SRC}
|
||||
)
|
||||
target_include_directories(wolfssl PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/config
|
||||
|
||||
### wolfSSL/wolfCrypt library
|
||||
file(GLOB_RECURSE WOLFSSL_SRC
|
||||
"${WOLFSSL_ROOT}/src/*.c"
|
||||
"${WOLFSSL_ROOT}/wolfcrypt/src/*.c"
|
||||
)
|
||||
target_compile_definitions(wolfssl PRIVATE
|
||||
WOLFSSL_USER_SETTINGS
|
||||
WOLFSSL_SP_ARM_THUMB_ASM
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
add_executable(testwolfcrypt
|
||||
src/test_main.c
|
||||
src/blink.c
|
||||
${WOLFSSL_ROOT}/wolfcrypt/test/test.c
|
||||
)
|
||||
### Test wolfCrypt algorithms
|
||||
add_executable(testwolfcrypt
|
||||
src/test_main.c
|
||||
src/blink.c
|
||||
${WOLFSSL_ROOT}/wolfcrypt/test/test.c
|
||||
)
|
||||
|
||||
pico_enable_stdio_usb(testwolfcrypt 1)
|
||||
pico_enable_stdio_uart(testwolfcrypt 0)
|
||||
target_compile_definitions(testwolfcrypt PRIVATE
|
||||
WOLFSSL_USER_SETTINGS
|
||||
)
|
||||
target_link_libraries(testwolfcrypt
|
||||
wolfssl
|
||||
pico_stdlib
|
||||
pico_cyw43_arch_none
|
||||
pico_rand
|
||||
)
|
||||
|
||||
target_link_libraries(testwolfcrypt
|
||||
wolfssl
|
||||
pico_stdlib
|
||||
pico_cyw43_arch_none
|
||||
pico_rand
|
||||
)
|
||||
pico_add_extra_outputs(testwolfcrypt)
|
||||
pico_enable_stdio_usb(testwolfcrypt 1)
|
||||
pico_enable_stdio_uart(testwolfcrypt 0)
|
||||
|
||||
pico_add_extra_outputs(testwolfcrypt)
|
||||
### End of Test wolfCrypt algorithms
|
||||
|
||||
|
||||
add_executable(benchmark
|
||||
src/bench_main.c
|
||||
src/blink.c
|
||||
${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c
|
||||
)
|
||||
### Benchmark wolfCrypt algorithms
|
||||
add_executable(benchmark
|
||||
src/bench_main.c
|
||||
src/blink.c
|
||||
${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c
|
||||
)
|
||||
|
||||
pico_enable_stdio_usb(benchmark 1)
|
||||
pico_enable_stdio_uart(benchmark 0)
|
||||
target_compile_definitions(benchmark PRIVATE
|
||||
WOLFSSL_USER_SETTINGS
|
||||
)
|
||||
target_link_libraries(benchmark
|
||||
wolfssl
|
||||
pico_stdlib
|
||||
pico_cyw43_arch_none
|
||||
pico_rand
|
||||
)
|
||||
|
||||
target_link_libraries(benchmark
|
||||
wolfssl
|
||||
pico_stdlib
|
||||
pico_cyw43_arch_none
|
||||
pico_rand
|
||||
)
|
||||
pico_add_extra_outputs(benchmark)
|
||||
pico_enable_stdio_usb(benchmark 1)
|
||||
pico_enable_stdio_uart(benchmark 0)
|
||||
|
||||
pico_add_extra_outputs(benchmark)
|
||||
### End of Benchmark wolfCrypt algorithms
|
||||
|
||||
|
||||
add_executable(Wifi
|
||||
src/blink.c
|
||||
src/wifi.c
|
||||
src/Wifi_main.c
|
||||
)
|
||||
### Wifi connection
|
||||
add_executable(Wifi
|
||||
src/blink.c
|
||||
src/wifi.c
|
||||
src/Wifi_main.c
|
||||
)
|
||||
|
||||
# enable usb output, disable uart output
|
||||
pico_enable_stdio_usb(Wifi 1)
|
||||
pico_enable_stdio_uart(Wifi 0)
|
||||
target_compile_definitions(Wifi PRIVATE
|
||||
WIFI_SSID=\"${WIFI_SSID}\"
|
||||
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
|
||||
PICO_CYW43_ARCH_POLL
|
||||
NO_SYS=1
|
||||
)
|
||||
|
||||
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_add_extra_outputs(Wifi)
|
||||
|
||||
add_executable(tcp_Client
|
||||
src/blink.c
|
||||
src/wifi.c
|
||||
src/tcp.c
|
||||
src/tcpClient_main.c
|
||||
)
|
||||
|
||||
# enable usb output, disable uart output
|
||||
pico_enable_stdio_usb(tcp_Client 1)
|
||||
pico_enable_stdio_uart(tcp_Client 0)
|
||||
|
||||
target_compile_definitions(tcp_Client PRIVATE
|
||||
WOLFSSL_USER_SETTINGS
|
||||
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_add_extra_outputs(tcp_Client)
|
||||
target_link_libraries(Wifi
|
||||
pico_stdlib
|
||||
pico_rand
|
||||
pico_lwip
|
||||
pico_cyw43_arch
|
||||
pico_lwip_nosys
|
||||
pico_async_context_poll
|
||||
)
|
||||
|
||||
|
||||
add_executable(tls_Client
|
||||
src/blink.c
|
||||
src/wifi.c
|
||||
src/tcp.c
|
||||
src/tlsClient_main.c
|
||||
)
|
||||
pico_enable_stdio_usb(Wifi 1)
|
||||
pico_enable_stdio_uart(Wifi 0)
|
||||
|
||||
# enable usb output, disable uart output
|
||||
pico_enable_stdio_usb(tls_Client 1)
|
||||
pico_enable_stdio_uart(tls_Client 0)
|
||||
pico_add_extra_outputs(Wifi)
|
||||
### End of Wifi connection
|
||||
|
||||
target_compile_definitions(tls_Client PRIVATE
|
||||
WOLFSSL_USER_SETTINGS
|
||||
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
|
||||
)
|
||||
### TCP Client
|
||||
add_executable(tcp_Client
|
||||
src/blink.c
|
||||
src/wifi.c
|
||||
src/tcp.c
|
||||
src/tcpClient_main.c
|
||||
)
|
||||
|
||||
pico_add_extra_outputs(tls_Client)
|
||||
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
|
||||
)
|
||||
|
||||
pico_enable_stdio_usb(tls_Client 1)
|
||||
pico_enable_stdio_uart(tls_Client 0)
|
||||
|
||||
pico_add_extra_outputs(tls_Client)
|
||||
### End of TLS Client
|
|
@ -89,7 +89,7 @@ extern time_t myTime(time_t *);
|
|||
// #define WOLFSSL_SP_X86
|
||||
// #define WOLFSSL_SP_ARM32_ASM
|
||||
// #define WOLFSSL_SP_ARM64_ASM
|
||||
// #define WOLFSSL_SP_ARM_THUMB_ASM
|
||||
#define WOLFSSL_SP_ARM_THUMB_ASM
|
||||
// #define WOLFSSL_SP_ARM_CORTEX_M_ASM
|
||||
#elif 1
|
||||
/* Fast Math (tfm.c) (stack based and timing resistant) */
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "pico/cyw43_arch.h"
|
||||
#include "wolf/blink.h"
|
||||
|
||||
|
||||
#include "hardware/clocks.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ int main(int argc, char **argv)
|
|||
int ret;
|
||||
|
||||
blink(10, WOLF_BLINK_INIT);
|
||||
printf("\nSystem clock = %dMHz\n\n", clock_get_hz(clk_sys)/1000000);
|
||||
ret = benchmark_test(NULL);
|
||||
printf("End: %d\n", ret);
|
||||
return ret;
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
#include "pico/cyw43_arch.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "wolfssl/wolfcrypt/settings.h"
|
||||
#include "wolfssl/ssl.h"
|
||||
#include "wolf/tcp.h"
|
||||
|
||||
#include "lwip/pbuf.h"
|
||||
|
@ -33,9 +31,6 @@
|
|||
#define TEST_ITERATIONS 10
|
||||
#define POLL_TIME_S 5
|
||||
|
||||
#define TEST_TASK_PRIORITY (tskIDLE_PRIORITY + 2UL)
|
||||
#define BLINK_TASK_PRIORITY (tskIDLE_PRIORITY + 1UL)
|
||||
|
||||
static void dump_bytes(const uint8_t *p, uint32_t len)
|
||||
{
|
||||
for (; len; len--, p++) {
|
||||
|
@ -84,7 +79,7 @@ static err_t tcp_result(WOLF_SOCKET_T *sock, int status)
|
|||
static err_t lwip_cb_client_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
|
||||
{
|
||||
WOLF_SOCKET_T *sock = (WOLF_SOCKET_T *)arg;
|
||||
DEBUG_printf("tcp_client_sent %u\n", len);
|
||||
|
||||
sock->sent_len += len;
|
||||
|
||||
if (sock->sent_len >= BUF_SIZE)
|
||||
|
@ -100,7 +95,6 @@ static err_t lwip_cb_client_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
|
|||
// We should receive a new buffer from the server
|
||||
sock->buffer_len = 0;
|
||||
sock->sent_len = 0;
|
||||
DEBUG_printf("Waiting for buffer from server\n");
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
|
@ -120,7 +114,7 @@ static err_t lwip_cb_client_connected(void *arg, struct tcp_pcb *tpcb, err_t err
|
|||
|
||||
static err_t lwip_cb_client_poll(void *arg, struct tcp_pcb *tpcb)
|
||||
{
|
||||
return tcp_result(arg, -1); // no response is an error?
|
||||
return tcp_result(arg, 0);
|
||||
}
|
||||
|
||||
static void lwip_cb_client_err(void *arg, err_t err)
|
||||
|
@ -135,7 +129,7 @@ static err_t lwip_cb_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
|
|||
{
|
||||
WOLF_SOCKET_T *sock = (WOLF_SOCKET_T *)arg;
|
||||
if (!p) {
|
||||
return tcp_result(arg, -1);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
cyw43_arch_lwip_check();
|
||||
|
@ -145,7 +139,6 @@ static err_t lwip_cb_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
|
|||
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);
|
||||
DEBUG_printf("sock->buffer_len = %d\n", sock->buffer_len);
|
||||
}
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
|
@ -154,8 +147,6 @@ static err_t lwip_cb_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
|
|||
bool wolf_TCPconnect(WOLF_SOCKET_T *sock, const char *ip, uint32_t port)
|
||||
{
|
||||
ip4addr_aton(ip, &sock->remote_addr);
|
||||
|
||||
DEBUG_printf("wolf_TCPconnect: Connecting to %s port %u\n", ip4addr_ntoa(&sock->remote_addr), port);
|
||||
sock->tcp_pcb = tcp_new_ip_type(IP_GET_TYPE(&sock->remote_addr));
|
||||
if (!sock->tcp_pcb) {
|
||||
DEBUG_printf("failed to create pcb\n");
|
||||
|
@ -173,9 +164,7 @@ bool wolf_TCPconnect(WOLF_SOCKET_T *sock, const char *ip, uint32_t port)
|
|||
cyw43_arch_lwip_begin();
|
||||
err_t err = tcp_connect(sock->tcp_pcb, &sock->remote_addr, port, lwip_cb_client_connected);
|
||||
cyw43_arch_lwip_end();
|
||||
if (err == ERR_OK)
|
||||
DEBUG_printf("wolf_TCPconnect: Connecting");
|
||||
else {
|
||||
if (err != ERR_OK) {
|
||||
DEBUG_printf("wolf_TCPconnect: Failed");
|
||||
return WOLF_FAIL;
|
||||
}
|
||||
|
@ -203,7 +192,6 @@ int wolf_TCPwrite(WOLF_SOCKET_T *sock, const unsigned char *buff, long unsigned
|
|||
int ret;
|
||||
int i;
|
||||
|
||||
DEBUG_printf("wolf_TCPread(%lx, %lx, %d)\n", sock, buff, len);
|
||||
sock->sent_len = 0;
|
||||
ret = tcp_write(sock->tcp_pcb, buff, len, TCP_WRITE_FLAG_COPY);
|
||||
|
||||
|
@ -211,11 +199,9 @@ int wolf_TCPwrite(WOLF_SOCKET_T *sock, const unsigned char *buff, long unsigned
|
|||
tcp_output(sock->tcp_pcb);
|
||||
}
|
||||
while(sock->sent_len < len) {
|
||||
putchar('>');
|
||||
cyw43_arch_poll();
|
||||
cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000));
|
||||
}
|
||||
putchar('\n');
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
|
@ -225,8 +211,6 @@ int wolf_TCPread(WOLF_SOCKET_T *sock, unsigned char *buff, long unsigned int len
|
|||
int remained;
|
||||
int i;
|
||||
#define POLLING 200
|
||||
|
||||
DEBUG_printf("wolf_TCPread(%lx, %lx, %d)\n", sock, buff, len);
|
||||
|
||||
for(i=0; i<POLLING; i++) {
|
||||
if(sock->buffer_len > 0) {
|
||||
|
@ -239,11 +223,8 @@ int wolf_TCPread(WOLF_SOCKET_T *sock, unsigned char *buff, long unsigned int len
|
|||
sock->buffer[i] = sock->buffer[i+recv_len];
|
||||
} else
|
||||
sock->buffer_len = 0;
|
||||
|
||||
DEBUG_printf("\n");
|
||||
return recv_len;
|
||||
}
|
||||
DEBUG_printf(">");
|
||||
cyw43_arch_poll();
|
||||
cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000));
|
||||
}
|
||||
|
|
|
@ -51,20 +51,19 @@ void tcpClient_test(void)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
DEBUG_printf("Writing to server: %s\n", msg);
|
||||
printf("Writing to server: %s\n", msg);
|
||||
err = wolf_TCPwrite(sock, msg, sizeof(msg));
|
||||
if (err < 0) {
|
||||
DEBUG_printf("Failed to write data. err=%d\n", err);
|
||||
goto exit;
|
||||
}
|
||||
DEBUG_printf("Writen data %d bytes\n", err);
|
||||
|
||||
err = wolf_TCPread(sock, buffer, BUFF_SIZE);
|
||||
if (err < 0) {
|
||||
DEBUG_printf("Failed to read data. err=%d\n", err);
|
||||
goto exit;
|
||||
}
|
||||
DEBUG_printf("Read data %d bytes: %s\n", err, buffer);
|
||||
printf("Message: %s\n", buffer);
|
||||
|
||||
exit:
|
||||
free(sock);
|
||||
|
@ -73,26 +72,26 @@ exit:
|
|||
void main(void)
|
||||
{
|
||||
blink(20, 1);
|
||||
printf("Started main_task\n");
|
||||
|
||||
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)) {
|
||||
if (wolf_wifiConnect(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
|
||||
printf("failed to connect.\n");
|
||||
return;
|
||||
} else {
|
||||
printf("Connected.\n");
|
||||
printf("Wifi connected.\n");
|
||||
}
|
||||
cyw43_arch_lwip_begin();
|
||||
printf("\nReady, running iperf client\n");
|
||||
|
||||
printf("Starting TCP client\n");
|
||||
tcpClient_test();
|
||||
printf("End of TCP client\n");
|
||||
|
||||
cyw43_arch_lwip_end();
|
||||
cyw43_arch_deinit();
|
||||
|
||||
printf("End of iperf client\n");
|
||||
printf("Wifi disconnected\n");
|
||||
}
|
||||
|
||||
void lwip_example_app_platform_assert(const char *msg, int line, const char *file)
|
||||
|
|
|
@ -46,10 +46,8 @@ int wolf_cb_TCPwrite(WOLFSSL *ssl, const unsigned char *buff, long unsigned int
|
|||
(void)ssl;
|
||||
unsigned long ret;
|
||||
WOLF_SOCKET_T *sock = (WOLF_SOCKET_T *)ctx;
|
||||
|
||||
printf("wolf_cb_TCPwrite(%lx, %d, %lx)\n", (unsigned long)buff, len, (unsigned long)ctx);
|
||||
ret = wolf_TCPwrite(sock, buff, len);
|
||||
printf("ret = %d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -59,9 +57,7 @@ int wolf_cb_TCPread(WOLFSSL *ssl, unsigned char *buff, long unsigned int len, vo
|
|||
WOLF_SOCKET_T *sock = (WOLF_SOCKET_T *)ctx;
|
||||
int ret;
|
||||
|
||||
printf("wolf_cb_TCPread(%lx, %d, %lx)\n", (unsigned long)buff, len, (unsigned long)ctx);
|
||||
ret = wolf_TCPread(sock, buff, len);
|
||||
printf("ret = %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -69,7 +65,7 @@ void tlsClient_test(void)
|
|||
{
|
||||
int i;
|
||||
int ret;
|
||||
#define BUFF_SIZE 2048
|
||||
#define BUFF_SIZE 2048
|
||||
static char buffer[BUFF_SIZE];
|
||||
char msg[] = "Hello Server";
|
||||
|
||||
|
@ -77,7 +73,6 @@ void tlsClient_test(void)
|
|||
WOLFSSL_CTX *ctx = NULL;
|
||||
WOLFSSL *ssl = NULL;
|
||||
|
||||
printf("tlsClient_test\n");
|
||||
/* Initialize wolfSSL */
|
||||
wolfSSL_Init();
|
||||
wolfSSL_Debugging_ON();
|
||||
|
@ -86,37 +81,34 @@ void tlsClient_test(void)
|
|||
printf("ERROR:wolfSSL_CTX_new()\n");
|
||||
return;
|
||||
}
|
||||
printf("wolfSSL_CTX_new: %lx\n", (unsigned long)ctx);
|
||||
/* 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;
|
||||
}
|
||||
printf("wolfSSL_SetIO: ");
|
||||
|
||||
wolfSSL_SetIORecv(ctx, (CallbackIORecv)wolf_cb_TCPread);
|
||||
wolfSSL_SetIOSend(ctx, (CallbackIOSend)wolf_cb_TCPwrite);
|
||||
printf("Done ");
|
||||
|
||||
if ((sock = wolf_TCPsocket()) == NULL) {
|
||||
printf("ERROR:wolf_TCPsocke()\n");
|
||||
return;
|
||||
}
|
||||
printf("wolf_TCPsocket: %lx\n", (unsigned long)sock);
|
||||
|
||||
if ((ret = wolf_TCPconnect(sock, TEST_TCP_SERVER_IP, TCP_PORT) != WOLF_SUCCESS)) {
|
||||
printf("ERROR:wolf_TCPconnect\n");
|
||||
goto exit;
|
||||
}
|
||||
printf("wolf_TCPconnect: %d\n", ret);
|
||||
|
||||
if ((ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to create WOLFSSL object\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
printf("wolfSSL_SetIOctx: ");
|
||||
|
||||
wolfSSL_SetIOReadCtx(ssl, sock);
|
||||
wolfSSL_SetIOWriteCtx(ssl, sock);
|
||||
printf("Done\n");
|
||||
|
||||
if ((ret = wolfSSL_connect(ssl)) != WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "ERROR: failed to connect to wolfSSL(%d)\n",
|
||||
|
@ -124,20 +116,19 @@ void tlsClient_test(void)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
DEBUG_printf("Writing to server: %s\n", msg);
|
||||
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);
|
||||
goto exit;
|
||||
}
|
||||
DEBUG_printf("Writen data %d bytes\n", ret);
|
||||
|
||||
ret = wolfSSL_read(ssl, buffer, BUFF_SIZE);
|
||||
if (ret < 0) {
|
||||
DEBUG_printf("Failed to read data. err=%d\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
DEBUG_printf("Read data %d bytes\nMessage: %s", ret, buffer);
|
||||
printf("Message: %s\n", buffer);
|
||||
|
||||
|
||||
exit:
|
||||
|
@ -154,7 +145,6 @@ exit:
|
|||
void main(void)
|
||||
{
|
||||
blink(20, 1);
|
||||
printf("Started main_task\n");
|
||||
|
||||
cyw43_arch_enable_sta_mode();
|
||||
printf("Connecting to Wi-Fi...\n");
|
||||
|
@ -163,17 +153,18 @@ void main(void)
|
|||
printf("failed to connect.\n");
|
||||
return;
|
||||
} else {
|
||||
printf("Connected.\n");
|
||||
printf("Wifi connected.\n");
|
||||
}
|
||||
cyw43_arch_lwip_begin();
|
||||
printf("\nReady, starting TLS client\n");
|
||||
|
||||
printf("Starting TLS client\n");
|
||||
tlsClient_test();
|
||||
printf("End of TLS client\n");
|
||||
|
||||
cyw43_arch_lwip_end();
|
||||
cyw43_arch_deinit();
|
||||
|
||||
printf("End of iperf client\n");
|
||||
printf("Wifi disconnected\n");
|
||||
}
|
||||
|
||||
void lwip_example_app_platform_assert(const char *msg, int line, const char *file)
|
||||
|
|
|
@ -36,7 +36,6 @@ int wolf_wifiConnect(const char *ssid, const char *pw, uint32_t auth, uint32_t t
|
|||
if (cyw43_arch_wifi_connect_timeout_ms(ssid, pw, auth, timeout)) {
|
||||
fprintf(stderr, "failed to connect. Retrying\n");
|
||||
} else {
|
||||
printf("Wifi Connected\n");
|
||||
return WOLF_SUCCESS;
|
||||
}
|
||||
sleep_ms(1000);
|
||||
|
|
Loading…
Reference in New Issue