@ -1,3 +1,13 @@
/**
* @ file HTTPS_Client . c
* @ brief Used to download the OTA image from the server
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* Additional Infos : Connects via HTTPS and HTTPS Basic Auth to the Server .
* Downloads the image in segments
*/
# include "HTTPS_Client.h"
static const char * TAG = " https_client " ;
@ -17,6 +27,16 @@ https_client_ret_t errHTTPSClientConnectToServer(void);
https_client_ret_t errHTTPSClientValidateServer ( void ) ;
https_client_ret_t errHTTPSClientSendRequest ( void ) ;
/**
* @ fn https_client_ret_t errHTTPSClientInitialize ( void )
* @ brief Initialize the client
* @ param void
* @ return HTTPS_Client error code
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* Initialize embedTLS
*/
https_client_ret_t errHTTPSClientInitialize ( void )
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK ;
@ -31,6 +51,18 @@ https_client_ret_t errHTTPSClientInitialize(void)
return i32RetHTTPClient ;
}
/**
* @ fn https_client_ret_t errHTTPSClientRetrieveData ( char * const cpu8Data , const uint32_t * const cpcu32DataLenght , uint32_t * pu32BytesRead )
* @ brief receive a image segment from server
* @ param cpu8Data data buffer
* @ param cpcu32DataLenght desired byte amount
* @ param pu32BytesRead actual received byte amount
* @ return HTTPS_Client error code
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* Read segement and handle all events like EOF or timeout
*/
https_client_ret_t errHTTPSClientRetrieveData ( char * const cpu8Data , const uint32_t * const cpcu32DataLenght , uint32_t * pu32BytesRead )
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK ;
@ -86,6 +118,16 @@ https_client_ret_t errHTTPSClientRetrieveData(char* const cpu8Data, const uint32
return i32RetHTTPClient ;
}
/**
* @ fn https_client_ret_t errHTTPSClientReset ( void )
* @ brief reset client for next receive of image
* @ param void
* @ return HTTPS_Client error code
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* reset session
*/
https_client_ret_t errHTTPSClientReset ( void )
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK ;
@ -103,9 +145,18 @@ https_client_ret_t errHTTPSClientReset(void)
return i32RetHTTPClient ;
}
/**
* @ fn https_client_ret_t https_clientInitEmbedTLS ( void )
* @ brief init embedTLS
* @ param void
* @ return HTTPS_Client error code
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* attach certs for tls
*/
https_client_ret_t https_clientInitEmbedTLS ( void )
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK ;
int32_t i32RetEmbedTLS = ESP_OK ;
static bool bAlreadySetup = false ;
@ -168,20 +219,13 @@ https_client_ret_t https_clientInitEmbedTLS(void)
i32RetEmbedTLS = mbedtls_ssl_setup ( & sHTTPS_ClientConfig . ssl , & sHTTPS_ClientConfig . conf ) ; //call this only once
if ( i32RetEmbedTLS ! = ESP_OK )
{
ESP_LOGE ( TAG , " mbedtls_ssl_setup returned 0x%x \n \n " , i32RetEmbedTLS ) ;
// uint8_t buffer[20];
//mbedtls_strerror(i32RetEmbedTLS, buffer, 20);
//ESP_LOGE(TAG, "%s", buffer);
ESP_LOGE ( TAG , " mbedtls_ssl_setup returned 0x%x \n " , i32RetEmbedTLS ) ;
}
else
{
bAlreadySetup = true ;
}
}
}
if ( i32RetEmbedTLS = = ESP_OK )
@ -197,6 +241,16 @@ https_client_ret_t https_clientInitEmbedTLS(void)
return i32RetHTTPClient ;
}
/**
* @ fn https_client_ret_t errHTTPSClientConnectToServer ( void )
* @ brief connect to server
* @ param void
* @ return HTTPS_Client error code
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* open TLS session
*/
https_client_ret_t errHTTPSClientConnectToServer ( void )
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK ;
@ -230,6 +284,16 @@ https_client_ret_t errHTTPSClientConnectToServer(void)
return i32RetHTTPClient ;
}
/**
* @ fn https_client_ret_t errHTTPSClientValidateServer ( void )
* @ brief validate server
* @ param void
* @ return HTTPS_Client error code
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* check CDN and cert
*/
https_client_ret_t errHTTPSClientValidateServer ( void )
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK ;
@ -248,6 +312,16 @@ https_client_ret_t errHTTPSClientValidateServer(void)
return i32RetHTTPClient ;
}
/**
* @ fn https_client_ret_t errHTTPSClientSendRequest ( void )
* @ brief send request to server
* @ param void
* @ return HTTPS_Client error code
* @ author Hendrik Schutter
* @ date 20.01 .2021
*
* send HTTP GET request
*/
https_client_ret_t errHTTPSClientSendRequest ( void )
{
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK ;