diff --git a/extras/tls/mbedtls_alt/ecdsa_se05x.c b/extras/tls/mbedtls_alt/ecdsa_se05x.c index 2950aa0e4..6979d721d 100644 --- a/extras/tls/mbedtls_alt/ecdsa_se05x.c +++ b/extras/tls/mbedtls_alt/ecdsa_se05x.c @@ -33,7 +33,7 @@ #include "se05x_mbedtls.h" //#include "se05x_APDU_apis.h" -#include +#include extern int mbedtls_ecdsa_sign_o(mbedtls_ecp_group *grp, mbedtls_mpi *r, diff --git a/libraries/SE05X/src/SE05X.cpp b/libraries/SE05X/src/SE05X.cpp index 30e82e93c..b5f799607 100644 --- a/libraries/SE05X/src/SE05X.cpp +++ b/libraries/SE05X/src/SE05X.cpp @@ -18,6 +18,8 @@ */ #include "SE05X.h" +#include "SE05XDebug.h" + /** * 26 bytes see ecc_der_header_nist256 diff --git a/libraries/SE05X/src/SE05X.h b/libraries/SE05X/src/SE05X.h index 149414b0f..f855a6baf 100644 --- a/libraries/SE05X/src/SE05X.h +++ b/libraries/SE05X/src/SE05X.h @@ -27,7 +27,6 @@ extern "C" { #endif #include "lib/apdu/se05x_APDU_apis.h" -#include "lib/platform/arduino/sm_port.h" #ifdef __cplusplus } @@ -325,7 +324,7 @@ class SE05XClass inline int locked() { return 1; } inline int lock() { return 1; } - inline int writeConfiguration(const byte data[]) { return 1; } + inline int writeConfiguration(const byte data[]) { (void)data; return 1; } inline Se05xSession_t* getSession() { return &_se05x_session; } private: diff --git a/libraries/SE05X/src/SE05XDebug.h b/libraries/SE05X/src/SE05XDebug.h new file mode 100644 index 000000000..19770889f --- /dev/null +++ b/libraries/SE05X/src/SE05XDebug.h @@ -0,0 +1,25 @@ +/* + SE05XDebug.h + Copyright (c) 2023 Arduino SA. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _SE05X_DEBUG_H_ +#define _SE05X_DEBUG_H_ + +#include "lib/platform/arduino/sm_port.h" + +#endif diff --git a/libraries/SE05X/src/lib/platform/arduino/sm_port.cpp b/libraries/SE05X/src/lib/platform/arduino/sm_port.cpp index 3e3f529c9..7690ca87e 100644 --- a/libraries/SE05X/src/lib/platform/arduino/sm_port.cpp +++ b/libraries/SE05X/src/lib/platform/arduino/sm_port.cpp @@ -19,15 +19,27 @@ #include "../../platform/arduino/sm_port.h" -void smlog_print(const char *format, ...) { - char debug_buf[1024]; - va_list argptr; - va_start(argptr, format); - vsprintf(debug_buf, format, argptr); - va_end(argptr); - Serial.print(debug_buf); -} +#if defined __has_include + #if __has_include () + #include + #define SE05X_DEBUG_ENABLE 1 + #else + #define SE05X_DEBUG_ENABLE 0 + #endif +#else + #define SE05X_DEBUG_ENABLE 0 +#endif -void smlog_none(const char *format, ...) { - (void)format; +void smlog_print(int const lvl, const char *fmt, ...) { +#if SE05X_DEBUG_ENABLE + va_list args; + va_start(args, fmt); + Debug.newlineOff(); + Debug.print(lvl, fmt, args); + Debug.newlineOn(); + va_end(args); +#else + (void)lvl; + (void)fmt; +#endif } diff --git a/libraries/SE05X/src/lib/platform/arduino/sm_port.h b/libraries/SE05X/src/lib/platform/arduino/sm_port.h index 04da9e64c..af21c3b44 100644 --- a/libraries/SE05X/src/lib/platform/arduino/sm_port.h +++ b/libraries/SE05X/src/lib/platform/arduino/sm_port.h @@ -22,59 +22,33 @@ #include "Arduino.h" /* - * 0: NONE - * 1: ERROR - * 2: WARNING - * 3: INFO - * 4: DEBUG - * 5: APDU + * -1: NONE + * 0: ERROR + * 1: WARNING + * 2: INFO + * 3: DEBUG + * 4: VERBOSE/APDU */ -#define DEBUG_LEVEL 0 -#if DEBUG_LEVEL > 0 - #define SMLOG_E smlog_print -#else - #define SMLOG_E smlog_none -#endif +#define SMLOG_E(fmt, ...) smlog_print(0, fmt, ## __VA_ARGS__) +#define SMLOG_W(fmt, ...) smlog_print(1, fmt, ## __VA_ARGS__) +#define SMLOG_I(fmt, ...) smlog_print(2, fmt, ## __VA_ARGS__) +#define SMLOG_D(fmt, ...) smlog_print(3, fmt, ## __VA_ARGS__) -#if DEBUG_LEVEL > 1 - #define SMLOG_W smlog_print -#else - #define SMLOG_W smlog_none -#endif +#define SMLOG_AU8_D(BUF, LEN) \ + smlog_print(4, ":"); \ + for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \ + smlog_print(4, "%02x ", BUF[bufIndex]); \ + } \ + smlog_print(4, "\n") -#if DEBUG_LEVEL > 2 - #define SMLOG_I smlog_print -#else - #define SMLOG_I smlog_none -#endif +#define SMLOG_MAU8_D(MSG, BUF, LEN) \ + smlog_print(4, "%s:", MSG); \ + for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \ + smlog_print(4, "%02x ", BUF[bufIndex]); \ + } \ + smlog_print(4, "\n") -#if DEBUG_LEVEL > 3 - #define SMLOG_D smlog_print -#else - #define SMLOG_D smlog_none -#endif - -#if DEBUG_LEVEL > 4 - #define SMLOG_AU8_D(BUF, LEN) \ - smlog_print("%s", ":"); \ - for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \ - smlog_print("%02x ", BUF[bufIndex]); \ - } \ - smlog_print("%s","\n") - - #define SMLOG_MAU8_D(MSG, BUF, LEN) \ - smlog_print("%s", MSG); \ - smlog_print("%s", ":"); \ - for (size_t bufIndex = 0; bufIndex < (size_t)LEN; bufIndex++) { \ - smlog_print("%02x ", BUF[bufIndex]); \ - } \ - smlog_print("%s","\n") - -#else - #define SMLOG_AU8_D(BUF, LEN) - #define SMLOG_MAU8_D(MSG, BUF, LEN) -#endif #define SM_MUTEX_DEFINE(x) #define SM_MUTEX_INIT(x) @@ -98,8 +72,7 @@ #ifdef __cplusplus extern "C" { #endif -void smlog_print(const char *format, ...); -void smlog_none(const char *format, ...); +void smlog_print(int const lvl, const char *fmt, ...); #ifdef __cplusplus } #endif diff --git a/libraries/SSLClient/src/cortex-m33/libmbedse05x.a b/libraries/SSLClient/src/cortex-m33/libmbedse05x.a index dc492d8d2..3ea7d3487 100644 Binary files a/libraries/SSLClient/src/cortex-m33/libmbedse05x.a and b/libraries/SSLClient/src/cortex-m33/libmbedse05x.a differ