MbeTLS - how to add extensions while creating self-signed certificate

Hi,

I am using the mbedtls library to programatically generate the self-signed certificate. I managed to do it. Now I have to add some extensions to CA, which when using the openssl tool, I add them like this:

authorityKeyIdentifier=keyid,issuer
extendedKeyUsage=serverAuth,clientAuth
subjectAltName=URI:URN:127.0.0.1

Any tips? Examples?