Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file debug.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief Debug functions |
| 5 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame^] | 8 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 9 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 23 | */ |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 24 | #ifndef POLARSSL_DEBUG_H |
| 25 | #define POLARSSL_DEBUG_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 28 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #else |
| 30 | #include POLARSSL_CONFIG_FILE |
| 31 | #endif |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 32 | |
Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 33 | #include "ssl.h" |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 34 | |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 35 | #if defined(POLARSSL_ECP_C) |
| 36 | #include "ecp.h" |
| 37 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 38 | |
Paul Bakker | 1504af5 | 2012-02-11 16:17:43 +0000 | [diff] [blame] | 39 | #if defined(POLARSSL_DEBUG_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 40 | |
Paul Bakker | eaebbd5 | 2014-04-25 15:04:14 +0200 | [diff] [blame] | 41 | #define POLARSSL_DEBUG_LOG_FULL 0 /**< Include file:line in log lines */ |
| 42 | #define POLARSSL_DEBUG_LOG_RAW 1 /**< Only log raw debug lines */ |
| 43 | |
| 44 | /** |
| 45 | * \name SECTION: Module settings |
| 46 | * |
| 47 | * The configuration options you can set for this module are in this section. |
| 48 | * Either change them in config.h or define them on the compiler command line. |
| 49 | * \{ |
| 50 | */ |
| 51 | |
| 52 | #if !defined(POLARSSL_DEBUG_DFL_MODE) |
| 53 | #define POLARSSL_DEBUG_DFL_MODE POLARSSL_DEBUG_LOG_FULL /**< Default log: Full or Raw */ |
| 54 | #endif |
| 55 | |
| 56 | /* \} name SECTION: Module settings */ |
| 57 | |
Paul Bakker | eaebbd5 | 2014-04-25 15:04:14 +0200 | [diff] [blame] | 58 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 59 | #define SSL_DEBUG_MSG( level, args ) \ |
| 60 | debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args ); |
| 61 | |
| 62 | #define SSL_DEBUG_RET( level, text, ret ) \ |
| 63 | debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret ); |
| 64 | |
| 65 | #define SSL_DEBUG_BUF( level, text, buf, len ) \ |
| 66 | debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len ); |
| 67 | |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 68 | #if defined(POLARSSL_BIGNUM_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 69 | #define SSL_DEBUG_MPI( level, text, X ) \ |
| 70 | debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X ); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 71 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 72 | |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 73 | #if defined(POLARSSL_ECP_C) |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 74 | #define SSL_DEBUG_ECP( level, text, X ) \ |
| 75 | debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X ); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 76 | #endif |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 77 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 78 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 79 | #define SSL_DEBUG_CRT( level, text, crt ) \ |
| 80 | debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt ); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 81 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 82 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 83 | #else /* POLARSSL_DEBUG_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 84 | |
| 85 | #define SSL_DEBUG_MSG( level, args ) do { } while( 0 ) |
| 86 | #define SSL_DEBUG_RET( level, text, ret ) do { } while( 0 ) |
| 87 | #define SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 ) |
| 88 | #define SSL_DEBUG_MPI( level, text, X ) do { } while( 0 ) |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 89 | #define SSL_DEBUG_ECP( level, text, X ) do { } while( 0 ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 90 | #define SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 ) |
| 91 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 92 | #endif /* POLARSSL_DEBUG_C */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 93 | |
| 94 | #ifdef __cplusplus |
| 95 | extern "C" { |
| 96 | #endif |
| 97 | |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 98 | /** |
| 99 | * \brief Set the log mode for the debug functions globally |
| 100 | * (Default value: POLARSSL_DEBUG_DFL_MODE) |
| 101 | * |
| 102 | * \param log_mode The log mode to use (POLARSSL_DEBUG_LOG_FULL or |
| 103 | * POLARSSL_DEBUG_LOG_RAW) |
| 104 | */ |
| 105 | void debug_set_log_mode( int log_mode ); |
| 106 | |
| 107 | /** |
| 108 | * \brief Set the level threshold to handle globally. Messages that have a |
| 109 | * level over the threshold value are ignored. |
| 110 | * (Default value: 0 (No debug)) |
| 111 | * |
| 112 | * \param threshold maximum level of messages to pass on |
| 113 | */ |
| 114 | void debug_set_threshold( int threshold ); |
| 115 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 116 | char *debug_fmt( const char *format, ... ); |
| 117 | |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 118 | void debug_print_msg( const ssl_context *ssl, int level, |
| 119 | const char *file, int line, const char *text ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 120 | |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 121 | void debug_print_ret( const ssl_context *ssl, int level, |
| 122 | const char *file, int line, |
| 123 | const char *text, int ret ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 124 | |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 125 | void debug_print_buf( const ssl_context *ssl, int level, |
| 126 | const char *file, int line, const char *text, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 127 | unsigned char *buf, size_t len ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 128 | |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 129 | #if defined(POLARSSL_BIGNUM_C) |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 130 | void debug_print_mpi( const ssl_context *ssl, int level, |
| 131 | const char *file, int line, |
| 132 | const char *text, const mpi *X ); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 133 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 134 | |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 135 | #if defined(POLARSSL_ECP_C) |
| 136 | void debug_print_ecp( const ssl_context *ssl, int level, |
| 137 | const char *file, int line, |
| 138 | const char *text, const ecp_point *X ); |
| 139 | #endif |
| 140 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 141 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 142 | void debug_print_crt( const ssl_context *ssl, int level, |
| 143 | const char *file, int line, |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 144 | const char *text, const x509_crt *crt ); |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 145 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 146 | |
| 147 | #ifdef __cplusplus |
| 148 | } |
| 149 | #endif |
| 150 | |
| 151 | #endif /* debug.h */ |