wolfSSL_read called from an STM32 microcontroller acting as a Server returns -313 (FATAL ERROR) after many succesfull readings from a CSharp application acting as a Client.
ret = wolfSSL_read(Pt_ssl, A_prcl_msd_m1_m1s_data_link_rx_buffer, sizeof(A_prcl_msd_m1_m1s_data_link_rx_buffer)-1);
err = wolfSSL_get_error(Pt_ssl, ret);
Our receive callback is like this and works fine
wolfSSL_CTX_SetIORecv(Pt_ctx, PRCL_MSD_M1_M1S_DLINK_uartIORx);
/*!
* \brief WolfSSL receive callback
* \dotfile PRCL_MSD_M1_M1S_DLINK_uartIORx.dot
* \ingroup MSD_M1_M1S_PROTOCOL_DATA_LINK
*/
static int PRCL_MSD_M1_M1S_DLINK_uartIORx(WOLFSSL *ssl, char *buf, const int sz, void *ctx)
{
bool b_message_received;
static int8_t * p_data_received_buf;
static int32_t total_amount_data_rcv = 0;
int32_t bytes_available_fifo = 0;
int32_t bytes_to_read;
int32_t bytes_read;
b_message_received = MDL_USARTS_Check_end_reception(USART_MSD_COMMS);
if (b_message_received == TRUE)
{
total_amount_data_rcv = MDL_USARTS_Get_DMA_amount_of_rx_data(USART_MSD_COMMS);
MDL_USARTS_Reset_DMA_amount_of_rx_data(USART_MSD_COMMS);
MDL_USARTS_Start_receive(USART_MSD_COMMS);
p_data_received_buf = (int8_t*)MDL_USARTS_Get_receive_buffer(USART_MSD_COMMS);
MDL_CIRC_FIFO_Fifo_push_buf(&T_wolfSSL_rx_fifo, (uint8_t *)p_data_received_buf, total_amount_data_rcv);
}
bytes_available_fifo = MDL_CIRC_FIFO_Fifo_used_size(&T_wolfSSL_rx_fifo);
if (bytes_available_fifo > 0)
{
DEBUG_PRINTF("FIFO used: %d, DMA received: %d\r\n", bytes_available_fifo, total_amount_data_rcv);
bytes_to_read = (bytes_available_fifo < sz) ? bytes_available_fifo : sz;
bytes_read = MDL_CIRC_FIFO_Fifo_pop_buf(&T_wolfSSL_rx_fifo, (uint8_t *)buf, bytes_to_read);
return bytes_read;
}
else
{
return WOLFSSL_CBIO_ERR_WANT_READ;
}
}
Does anyone has any suggestion?
Many Thanks,
Edoardo