Handshake in two phases

Hi everyone, I’m a bit new with mbedtls.

I’m having a problem with the handshake process.
I have to communicate to a server in which it does not do all the handshake (server and client certificates validations) process in one go.

Here is a simple explanation of how the process has to be like:

  1. open connection
  2. handshake (validate only the server certificate)
  3. send the message to the server
  4. do handshake again so that the server can validate the client certificate
  5. server sends message
  6. close connection

I can get to point 3 with success but then I can’t get pass point 4 because I do not know how to do the rest of the handshake.
At point 4 I use mbedtls_ssl_handshake() again, just like at point 2 but it results in error.

Does anyone can help me with this? Is there another function of mbedtls for this?

Thank you all!