From ee207b5ad839e0c06fc3b678ada5636201f1b398 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 23 Jan 2024 10:03:12 +0100 Subject: [PATCH 1/4] SE05X: Use Arduino_DebugUtils for debugging --- libraries/SE05X/src/SE05X.cpp | 1 + libraries/SE05X/src/SE05X.h | 1 - .../src/lib/platform/arduino/sm_port.cpp | 32 +++++--- .../SE05X/src/lib/platform/arduino/sm_port.h | 73 ++++++------------- 4 files changed, 46 insertions(+), 61 deletions(-) diff --git a/libraries/SE05X/src/SE05X.cpp b/libraries/SE05X/src/SE05X.cpp index 30e82e93c..8f5aa58cc 100644 --- a/libraries/SE05X/src/SE05X.cpp +++ b/libraries/SE05X/src/SE05X.cpp @@ -18,6 +18,7 @@ */ #include "SE05X.h" +#include "lib/platform/arduino/sm_port.h" /** * 26 bytes see ecc_der_header_nist256 diff --git a/libraries/SE05X/src/SE05X.h b/libraries/SE05X/src/SE05X.h index 149414b0f..0f80abc3b 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 } 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 From 681c69f3546bab56e656e9be8e6c954def1c3227 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 23 Jan 2024 11:47:18 +0100 Subject: [PATCH 2/4] mbedtls_alt: Allow library to build --- extras/tls/mbedtls_alt/ecdsa_se05x.c | 2 +- libraries/SE05X/src/SE05X.cpp | 3 ++- libraries/SE05X/src/SE05XDebug.h | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 libraries/SE05X/src/SE05XDebug.h 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 8f5aa58cc..b5f799607 100644 --- a/libraries/SE05X/src/SE05X.cpp +++ b/libraries/SE05X/src/SE05X.cpp @@ -18,7 +18,8 @@ */ #include "SE05X.h" -#include "lib/platform/arduino/sm_port.h" +#include "SE05XDebug.h" + /** * 26 bytes see ecc_der_header_nist256 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 From c5ab61201abe5489d3feb1e37f13a5593f22e641 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 23 Jan 2024 11:55:02 +0100 Subject: [PATCH 3/4] SSLClient: rebuild libmbedse05x.a after debug changes --- .../SSLClient/src/cortex-m33/libmbedse05x.a | Bin 7012 -> 7008 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/libraries/SSLClient/src/cortex-m33/libmbedse05x.a b/libraries/SSLClient/src/cortex-m33/libmbedse05x.a index dc492d8d29488f045ea5f4232b31a87005674de6..3ea7d34874c93d14bdd3ec7a9cc01b867f98753b 100644 GIT binary patch delta 1014 zcm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}V0urSJ{G4>$LVKr`hA@K{=YUt0$O!g!<0B( zK>E_QsobsZ<3vhZ_CXe1!>|pquy;k@W=sPZXG{lp zv*OP(YH2R*&%VQq831lZ+J{%rS4V?3utE<|8Y5}bwyHP)Pw=z$1frK(r!%20a#mNQ z$X5|JuO~w~0o^0dbwy~3Ea-~3#sq*(WPvwv-D-f##GulWy?X7M|5qRE(9fv;0;Eqv AdH?_b From 46a4601be6922cad08156c7b82689dbf72376297 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 23 Jan 2024 14:51:27 +0100 Subject: [PATCH 4/4] SE05X: avoid unused variable warning --- libraries/SE05X/src/SE05X.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SE05X/src/SE05X.h b/libraries/SE05X/src/SE05X.h index 0f80abc3b..f855a6baf 100644 --- a/libraries/SE05X/src/SE05X.h +++ b/libraries/SE05X/src/SE05X.h @@ -324,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: