diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index 200b99b3d..449e85a2e 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -91,6 +91,11 @@ #endif #define NO_TIME_H /* since Micrium not defining XTIME or XGMTIME, CERT_GEN not available */ +#elif defined(MICROCHIP_TCPIP) + #include + #define XTIME(t1) pic32_time((t1)) + #define XGMTIME(c) gmtime((c)) + #define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t)) #elif defined(USER_TIME) /* user time, and gmtime compatible functions, there is a gmtime implementation here that WINCE uses, so really just need some ticks @@ -237,6 +242,29 @@ struct tm* my_gmtime(const time_t* timer) /* has a gmtime() but hangs */ #endif /* THREADX */ +#ifdef MICROCHIP_TCPIP + +/* + * time() is just a stub in Microchip libraries. We need our own + * implementation. Use SNTP client to get seconds since epoch. + */ +time_t pic32_time(time_t* timer) +{ + DWORD sec = 0; + time_t localTime; + + if (timer == NULL) + timer = &localTime; + + sec = SNTPGetUTCSeconds(); + *timer = (time_t) sec; + + return *timer; +} + +#endif /* MICROCHIP_TCPIP */ + + static INLINE word32 btoi(byte b) { return b - 0x30; diff --git a/cyassl/ctaocrypt/settings.h b/cyassl/ctaocrypt/settings.h index ae05cd0c6..824844079 100644 --- a/cyassl/ctaocrypt/settings.h +++ b/cyassl/ctaocrypt/settings.h @@ -45,6 +45,9 @@ /* Uncomment next line if using Microchip PIC32 ethernet starter kit */ /* #define MICROCHIP_PIC32 */ +/* Uncomment next line if using Microchip TCP/IP stack, for time features */ +/* #define MICROCHIP_TCPIP */ + /* Uncomment next line if using FreeRTOS */ /* #define FREERTOS */ @@ -83,7 +86,6 @@ #ifdef MICROCHIP_PIC32 #define SIZEOF_LONG_LONG 8 #define SINGLE_THREADED - #define CYASSL_USER_IO #define NO_WRITEV #define NO_DEV_RANDOM #define NO_FILESYSTEM @@ -91,6 +93,12 @@ #define TFM_TIMING_RESISTANT #endif +#ifdef MICROCHIP_TCPIP + /* includes timer functions */ + #include "TCPIP Stack/TCPIP.h" + #define CYASSL_USER_IO +#endif + #ifdef MBED #define SINGLE_THREADED #define CYASSL_USER_IO diff --git a/src/internal.c b/src/internal.c index eccbff327..e144bc982 100644 --- a/src/internal.c +++ b/src/internal.c @@ -2064,6 +2064,15 @@ ProtocolVersion MakeDTLSv1_2(void) return (word32)clk; } + +#elif defined(MICROCHIP_TCPIP) + + word32 LowResTimer(void) + { + return (word32) TickGet(); + } + + #elif defined(USER_TICKS) #if 0 word32 LowResTimer(void)