From f7c34d22e6514ba0df228fbf4ea8bc2ff8e0a19d Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Mon, 29 Nov 2021 15:56:00 -0700 Subject: [PATCH] add calls to user callback and adjust formating --- src/internal.c | 4 ++-- src/wolfio.c | 27 +++++++++++++++++++-------- wolfcrypt/src/wc_port.c | 3 ++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/internal.c b/src/internal.c index 0f0290688..f583458f9 100644 --- a/src/internal.c +++ b/src/internal.c @@ -2121,8 +2121,8 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap) ctx->CBIORecv = Mynewt_Receive; ctx->CBIOSend = Mynewt_Send; #elif defined WOLFSSL_LWIP_NATIVE - ctx->CBIORecv = LwIPNativeReceive; - ctx->CBIOSend = LwIPNativeSend; + ctx->CBIORecv = LwIPNativeReceive; + ctx->CBIOSend = LwIPNativeSend; #elif defined(WOLFSSL_GNRC) ctx->CBIORecv = GNRC_ReceiveFrom; ctx->CBIOSend = GNRC_SendTo; diff --git a/src/wolfio.c b/src/wolfio.c index d91ff1000..3a94b6ad1 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -2567,15 +2567,14 @@ int LwIPNativeSend(WOLFSSL* ssl, char* buf, int sz, void* ctx) } -int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz, - void* ctx) +int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx) { struct pbuf *current, *head; WOLFSSL_LWIP_NATIVE_STATE* nlwip; int ret = 0; if (nlwip == NULL || ctx == NULL) { - return WOLFSSL_CBIO_ERR_GENERAL; + return WOLFSSL_CBIO_ERR_GENERAL; } nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)ctx; @@ -2604,7 +2603,7 @@ int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz, XMEMCPY(&buf[read], (const char *)&(((char *)(current->payload))[nlwip->pulled]), - len); + len); nlwip->pulled = nlwip->pulled + len; if (nlwip->pulled >= current->len) { WOLFSSL_MSG("Native LwIP read full pbuf"); @@ -2660,6 +2659,10 @@ static err_t LwIPNativeReceiveCB(void* cb, struct tcp_pcb* pcb, } } + if (nlwip->recv_fn) { + return nlwip->recv_fn(nlwip->arg, pcb, pbuf, err); + } + WOLFSSL_LEAVE("LwIPNativeReceiveCB", nlwip->pbuf->tot_len); return ERR_OK; } @@ -2667,9 +2670,17 @@ static err_t LwIPNativeReceiveCB(void* cb, struct tcp_pcb* pcb, static err_t LwIPNativeSentCB(void* cb, struct tcp_pcb* pcb, u16_t len) { - (void)cb; - (void)pcb; - (void)len; + WOLFSSL_LWIP_NATIVE_STATE* nlwip; + + if (cb == NULL || pcb == NULL) { + WOLFSSL_MSG("Expected callback was null, abort"); + return ERR_ABRT; + } + + nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)cb; + if (nlwip->sent_fn) { + return nlwip->sent_fn(nlwip->arg, pcb, len); + } return ERR_OK; } @@ -2691,7 +2702,7 @@ int wolfSSL_SetIO_LwIP(WOLFSSL* ssl, void* pcb, /* wolfSSL_LwIP_recv/sent_cb invokes recv/sent user callback in them. */ tcp_recv(pcb, LwIPNativeReceiveCB); tcp_sent(pcb, LwIPNativeSentCB); - tcp_arg (pcb, (void *)&(ssl->lwipCtx)); + tcp_arg (pcb, (void *)&ssl->lwipCtx); wolfSSL_SetIOReadCtx(ssl, &ssl->lwipCtx); wolfSSL_SetIOWriteCtx(ssl, &ssl->lwipCtx); diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 8704416f5..f44b81f90 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -2485,7 +2485,8 @@ time_t stm32_hal_time(time_t *t1) RTC_TimeTypeDef time; RTC_DateTypeDef date; - /* must get time and date here due to STM32 HW bug */ + /* order of GetTime followed by GetDate required here due to STM32 HW + * requirement */ HAL_RTC_GetTime(&hrtc, &time, FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &date, FORMAT_BIN);