cyassl re-port with cellular comms, PSK test
Dependencies: VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src
logging.c
00001 /* logging.c 00002 * 00003 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd. 00004 * 00005 * This file is part of CyaSSL. 00006 * 00007 * CyaSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * CyaSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00020 */ 00021 00022 #define DEBUG_CYASSL 00023 00024 #ifdef HAVE_CONFIG_H 00025 #include <config.h> 00026 #endif 00027 00028 /* submitted by eof */ 00029 00030 #include <cyassl/ctaocrypt/settings.h> 00031 #include <cyassl/ctaocrypt/logging.h> 00032 #include <cyassl/ctaocrypt/error.h> 00033 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif 00038 CYASSL_API int CyaSSL_Debugging_ON(void); 00039 CYASSL_API void CyaSSL_Debugging_OFF(void); 00040 #ifdef __cplusplus 00041 } 00042 #endif 00043 00044 00045 #ifdef DEBUG_CYASSL 00046 00047 /* Set these to default values initially. */ 00048 static CyaSSL_Logging_cb log_function = 0; 00049 static int loggingEnabled = 0; 00050 00051 #endif /* DEBUG_CYASSL */ 00052 00053 00054 int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f) 00055 { 00056 #ifdef DEBUG_CYASSL 00057 int res = 0; 00058 00059 if (f) 00060 log_function = f; 00061 else 00062 res = BAD_FUNC_ARG; 00063 00064 return res; 00065 #else 00066 (void)f; 00067 return NOT_COMPILED_IN; 00068 #endif 00069 } 00070 00071 00072 int CyaSSL_Debugging_ON(void) 00073 { 00074 00075 #ifdef DEBUG_CYASSL 00076 loggingEnabled = 1; 00077 return 0; 00078 #else 00079 return NOT_COMPILED_IN; 00080 #endif 00081 } 00082 00083 00084 void CyaSSL_Debugging_OFF(void) 00085 { 00086 #ifdef DEBUG_CYASSL 00087 loggingEnabled = 0; 00088 #endif 00089 } 00090 00091 00092 #ifdef DEBUG_CYASSL 00093 00094 #ifdef FREESCALE_MQX 00095 #include <fio.h> 00096 #else 00097 #include <stdio.h> /* for default printf stuff */ 00098 #endif 00099 00100 #ifdef THREADX 00101 int dc_log_printf(char*, ...); 00102 #endif 00103 00104 static void cyassl_log(const int logLevel, const char *const logMessage) 00105 { 00106 if (log_function) 00107 log_function(logLevel, logMessage); 00108 else { 00109 if (loggingEnabled) { 00110 #ifdef THREADX 00111 dc_log_printf("%s\n", logMessage); 00112 #elif defined(MICRIUM) 00113 #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) 00114 NetSecure_TraceOut((CPU_CHAR *)logMessage); 00115 #endif 00116 #else 00117 //fprintf(stderr, "%s\n", logMessage); 00118 printf("%s\r\n",logMessage); 00119 #endif 00120 } 00121 } 00122 } 00123 00124 00125 void CYASSL_MSG(const char* msg) 00126 { 00127 if (loggingEnabled) 00128 cyassl_log(INFO_LOG , msg); 00129 } 00130 00131 00132 void CYASSL_ENTER(const char* msg) 00133 { 00134 if (loggingEnabled) { 00135 char buffer[80]; 00136 sprintf(buffer, "CyaSSL Entering %s", msg); 00137 cyassl_log(ENTER_LOG , buffer); 00138 } 00139 } 00140 00141 00142 void CYASSL_LEAVE(const char* msg, int ret) 00143 { 00144 if (loggingEnabled) { 00145 char buffer[80]; 00146 sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret); 00147 cyassl_log(LEAVE_LOG , buffer); 00148 } 00149 } 00150 00151 00152 void CYASSL_ERROR(int error) 00153 { 00154 if (loggingEnabled) { 00155 char buffer[80]; 00156 sprintf(buffer, "CyaSSL error occured, error = %d", error); 00157 cyassl_log(ERROR_LOG , buffer); 00158 } 00159 } 00160 00161 #endif /* DEBUG_CYASSL */
Generated on Thu Jul 14 2022 00:25:23 by 1.7.2