blob: 618a68ce158a80af88af483ed5c27b2dea33867b [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é-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * 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 Bakker5121ce52009-01-03 21:22:43 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_DEBUG_H
25#define MBEDTLS_DEBUG_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Rich Evans00ab4702015-02-06 13:43:58 +000032
Paul Bakker314052f2011-08-15 09:07:52 +000033#include "ssl.h"
Rich Evans00ab4702015-02-06 13:43:58 +000034
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#if defined(MBEDTLS_ECP_C)
Paul Bakker41c83d32013-03-20 14:39:14 +010036#include "ecp.h"
37#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000038
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000040
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +020042 mbedtls_debug_print_msg_free( ssl, level, __FILE__, __LINE__, mbedtls_debug_fmt args )
Paul Bakker5121ce52009-01-03 21:22:43 +000043
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020045 mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
Paul Bakker5121ce52009-01-03 21:22:43 +000046
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020048 mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
Paul Bakker5121ce52009-01-03 21:22:43 +000049
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#if defined(MBEDTLS_BIGNUM_C)
51#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020052 mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020053#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_ECP_C)
56#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020057 mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
Paul Bakkered27a042013-04-18 22:46:23 +020058#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_X509_CRT_PARSE_C)
61#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
Manuel Pégourié-Gonnard2ff873c2015-05-19 14:38:09 +020062 mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
Paul Bakkered27a042013-04-18 22:46:23 +020063#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000064
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#else /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000066
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
68#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
69#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
70#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
71#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
72#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000073
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074#endif /* MBEDTLS_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000075
76#ifdef __cplusplus
77extern "C" {
78#endif
79
Paul Bakkerc73079a2014-04-25 16:34:30 +020080/**
Paul Bakkerc73079a2014-04-25 16:34:30 +020081 * \brief Set the level threshold to handle globally. Messages that have a
82 * level over the threshold value are ignored.
83 * (Default value: 0 (No debug))
84 *
85 * \param threshold maximum level of messages to pass on
86 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087void mbedtls_debug_set_threshold( int threshold );
Paul Bakkerc73079a2014-04-25 16:34:30 +020088
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089char *mbedtls_debug_fmt( const char *format, ... );
Paul Bakker5121ce52009-01-03 21:22:43 +000090
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +000092 const char *file, int line, const char *text );
Paul Bakker5121ce52009-01-03 21:22:43 +000093
Manuel Pégourié-Gonnardd23f5932015-06-23 12:04:52 +020094void mbedtls_debug_print_msg_free( const mbedtls_ssl_context *ssl, int level,
95 const char *file, int line, char *text );
96
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +000098 const char *file, int line,
99 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000100
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000102 const char *file, int line, const char *text,
Manuel Pégourié-Gonnarda78b2182015-03-19 17:16:11 +0000103 const unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000104
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105#if defined(MBEDTLS_BIGNUM_C)
106void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000107 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108 const char *text, const mbedtls_mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200109#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000110
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#if defined(MBEDTLS_ECP_C)
112void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
Paul Bakker41c83d32013-03-20 14:39:14 +0100113 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114 const char *text, const mbedtls_ecp_point *X );
Paul Bakker41c83d32013-03-20 14:39:14 +0100115#endif
116
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117#if defined(MBEDTLS_X509_CRT_PARSE_C)
118void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000119 const char *file, int line,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120 const char *text, const mbedtls_x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200121#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000122
123#ifdef __cplusplus
124}
125#endif
126
127#endif /* debug.h */