Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SE05X: Use Arduino_DebugUtils for debugging #247

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extras/tls/mbedtls_alt/ecdsa_se05x.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include "se05x_mbedtls.h"
//#include "se05x_APDU_apis.h"
#include <SE05X.h>
#include <SE05XDebug.h>

extern int mbedtls_ecdsa_sign_o(mbedtls_ecp_group *grp,
mbedtls_mpi *r,
Expand Down
2 changes: 2 additions & 0 deletions libraries/SE05X/src/SE05X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

#include "SE05X.h"
#include "SE05XDebug.h"


/**
* 26 bytes see ecc_der_header_nist256
Expand Down
3 changes: 1 addition & 2 deletions libraries/SE05X/src/SE05X.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extern "C" {
#endif

#include "lib/apdu/se05x_APDU_apis.h"
#include "lib/platform/arduino/sm_port.h"

#ifdef __cplusplus
}
Expand Down Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions libraries/SE05X/src/SE05XDebug.h
Original file line number Diff line number Diff line change
@@ -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
32 changes: 22 additions & 10 deletions libraries/SE05X/src/lib/platform/arduino/sm_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<Arduino_DebugUtils.h>)
#include <Arduino_DebugUtils.h>
#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
}
73 changes: 23 additions & 50 deletions libraries/SE05X/src/lib/platform/arduino/sm_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Binary file modified libraries/SSLClient/src/cortex-m33/libmbedse05x.a
Binary file not shown.