| 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 | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 6 | *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved | 
| Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 7 | *  SPDX-License-Identifier: Apache-2.0 | 
|  | 8 | * | 
|  | 9 | *  Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 10 | *  not use this file except in compliance with the License. | 
|  | 11 | *  You may obtain a copy of the License at | 
|  | 12 | * | 
|  | 13 | *  http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 14 | * | 
|  | 15 | *  Unless required by applicable law or agreed to in writing, software | 
|  | 16 | *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 17 | *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 18 | *  See the License for the specific language governing permissions and | 
|  | 19 | *  limitations under the License. | 
| Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 20 | * | 
| Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 21 | *  This file is part of mbed TLS (https://tls.mbed.org) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 22 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 23 | #ifndef MBEDTLS_DEBUG_H | 
|  | 24 | #define MBEDTLS_DEBUG_H | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 25 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 26 | #if !defined(MBEDTLS_CONFIG_FILE) | 
| Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 27 | #include "config.h" | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 28 | #else | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 29 | #include MBEDTLS_CONFIG_FILE | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 30 | #endif | 
| Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 31 |  | 
| Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 32 | #include "ssl.h" | 
| Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 33 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 34 | #if defined(MBEDTLS_ECP_C) | 
| Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 35 | #include "ecp.h" | 
|  | 36 | #endif | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 37 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 38 | #if defined(MBEDTLS_DEBUG_C) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 39 |  | 
| Manuel Pégourié-Gonnard | b74c245 | 2015-06-29 20:08:23 +0200 | [diff] [blame] | 40 | #define MBEDTLS_DEBUG_STRIP_PARENS( ... )   __VA_ARGS__ | 
|  | 41 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 42 | #define MBEDTLS_SSL_DEBUG_MSG( level, args )                    \ | 
| Manuel Pégourié-Gonnard | a16e7c4 | 2015-06-29 20:14:19 +0200 | [diff] [blame] | 43 | mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__,    \ | 
| Manuel Pégourié-Gonnard | b74c245 | 2015-06-29 20:08:23 +0200 | [diff] [blame] | 44 | MBEDTLS_DEBUG_STRIP_PARENS args ) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 45 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 46 | #define MBEDTLS_SSL_DEBUG_RET( level, text, ret )                \ | 
| Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 47 | mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret ) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 48 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 49 | #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len )           \ | 
| Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 50 | mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len ) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | #if defined(MBEDTLS_BIGNUM_C) | 
|  | 53 | #define MBEDTLS_SSL_DEBUG_MPI( level, text, X )                  \ | 
| Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 54 | mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X ) | 
| Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 55 | #endif | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 56 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 57 | #if defined(MBEDTLS_ECP_C) | 
|  | 58 | #define MBEDTLS_SSL_DEBUG_ECP( level, text, X )                  \ | 
| Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 59 | mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X ) | 
| Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 60 | #endif | 
| Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 61 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | #if defined(MBEDTLS_X509_CRT_PARSE_C) | 
|  | 63 | #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt )                \ | 
| Manuel Pégourié-Gonnard | 2ff873c | 2015-05-19 14:38:09 +0200 | [diff] [blame] | 64 | mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt ) | 
| Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 65 | #endif | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 66 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 67 | #else /* MBEDTLS_DEBUG_C */ | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 68 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | #define MBEDTLS_SSL_DEBUG_MSG( level, args )            do { } while( 0 ) | 
|  | 70 | #define MBEDTLS_SSL_DEBUG_RET( level, text, ret )       do { } while( 0 ) | 
|  | 71 | #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len )  do { } while( 0 ) | 
|  | 72 | #define MBEDTLS_SSL_DEBUG_MPI( level, text, X )         do { } while( 0 ) | 
|  | 73 | #define MBEDTLS_SSL_DEBUG_ECP( level, text, X )         do { } while( 0 ) | 
|  | 74 | #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt )       do { } while( 0 ) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 75 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 76 | #endif /* MBEDTLS_DEBUG_C */ | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 77 |  | 
|  | 78 | #ifdef __cplusplus | 
|  | 79 | extern "C" { | 
|  | 80 | #endif | 
|  | 81 |  | 
| Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 82 | /** | 
| Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 83 | * \brief   Set the level threshold to handle globally. Messages that have a | 
|  | 84 | *          level over the threshold value are ignored. | 
|  | 85 | *          (Default value: 0 (No debug)) | 
|  | 86 | * | 
|  | 87 | * \param threshold     maximum level of messages to pass on | 
|  | 88 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 89 | void mbedtls_debug_set_threshold( int threshold ); | 
| Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 90 |  | 
| Manuel Pégourié-Gonnard | a16e7c4 | 2015-06-29 20:14:19 +0200 | [diff] [blame] | 91 | void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level, | 
| Manuel Pégourié-Gonnard | b74c245 | 2015-06-29 20:08:23 +0200 | [diff] [blame] | 92 | const char *file, int line, | 
|  | 93 | const char *format, ... ); | 
| Manuel Pégourié-Gonnard | d23f593 | 2015-06-23 12:04:52 +0200 | [diff] [blame] | 94 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 95 | void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level, | 
| Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 96 | const char *file, int line, | 
|  | 97 | const char *text, int ret ); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 98 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 99 | void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level, | 
| Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 100 | const char *file, int line, const char *text, | 
| Manuel Pégourié-Gonnard | a78b218 | 2015-03-19 17:16:11 +0000 | [diff] [blame] | 101 | const unsigned char *buf, size_t len ); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 102 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 103 | #if defined(MBEDTLS_BIGNUM_C) | 
|  | 104 | void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level, | 
| Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 105 | const char *file, int line, | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 106 | const char *text, const mbedtls_mpi *X ); | 
| Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 107 | #endif | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 108 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 109 | #if defined(MBEDTLS_ECP_C) | 
|  | 110 | void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level, | 
| Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 111 | const char *file, int line, | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 112 | const char *text, const mbedtls_ecp_point *X ); | 
| Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 113 | #endif | 
|  | 114 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 115 | #if defined(MBEDTLS_X509_CRT_PARSE_C) | 
|  | 116 | void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level, | 
| Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 117 | const char *file, int line, | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 118 | const char *text, const mbedtls_x509_crt *crt ); | 
| Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 119 | #endif | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 120 |  | 
|  | 121 | #ifdef __cplusplus | 
|  | 122 | } | 
|  | 123 | #endif | 
|  | 124 |  | 
|  | 125 | #endif /* debug.h */ |