From e70552a2987f8ef9cc5d71ddae94e97d0c058306 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 11 Sep 2024 23:15:09 +0200 Subject: [PATCH] Move debug to dedicated header Signed-off-by: Pol Henarejos --- src/apdu.h | 36 ----------------------------------- src/debug.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 36 deletions(-) create mode 100644 src/debug.h diff --git a/src/apdu.h b/src/apdu.h index 89c04b5..ffa601b 100644 --- a/src/apdu.h +++ b/src/apdu.h @@ -41,42 +41,6 @@ typedef struct cmd { int (*cmd_handler)(); } cmd_t; - -#if defined(DEBUG_APDU) && DEBUG_APDU == 1 -#define DEBUG_PAYLOAD(_p, _s) { \ - printf("Payload %s (%d bytes):\n", #_p, (int) (_s)); \ - for (int _i = 0; _i < _s; _i += 16) { \ - printf("%" PRIxPTR "h : ", (uintptr_t) (_i + _p)); \ - for (int _j = 0; _j < 16; _j++) { \ - if (_j < _s - _i) printf("%02X ", (_p)[_i + _j]); \ - else printf(" "); \ - if (_j == 7) printf(" "); \ - } printf(": "); \ - for (int _j = 0; _j < 16; _j++) { \ - if (_j < _s - _i && (_p)[_i + _j] > 32 && (_p)[_i + _j] != 127 && (_p)[_i + _j] < 176) printf("%c", (_p)[_i + _j]); \ - else printf(" "); \ - if (_j == 7) printf(" "); \ - } \ - printf("\n"); \ - } printf("\n"); \ -} -#define DEBUG_DATA(_p, _s) \ - { \ - printf("Data %s (%d bytes):\n", #_p, (int) (_s)); \ - char *tmp = (char *) calloc(1, 2 * _s + 1); \ - for (int _i = 0; _i < _s; _i++) \ - { \ - sprintf(&tmp[2 * _i], "%02X", (_p)[_i]); \ - } \ - printf("%s\n", tmp); \ - free(tmp); \ - } - -#else -#define DEBUG_PAYLOAD(_p, _s) -#define DEBUG_DATA(_p, _s) -#endif - extern uint8_t num_apps; extern app_t apps[4]; extern app_t *current_app; diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..b5a2ca0 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,54 @@ +/* + * This file is part of the Pico Keys SDK distribution (https://github.com/polhenarejos/pico-keys-sdk). + * Copyright (c) 2022 Pol Henarejos. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#if defined(DEBUG_APDU) && DEBUG_APDU == 1 +#define DEBUG_PAYLOAD(_p, _s) { \ + printf("Payload %s (%d bytes):\n", #_p, (int) (_s)); \ + for (int _i = 0; _i < _s; _i += 16) { \ + printf("%" PRIxPTR "h : ", (uintptr_t) (_i + _p)); \ + for (int _j = 0; _j < 16; _j++) { \ + if (_j < _s - _i) printf("%02X ", (_p)[_i + _j]); \ + else printf(" "); \ + if (_j == 7) printf(" "); \ + } printf(": "); \ + for (int _j = 0; _j < 16; _j++) { \ + if (_j < _s - _i && (_p)[_i + _j] > 32 && (_p)[_i + _j] != 127 && (_p)[_i + _j] < 176) printf("%c", (_p)[_i + _j]); \ + else printf(" "); \ + if (_j == 7) printf(" "); \ + } \ + printf("\n"); \ + } printf("\n"); \ +} +#define DEBUG_DATA(_p, _s) { \ + printf("Data %s (%d bytes):\n", #_p, (int) (_s)); \ + char *_tmp = (char *) calloc(1, 2 * _s + 1); \ + for (int _i = 0; _i < _s; _i++) { \ + sprintf(&_tmp[2 * _i], "%02X", (_p)[_i]); \ + } \ + printf("%s\n", _tmp); \ + free(_tmp); \ + } + +#else +#define DEBUG_PAYLOAD(_p, _s) +#define DEBUG_DATA(_p, _s) +#endif + +#endif // _DEBUG_H_