esp_tls_error_capture_internal.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_TLS_ERROR_CAPTURE_INTERNAL_H__
  14. #define __ESP_TLS_ERROR_CAPTURE_INTERNAL_H__
  15. /**
  16. * Note: this is an implementation placeholder for error logger.
  17. * This version is internal to esp-tls component and only saves single esp_err of last occurred error
  18. */
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * Definition of different types/sources of error codes reported
  24. * from different components
  25. */
  26. typedef enum {
  27. ERR_TYPE_UNKNOWN = 0,
  28. ERR_TYPE_SYSTEM,
  29. ERR_TYPE_MBEDTLS,
  30. ERR_TYPE_MBEDTLS_CERT_FLAGS,
  31. ERR_TYPE_ESP,
  32. ERR_TYPE_WOLFSSL,
  33. ERR_TYPE_WOLFSSL_CERT_FLAGS,
  34. } err_type_t;
  35. /**
  36. * Error tracker logging macro, this implementation saves latest errors of
  37. * ERR_TYPE_ESP, ERR_TYPE_ESP_TLS and ERR_TYPE_ESP_TLS_CERT_FLAGS types
  38. */
  39. #define ESP_INT_EVENT_TRACKER_CAPTURE(h, type, code) esp_int_event_tracker_capture(h, type, code)
  40. static inline void esp_int_event_tracker_capture(esp_tls_error_handle_t h, uint32_t type, int code)
  41. {
  42. if (h) {
  43. if (type == ERR_TYPE_ESP) {
  44. h->last_error = code;
  45. } else if (type == ERR_TYPE_MBEDTLS) {
  46. h->esp_tls_error_code = code;
  47. } else if (type == ERR_TYPE_MBEDTLS_CERT_FLAGS) {
  48. h->esp_tls_flags = code;
  49. } else if (type == ERR_TYPE_WOLFSSL) {
  50. h->esp_tls_error_code = code;
  51. } else if (type == ERR_TYPE_WOLFSSL_CERT_FLAGS) {
  52. h->esp_tls_flags = code;
  53. }
  54. }
  55. }
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif //__ESP_TLS_ERROR_CAPTURE_INTERNAL_H__