2016-11-26 00:58:50 +00:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <strings.h>
|
|
|
|
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "mbedtls/platform.h"
|
|
|
|
#include "mbedtls/debug.h"
|
|
|
|
#include "mbedtls/ssl.h"
|
|
|
|
#include "mbedtls/esp_debug.h"
|
|
|
|
|
2018-11-11 07:44:54 +00:00
|
|
|
#ifdef CONFIG_MBEDTLS_DEBUG
|
2016-11-26 00:58:50 +00:00
|
|
|
static const char *TAG = "mbedtls";
|
|
|
|
|
|
|
|
static void mbedtls_esp_debug(void *ctx, int level,
|
|
|
|
const char *file, int line,
|
|
|
|
const char *str);
|
|
|
|
|
|
|
|
void mbedtls_esp_enable_debug_log(mbedtls_ssl_config *conf, int threshold)
|
|
|
|
{
|
2018-11-11 07:44:54 +00:00
|
|
|
esp_log_level_t level = ESP_LOG_NONE;
|
2016-11-26 00:58:50 +00:00
|
|
|
mbedtls_debug_set_threshold(threshold);
|
|
|
|
mbedtls_ssl_conf_dbg(conf, mbedtls_esp_debug, NULL);
|
|
|
|
switch(threshold) {
|
|
|
|
case 1:
|
|
|
|
level = ESP_LOG_WARN;
|
2018-06-14 16:11:21 +00:00
|
|
|
break;
|
2016-11-26 00:58:50 +00:00
|
|
|
case 2:
|
|
|
|
level = ESP_LOG_INFO;
|
2018-06-14 16:11:21 +00:00
|
|
|
break;
|
2016-11-26 00:58:50 +00:00
|
|
|
case 3:
|
|
|
|
level = ESP_LOG_DEBUG;
|
2018-06-14 16:11:21 +00:00
|
|
|
break;
|
2016-11-26 00:58:50 +00:00
|
|
|
case 4:
|
|
|
|
level = ESP_LOG_VERBOSE;
|
2018-06-14 16:11:21 +00:00
|
|
|
break;
|
2016-11-26 00:58:50 +00:00
|
|
|
}
|
|
|
|
esp_log_level_set(TAG, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mbedtls_esp_disable_debug_log(mbedtls_ssl_config *conf)
|
|
|
|
{
|
|
|
|
mbedtls_ssl_conf_dbg(conf, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2018-11-11 07:44:54 +00:00
|
|
|
|
2016-11-26 00:58:50 +00:00
|
|
|
/* Default mbedtls debug function that translates mbedTLS debug output
|
|
|
|
to ESP_LOGx debug output.
|
|
|
|
*/
|
|
|
|
static void mbedtls_esp_debug(void *ctx, int level,
|
|
|
|
const char *file, int line,
|
|
|
|
const char *str)
|
|
|
|
{
|
|
|
|
char *file_sep;
|
|
|
|
|
|
|
|
/* Shorten 'file' from the whole file path to just the filename
|
|
|
|
|
|
|
|
This is a bit wasteful because the macros are compiled in with
|
|
|
|
the full _FILE_ path in each case.
|
|
|
|
*/
|
|
|
|
file_sep = rindex(file, '/');
|
|
|
|
if(file_sep)
|
|
|
|
file = file_sep+1;
|
|
|
|
|
|
|
|
switch(level) {
|
|
|
|
case 1:
|
|
|
|
ESP_LOGW(TAG, "%s:%d %s", file, line, str);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ESP_LOGI(TAG, "%s:%d %s", file, line, str);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ESP_LOGD(TAG, "%s:%d %s", file, line, str);
|
2018-06-14 16:11:21 +00:00
|
|
|
break;
|
2016-11-26 00:58:50 +00:00
|
|
|
case 4:
|
|
|
|
ESP_LOGV(TAG, "%s:%d %s", file, line, str);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ESP_LOGE(TAG, "Unexpected log level %d: %s", level, str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 07:40:01 +00:00
|
|
|
#endif
|