1 /* 2 * Copyright (c) 2019,2020 Linaro Limited 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #include <zephyr/kernel.h> 7 #include <zephyr/logging/log_ctrl.h> 8 #include <zephyr/logging/log.h> 9 10 #include "psa/crypto.h" 11 #include "util_app_log.h" 12 13 LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL); 14 al_psa_status(psa_status_t status,const char * func_name)15psa_status_t al_psa_status(psa_status_t status, const char *func_name) 16 { 17 switch (status) { 18 case PSA_SUCCESS: 19 break; 20 21 /* Generic PSA errors (psa/error.h). */ 22 case PSA_ERROR_PROGRAMMER_ERROR: 23 LOG_ERR("Programmer error"); 24 break; 25 case PSA_ERROR_CONNECTION_REFUSED: 26 LOG_ERR("Connection refused"); 27 break; 28 case PSA_ERROR_CONNECTION_BUSY: 29 LOG_ERR("Connection busy"); 30 break; 31 case PSA_ERROR_GENERIC_ERROR: 32 LOG_ERR("Generic error"); 33 break; 34 case PSA_ERROR_NOT_PERMITTED: 35 LOG_ERR("Not permitted"); 36 break; 37 case PSA_ERROR_NOT_SUPPORTED: 38 LOG_ERR("Unsupported operation"); 39 break; 40 case PSA_ERROR_INVALID_ARGUMENT: 41 LOG_ERR("Invalid argument"); 42 break; 43 case PSA_ERROR_INVALID_HANDLE: 44 LOG_ERR("Invalid handle"); 45 break; 46 case PSA_ERROR_BAD_STATE: 47 LOG_ERR("Bad state"); 48 break; 49 case PSA_ERROR_BUFFER_TOO_SMALL: 50 LOG_ERR("Buffer too small"); 51 break; 52 case PSA_ERROR_ALREADY_EXISTS: 53 LOG_ERR("Already exists"); 54 break; 55 case PSA_ERROR_DOES_NOT_EXIST: 56 LOG_ERR("Does not exist"); 57 break; 58 case PSA_ERROR_INSUFFICIENT_MEMORY: 59 LOG_ERR("Insufficient memory"); 60 break; 61 case PSA_ERROR_INSUFFICIENT_STORAGE: 62 LOG_ERR("Insufficient storage"); 63 break; 64 case PSA_ERROR_INSUFFICIENT_DATA: 65 LOG_ERR("Insufficient memory data"); 66 break; 67 case PSA_ERROR_SERVICE_FAILURE: 68 LOG_ERR("Service failure"); 69 break; 70 case PSA_ERROR_COMMUNICATION_FAILURE: 71 LOG_ERR("Communication failure"); 72 break; 73 case PSA_ERROR_STORAGE_FAILURE: 74 LOG_ERR("Storage failure"); 75 break; 76 case PSA_ERROR_HARDWARE_FAILURE: 77 LOG_ERR("Hardware failure"); 78 break; 79 case PSA_ERROR_INVALID_SIGNATURE: 80 LOG_ERR("Invalid signature"); 81 break; 82 83 /* PSA crypto errors (psa/crypto_values.h). */ 84 case PSA_ERROR_INSUFFICIENT_ENTROPY: 85 LOG_ERR("CRYPTO: Insufficient entropy"); 86 break; 87 case PSA_ERROR_CORRUPTION_DETECTED: 88 LOG_ERR("CRYPTO: Tampering detected"); 89 break; 90 91 /* Catch-all error handler. */ 92 default: 93 LOG_ERR("Unhandled status response: %d", status); 94 break; 95 } 96 97 /* Display the calling function name for debug purposes. */ 98 if (status != PSA_SUCCESS) { 99 LOG_ERR("Function: '%s'", func_name); 100 } 101 102 return status; 103 } 104 al_dump_log(void)105void al_dump_log(void) 106 { 107 while (log_process()) { 108 109 } 110 } 111