debug.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * \file debug.h
  3. *
  4. * \brief Debug functions
  5. *
  6. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  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.
  20. *
  21. * This file is part of mbed TLS (https://tls.mbed.org)
  22. */
  23. #ifndef MBEDTLS_DEBUG_H
  24. #define MBEDTLS_DEBUG_H
  25. #if !defined(MBEDTLS_CONFIG_FILE)
  26. #include "config.h"
  27. #else
  28. #include MBEDTLS_CONFIG_FILE
  29. #endif
  30. #include "ssl.h"
  31. #if defined(MBEDTLS_ECP_C)
  32. #include "ecp.h"
  33. #endif
  34. #if defined(MBEDTLS_DEBUG_C)
  35. #define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
  36. #define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
  37. mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
  38. MBEDTLS_DEBUG_STRIP_PARENS args )
  39. #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
  40. mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
  41. #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
  42. mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
  43. #if defined(MBEDTLS_BIGNUM_C)
  44. #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
  45. mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
  46. #endif
  47. #if defined(MBEDTLS_ECP_C)
  48. #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
  49. mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
  50. #endif
  51. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  52. #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
  53. mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
  54. #endif
  55. #else /* MBEDTLS_DEBUG_C */
  56. #define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
  57. #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
  58. #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
  59. #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
  60. #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
  61. #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
  62. #endif /* MBEDTLS_DEBUG_C */
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif
  66. /**
  67. * \brief Set the level threshold to handle globally. Messages that have a
  68. * level over the threshold value are ignored.
  69. * (Default value: 0 (No debug))
  70. *
  71. * \param threshold maximum level of messages to pass on
  72. */
  73. void mbedtls_debug_set_threshold( int threshold );
  74. void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
  75. const char *file, int line,
  76. const char *format, ... );
  77. void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
  78. const char *file, int line,
  79. const char *text, int ret );
  80. void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
  81. const char *file, int line, const char *text,
  82. const unsigned char *buf, size_t len );
  83. #if defined(MBEDTLS_BIGNUM_C)
  84. void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
  85. const char *file, int line,
  86. const char *text, const mbedtls_mpi *X );
  87. #endif
  88. #if defined(MBEDTLS_ECP_C)
  89. void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
  90. const char *file, int line,
  91. const char *text, const mbedtls_ecp_point *X );
  92. #endif
  93. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  94. void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
  95. const char *file, int line,
  96. const char *text, const mbedtls_x509_crt *crt );
  97. #endif
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif /* debug.h */