From 4d3b3b09b5105229556262cbbad1b5d3949ef29a Mon Sep 17 00:00:00 2001 From: "freddy.li" Date: Fri, 12 Nov 2021 19:14:45 +0800 Subject: [PATCH] update mbedtls --- include/mbedtls/platform_time.h | 7 +++++ library/net_sockets.c | 43 +++++++++++++++++++++++-- mbedtls.mk | 6 +++- port/helios/inc/timing_alt.h | 4 +++ port/helios/src/timing_alt.c | 56 +++++++++++++++++++++++++++------ 5 files changed, 103 insertions(+), 13 deletions(-) diff --git a/include/mbedtls/platform_time.h b/include/mbedtls/platform_time.h index 51bde6c..366687c 100644 --- a/include/mbedtls/platform_time.h +++ b/include/mbedtls/platform_time.h @@ -30,6 +30,11 @@ #include MBEDTLS_CONFIG_FILE #endif +#if defined (PLAT_Qualcomm) +#include "../../port/helios/inc/timing_alt.h" +#endif + + #ifdef __cplusplus extern "C" { #endif @@ -70,6 +75,8 @@ int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time #else #if defined(MBEDTLS_PLATFORM_TIME_MACRO) #define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO +#elif defined (PLAT_Qualcomm) +#define mbedtls_time qual_mbedtls_time #else #define mbedtls_time time #endif /* MBEDTLS_PLATFORM_TIME_MACRO */ diff --git a/library/net_sockets.c b/library/net_sockets.c index 115c691..33addfd 100644 --- a/library/net_sockets.c +++ b/library/net_sockets.c @@ -86,11 +86,17 @@ static int wsa_init_done = 0; #if defined (MBEDTLS_WITH_HELIOS) #include "helios_datacall.h" + +#if defined(PLAT_Qualcomm) +#include "helios_socket.h" +#else #include "sockets.h" #if defined (PLAT_Unisoc) #include "socket.h" #endif #include "netdb.h" +#endif + #else #include @@ -213,7 +219,8 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, } #if defined (MBEDTLS_WITH_HELIOS) - Helios_DataCallInfoStruct data_call_info = {0}; + Helios_DataCallInfoStruct data_call_info; + memset(&data_call_info, 0x00, sizeof(Helios_DataCallInfoStruct)); union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; @@ -363,7 +370,11 @@ static int net_would_block( const mbedtls_net_context *ctx ) static int net_would_block( const mbedtls_net_context *ctx ) { +#if defined (PLAT_Qualcomm) + int err = errno(ctx->fd); +#else int err = errno; +#endif /* * Never return 'WOULD BLOCK' on a blocking socket @@ -374,11 +385,19 @@ static int net_would_block( const mbedtls_net_context *ctx ) #endif ) & O_NONBLOCK ) != O_NONBLOCK ) { + #if defined (PLAT_Qualcomm) + err = errno(ctx->fd); + #else err = errno; + #endif return( 0 ); } - switch( err = errno) +#if defined (PLAT_Qualcomm) + switch( err = errno(ctx->fd) ) +#else + switch( err = errno ) +#endif { #if defined EAGAIN case EAGAIN: @@ -652,10 +671,18 @@ int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len ) if( WSAGetLastError() == WSAECONNRESET ) return( MBEDTLS_ERR_NET_CONN_RESET ); #else + #if defined (PLAT_Qualcomm) + if( errno(((mbedtls_net_context *) ctx)->fd) == EPIPE || errno(((mbedtls_net_context *) ctx)->fd) == ECONNRESET ) + #else if( errno == EPIPE || errno == ECONNRESET ) + #endif return( MBEDTLS_ERR_NET_CONN_RESET ); + #if defined (PLAT_Qualcomm) + if( errno(((mbedtls_net_context *) ctx)->fd) == EINTR ) + #else if( errno == EINTR ) + #endif return( MBEDTLS_ERR_SSL_WANT_READ ); #endif @@ -698,7 +725,11 @@ int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, if( WSAGetLastError() == WSAEINTR ) return( MBEDTLS_ERR_SSL_WANT_READ ); #else + #if defined (PLAT_Qualcomm) + if( errno(((mbedtls_net_context *) ctx)->fd) == EINTR ) + #else if( errno == EINTR ) + #endif return( MBEDTLS_ERR_SSL_WANT_READ ); #endif @@ -732,10 +763,18 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len ) if( WSAGetLastError() == WSAECONNRESET ) return( MBEDTLS_ERR_NET_CONN_RESET ); #else + #if defined (PLAT_Qualcomm) + if( errno(((mbedtls_net_context *) ctx)->fd) == EPIPE || errno(((mbedtls_net_context *) ctx)->fd) == ECONNRESET ) + #else if( errno == EPIPE || errno == ECONNRESET ) + #endif return( MBEDTLS_ERR_NET_CONN_RESET ); + #if defined (PLAT_Qualcomm) + if( errno(((mbedtls_net_context *) ctx)->fd) == EINTR ) + #else if( errno == EINTR ) + #endif return( MBEDTLS_ERR_SSL_WANT_WRITE ); #endif diff --git a/mbedtls.mk b/mbedtls.mk index 7e9584e..8f45a80 100644 --- a/mbedtls.mk +++ b/mbedtls.mk @@ -107,11 +107,15 @@ $(NAME)_COMPONENTS = \ system/platform/$(strip $(PLAT)) \ system/lwip \ system/fs \ - system/network + system/network \ + system/hal $(NAME)_CFLAGS = \ -Wno-error=unused-parameter \ -Wno-error=unused-function +ifeq ($(strip $(PLAT)),Qualcomm) + $(NAME)_CFLAGS += -Wno-error=tautological-constant-out-of-range-compare +endif ifeq ($(strip $(PLAT)),Unisoc) $(NAME)_CFLAGS += --include=system/lwip/$(strip $(PLAT))/src/include/lwip/errno.h diff --git a/port/helios/inc/timing_alt.h b/port/helios/inc/timing_alt.h index 5244e97..e44b103 100644 --- a/port/helios/inc/timing_alt.h +++ b/port/helios/inc/timing_alt.h @@ -2,6 +2,10 @@ #ifndef MBEDTLS_TIMING_ALT_H #define MBEDTLS_TIMING_ALT_H +#if defined (PLAT_Qualcomm) +#include +time_t qual_mbedtls_time(time_t *t); +#endif /** * \brief timer structure */ diff --git a/port/helios/src/timing_alt.c b/port/helios/src/timing_alt.c index d6dbc05..ae3f3e4 100644 --- a/port/helios/src/timing_alt.c +++ b/port/helios/src/timing_alt.c @@ -3,15 +3,20 @@ #include "helios_os.h" #include #include +#if defined (PLAT_Qualcomm) +#include "helios_rtc.h" +#endif -#if defined (PLAT_ASR) +#if defined (PLAT_ASR) || defined (PLAT_Qualcomm) struct timeval { int tv_sec; int tv_usec; }; #endif +#if !defined (PLAT_Qualcomm) extern int gettimeofday(struct timeval *tv, void *tz); +#endif struct _hr_time { @@ -19,19 +24,42 @@ struct _hr_time }; static int hardclock_init = 0; -static struct timeval tv_init; +static struct timeval tv_init; + +#if defined (PLAT_Qualcomm) +void qual_gettimeofday(struct timeval *tv, void *tz) +{ + (void)tz; + unsigned long system_uptime = Helios_RTC_GetTicks(); + tv->tv_sec = system_uptime/1000; + tv->tv_usec = (system_uptime%1000)*1000; +} +time_t qual_mbedtls_time(time_t *t) +{ + (void)t; + return (time_t)Helios_RTC_GetSecond(); +} +#endif unsigned long mbedtls_timing_hardclock( void ) { struct timeval tv_cur; if( hardclock_init == 0 ) - { - gettimeofday( &tv_init, NULL ); + { +#if defined (PLAT_Qualcomm) + qual_gettimeofday( &tv_init, NULL ); +#else + gettimeofday( &tv_init, NULL ); + +#endif hardclock_init = 1; } - - gettimeofday( &tv_cur, NULL ); +#if defined (PLAT_Qualcomm) + qual_gettimeofday( &tv_cur, NULL ); +#else + gettimeofday( &tv_cur, NULL ); +#endif return( ( tv_cur.tv_sec - tv_init.tv_sec ) * 1000000 + ( tv_cur.tv_usec - tv_init.tv_usec ) ); } @@ -41,15 +69,23 @@ unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int struct _hr_time *t = (struct _hr_time *) val; if( reset ) - { - gettimeofday( &t->start, NULL ); + { +#if defined (PLAT_Qualcomm) + qual_gettimeofday( &t->start, NULL ); +#else + gettimeofday( &t->start, NULL ); +#endif return( 0 ); } else { unsigned long delta; - struct timeval now; - gettimeofday( &now, NULL ); + struct timeval now; +#if defined (PLAT_Qualcomm) + qual_gettimeofday( &now, NULL ); +#else + gettimeofday( &now, NULL ); +#endif delta = ( now.tv_sec - t->start.tv_sec ) * 1000ul + ( now.tv_usec - t->start.tv_usec ) / 1000; return( delta ); -- Gitee