add calls to user callback and adjust formating

pull/4589/head
Jacob Barthelmeh 2021-11-29 15:56:00 -07:00
parent 7e2fab6f4a
commit f7c34d22e6
3 changed files with 23 additions and 11 deletions

View File

@ -2121,8 +2121,8 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap)
ctx->CBIORecv = Mynewt_Receive; ctx->CBIORecv = Mynewt_Receive;
ctx->CBIOSend = Mynewt_Send; ctx->CBIOSend = Mynewt_Send;
#elif defined WOLFSSL_LWIP_NATIVE #elif defined WOLFSSL_LWIP_NATIVE
ctx->CBIORecv = LwIPNativeReceive; ctx->CBIORecv = LwIPNativeReceive;
ctx->CBIOSend = LwIPNativeSend; ctx->CBIOSend = LwIPNativeSend;
#elif defined(WOLFSSL_GNRC) #elif defined(WOLFSSL_GNRC)
ctx->CBIORecv = GNRC_ReceiveFrom; ctx->CBIORecv = GNRC_ReceiveFrom;
ctx->CBIOSend = GNRC_SendTo; ctx->CBIOSend = GNRC_SendTo;

View File

@ -2567,15 +2567,14 @@ int LwIPNativeSend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
} }
int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz, int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx)
void* ctx)
{ {
struct pbuf *current, *head; struct pbuf *current, *head;
WOLFSSL_LWIP_NATIVE_STATE* nlwip; WOLFSSL_LWIP_NATIVE_STATE* nlwip;
int ret = 0; int ret = 0;
if (nlwip == NULL || ctx == NULL) { if (nlwip == NULL || ctx == NULL) {
return WOLFSSL_CBIO_ERR_GENERAL; return WOLFSSL_CBIO_ERR_GENERAL;
} }
nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)ctx; nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)ctx;
@ -2604,7 +2603,7 @@ int LwIPNativeReceive(WOLFSSL* ssl, char* buf, int sz,
XMEMCPY(&buf[read], XMEMCPY(&buf[read],
(const char *)&(((char *)(current->payload))[nlwip->pulled]), (const char *)&(((char *)(current->payload))[nlwip->pulled]),
len); len);
nlwip->pulled = nlwip->pulled + len; nlwip->pulled = nlwip->pulled + len;
if (nlwip->pulled >= current->len) { if (nlwip->pulled >= current->len) {
WOLFSSL_MSG("Native LwIP read full pbuf"); 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); WOLFSSL_LEAVE("LwIPNativeReceiveCB", nlwip->pbuf->tot_len);
return ERR_OK; 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) static err_t LwIPNativeSentCB(void* cb, struct tcp_pcb* pcb, u16_t len)
{ {
(void)cb; WOLFSSL_LWIP_NATIVE_STATE* nlwip;
(void)pcb;
(void)len; 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; 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. */ /* wolfSSL_LwIP_recv/sent_cb invokes recv/sent user callback in them. */
tcp_recv(pcb, LwIPNativeReceiveCB); tcp_recv(pcb, LwIPNativeReceiveCB);
tcp_sent(pcb, LwIPNativeSentCB); tcp_sent(pcb, LwIPNativeSentCB);
tcp_arg (pcb, (void *)&(ssl->lwipCtx)); tcp_arg (pcb, (void *)&ssl->lwipCtx);
wolfSSL_SetIOReadCtx(ssl, &ssl->lwipCtx); wolfSSL_SetIOReadCtx(ssl, &ssl->lwipCtx);
wolfSSL_SetIOWriteCtx(ssl, &ssl->lwipCtx); wolfSSL_SetIOWriteCtx(ssl, &ssl->lwipCtx);

View File

@ -2485,7 +2485,8 @@ time_t stm32_hal_time(time_t *t1)
RTC_TimeTypeDef time; RTC_TimeTypeDef time;
RTC_DateTypeDef date; 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_GetTime(&hrtc, &time, FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &date, FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &date, FORMAT_BIN);