
#include <stdio.h>
#include "drivers/mss_sys_services/mss_sys_services.h"
#include "drivers/mss_uart/mss_uart.h"


static void display_error_info1(uint8_t status);
static void display_error_info2(uint8_t status);
static void display_error_info3(uint8_t status);

mss_uart_instance_t * const gp_my_uart = &g_mss_uart1;

/*==============================================================================
 * Global Variables.
 */

const uint8_t *g_errror_message[] =
{
    (const uint8_t*)"\r\n eNVM MSS Error",
    (const uint8_t*)"\r\n Error - PUF error when creating.",                         /* 0 */
    (const uint8_t*)"\r\n Error - Invalid subcmd",                    				/* 1 */
    (const uint8_t*)"\r\n Error - eNVM program Error.",                             /* 2 */
    (const uint8_t*)"\r\n Error - eNVM Verify Error",                   			/* 3 */
    (const uint8_t*)"\r\n Error - Memory Access Error",        					 /* 4 */
    (const uint8_t*)"\r\n Error - License not available in device.",            /* 5 */
    (const uint8_t*)"\r\n Error - Service disabled by factory security.",       /* 6 */
    (const uint8_t*)"\r\n Error - Service disabled by user security.",          /* 7 */
    (const uint8_t*)"\r\n Error - Unexpected error.",                           /* 8 */
    (const uint8_t*)"\r\n Error - Invalid status."  ,                            /* 9 */
    (const uint8_t*)"\r\n Error - Invalid request or KC, when exporting or importing",/* 10 */
    (const uint8_t*)"\r\n Error - Invalid hash",									/* 11 */
    (const uint8_t*)"\r\n Error - Invalid user AC",									/* 12 */
    (const uint8_t*)"\r\n Error - Incorrect keysize for renewing a kc",				/* 13 */
    (const uint8_t*)"\r\n Error - Private eNVM user digest mismatch",				/* 14 */
    (const uint8_t*)"\r\n Error - DRBG error",										/* 15 */
    (const uint8_t*)"\r\n Error - Invalid keynum or argument or exported or invalid key",/* 16 */
};
/*==============================================================================
  Display error message.
 */
static void display_error_info1(uint8_t status)
{
    switch(status)
    {
        case MSS_SYS_ENVM_ERROR :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[0]);
            break;

        case MSS_SYS_PUF_ERROR_WHEN_CREATING :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[1]);
            break;

        case  MSS_SYS_INVALID_SUBCMD:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[2]);
            break;

        case MSS_SYS_ENVM_PROGRAM_ERROR :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[3]);
            break;

        case MSS_SYS_ENVM_VERIFY_ERROR  :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[4]);
            break;

        case MSS_SYS_MEM_ACCESS_ERROR:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[5]);
            break;

        case MSS_SYS_SERVICE_NOT_LICENSED:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[6]);
            break;

        case MSS_SYS_SERVICE_DISABLED_BY_FACTORY:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[7]);
            break;

        case MSS_SYS_SERVICE_DISABLED_BY_USER:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[8]);
            break;

        case MSS_SYS_UNEXPECTED_ERROR:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[9]);
            break;

        default:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[10]);
            break;
    }
}
static void display_error_info2(uint8_t status)
{
    switch(status)
    {
        case MSS_SYS_ENVM_ERROR :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[0]);
            break;

        case MSS_SYS_PUF_ERROR_WHEN_CREATING :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[1]);
            break;

        case  MSS_SYS_INVALID_REQUEST_OR_KC :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[11]);
            break;

        case MSS_SYS_ENVM_PROGRAM_ERROR :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[3]);
            break;

        case MSS_SYS_INVALID_HASH  :
             MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[12]);
             break;

        case MSS_SYS_INVALID_USER_AC1   :
             MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[13]);
             break;

        case MSS_SYS_ENVM_VERIFY_ERROR  :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[4]);
            break;

        case MSS_SYS_INCORRECT_KEYSIZE_FOR_RENEWING_A_KC:
             MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[14]);
            break;

        case MSS_SYS_PRIVATE_ENVM_USER_DIGEST_MISMATCH:
             MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[15]);
             break;

        case MSS_SYS_USER_KEY_CODE_INVALID_SUBCMD:
             MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[2]);
             break;

        case  MSS_SYS_DRBG_ERROR:
              MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[16]);
              break;

        case MSS_SYS_MEM_ACCESS_ERROR:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[5]);
            break;

        case MSS_SYS_SERVICE_NOT_LICENSED:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[6]);
            break;

        case MSS_SYS_SERVICE_DISABLED_BY_FACTORY:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[7]);
            break;

        case MSS_SYS_SERVICE_DISABLED_BY_USER:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[8]);
            break;

        case MSS_SYS_UNEXPECTED_ERROR:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[9]);
            break;

        default:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[10]);
            break;
    }
}
static void display_error_info3(uint8_t status)
{
    switch(status)
    {

        case MSS_SYS_PUF_ERROR_WHEN_CREATING :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[1]);
            break;

        case MSS_SYS_INVALID_KEYNUM_OR_ARGUMENT   :
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[17]);
            break;

        case MSS_SYS_INVALID_HASH  :
             MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[12]);
             break;

        case MSS_SYS_PRIVATE_ENVM_USER_DIGEST_MISMATCH:
             MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[15]);
             break;

        case MSS_SYS_MEM_ACCESS_ERROR:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[5]);
            break;

        case MSS_SYS_SERVICE_NOT_LICENSED:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[6]);
            break;

        case MSS_SYS_SERVICE_DISABLED_BY_FACTORY:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[7]);
            break;

        case MSS_SYS_SERVICE_DISABLED_BY_USER:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[8]);
            break;

        case MSS_SYS_UNEXPECTED_ERROR:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[9]);
            break;

        default:
            MSS_UART_polled_tx_string(gp_my_uart, g_errror_message[10]);
            break;
    }
}
