blob: 519f16e3a1537da6dc5205c1818f3666e649d688 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file debug.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief Debug functions
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnard967a2a52015-01-22 14:28:16 +00008 * This file is part of mbed TLS (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000024 */
Paul Bakkercce9d772011-11-18 14:26:47 +000025#ifndef POLARSSL_DEBUG_H
26#define POLARSSL_DEBUG_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000029#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#else
31#include POLARSSL_CONFIG_FILE
32#endif
Paul Bakker314052f2011-08-15 09:07:52 +000033#include "ssl.h"
Paul Bakker41c83d32013-03-20 14:39:14 +010034#if defined(POLARSSL_ECP_C)
35#include "ecp.h"
36#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000037
Paul Bakker1504af52012-02-11 16:17:43 +000038#if defined(POLARSSL_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000039
Paul Bakkereaebbd52014-04-25 15:04:14 +020040#define POLARSSL_DEBUG_LOG_FULL 0 /**< Include file:line in log lines */
41#define POLARSSL_DEBUG_LOG_RAW 1 /**< Only log raw debug lines */
42
43/**
44 * \name SECTION: Module settings
45 *
46 * The configuration options you can set for this module are in this section.
47 * Either change them in config.h or define them on the compiler command line.
48 * \{
49 */
50
51#if !defined(POLARSSL_DEBUG_DFL_MODE)
52#define POLARSSL_DEBUG_DFL_MODE POLARSSL_DEBUG_LOG_FULL /**< Default log: Full or Raw */
53#endif
54
55/* \} name SECTION: Module settings */
56
Paul Bakkereaebbd52014-04-25 15:04:14 +020057
Paul Bakker5121ce52009-01-03 21:22:43 +000058#define SSL_DEBUG_MSG( level, args ) \
59 debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args );
60
61#define SSL_DEBUG_RET( level, text, ret ) \
62 debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret );
63
64#define SSL_DEBUG_BUF( level, text, buf, len ) \
65 debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len );
66
Paul Bakkered27a042013-04-18 22:46:23 +020067#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000068#define SSL_DEBUG_MPI( level, text, X ) \
69 debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X );
Paul Bakkered27a042013-04-18 22:46:23 +020070#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Paul Bakkered27a042013-04-18 22:46:23 +020072#if defined(POLARSSL_ECP_C)
Paul Bakker41c83d32013-03-20 14:39:14 +010073#define SSL_DEBUG_ECP( level, text, X ) \
74 debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X );
Paul Bakkered27a042013-04-18 22:46:23 +020075#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010076
Paul Bakker7c6b2c32013-09-16 13:49:26 +020077#if defined(POLARSSL_X509_CRT_PARSE_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000078#define SSL_DEBUG_CRT( level, text, crt ) \
79 debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt );
Paul Bakkered27a042013-04-18 22:46:23 +020080#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000081
Paul Bakker9af723c2014-05-01 13:03:14 +020082#else /* POLARSSL_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000083
84#define SSL_DEBUG_MSG( level, args ) do { } while( 0 )
85#define SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
86#define SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
87#define SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
Paul Bakker41c83d32013-03-20 14:39:14 +010088#define SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000089#define SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
90
Paul Bakker9af723c2014-05-01 13:03:14 +020091#endif /* POLARSSL_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000092
93#ifdef __cplusplus
94extern "C" {
95#endif
96
Paul Bakkerc73079a2014-04-25 16:34:30 +020097/**
98 * \brief Set the log mode for the debug functions globally
99 * (Default value: POLARSSL_DEBUG_DFL_MODE)
100 *
101 * \param log_mode The log mode to use (POLARSSL_DEBUG_LOG_FULL or
102 * POLARSSL_DEBUG_LOG_RAW)
103 */
104void debug_set_log_mode( int log_mode );
105
106/**
107 * \brief Set the level threshold to handle globally. Messages that have a
108 * level over the threshold value are ignored.
109 * (Default value: 0 (No debug))
110 *
111 * \param threshold maximum level of messages to pass on
112 */
113void debug_set_threshold( int threshold );
114
Paul Bakker5121ce52009-01-03 21:22:43 +0000115char *debug_fmt( const char *format, ... );
116
Paul Bakkerff60ee62010-03-16 21:09:09 +0000117void debug_print_msg( const ssl_context *ssl, int level,
118 const char *file, int line, const char *text );
Paul Bakker5121ce52009-01-03 21:22:43 +0000119
Paul Bakkerff60ee62010-03-16 21:09:09 +0000120void debug_print_ret( const ssl_context *ssl, int level,
121 const char *file, int line,
122 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000123
Paul Bakkerff60ee62010-03-16 21:09:09 +0000124void debug_print_buf( const ssl_context *ssl, int level,
125 const char *file, int line, const char *text,
Paul Bakker23986e52011-04-24 08:57:21 +0000126 unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000127
Paul Bakkered27a042013-04-18 22:46:23 +0200128#if defined(POLARSSL_BIGNUM_C)
Paul Bakkerff60ee62010-03-16 21:09:09 +0000129void debug_print_mpi( const ssl_context *ssl, int level,
130 const char *file, int line,
131 const char *text, const mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200132#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000133
Paul Bakker41c83d32013-03-20 14:39:14 +0100134#if defined(POLARSSL_ECP_C)
135void debug_print_ecp( const ssl_context *ssl, int level,
136 const char *file, int line,
137 const char *text, const ecp_point *X );
138#endif
139
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200140#if defined(POLARSSL_X509_CRT_PARSE_C)
Paul Bakkerff60ee62010-03-16 21:09:09 +0000141void debug_print_crt( const ssl_context *ssl, int level,
142 const char *file, int line,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200143 const char *text, const x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200144#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000145
146#ifdef __cplusplus
147}
148#endif
149
150#endif /* debug.h */