wolfSSL's I/O callbacks are prototyped by the following:
int (*CallbackIORecv)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
int (*CallbackIOSend)(WOLFSSL *ssl, char *buf, int sz, void *ctx);
Whenever wolfSSL needs additional data to advance its internal state machine, it will call the RECEIVE callback. The job of the RECEIVE callback is to place data into the provided buffer “buf”. wolfSSL asks for “sz” bytes of data, but if the callback has less data than requested, it can copy the number of bytes it has available into “buf” and return the number of bytes that have been written.
Whenever wolfSSL needs to send data in order to advance its internal state machine, it will call the SEND callback. The job of the SEND callback is to send the data in the buffer “buf” to the peer. The number of bytes in “buf” is given to the callback through the “sz” parameter. If the callback is only able to send part of the data in “buf”, it should return the number of bytes that were sent. wolfSSL will internally loop back around and call the callback again to get the rest of the data.
The third thing that comes into play with the I/O callbacks is the associated context (void *ctx). This can be a pointer to anything the user would like handed back to them during the I/O callbacks. Oftentimes this is a custom structure that would hold a pointer to data buffers, data sizes, socket handles, or in your case information necessary to send/receive data over your UART connection.
These I/O callback “contexts” can be set by the application using:
void wolfSSL_SetIOReadCtx( WOLFSSL* ssl, void *ctx);
void wolfSSL_SetIOWriteCtx(WOLFSSL* ssl, void *ctx);
From your last post, it sounds like in your case, your UART might buffer data when received, then in the wolfSSL Receive callback, you would simply copy data from the buffered area to wolfSSL’s internal buffer in the callback.
Does this make sense? Is there anything that needs clarifying?
Best Regards,
Chris