From 2ae2388cefc08594f538f6e01bc012f43880da82 Mon Sep 17 00:00:00 2001 From: Jakub Kramarz Date: Sun, 26 Jan 2025 14:30:01 +0100 Subject: [PATCH] util_hdsio: extract getSioMediaTypeInfo --- client/CMakeLists.txt | 1 + client/Makefile | 1 + client/src/cmdhfseos.c | 28 +--------------------- client/src/cmdhfseos.h | 6 ----- client/src/util_hidsio.c | 51 ++++++++++++++++++++++++++++++++++++++++ client/src/util_hidsio.h | 26 ++++++++++++++++++++ 6 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 client/src/util_hidsio.c create mode 100644 client/src/util_hidsio.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 2a74b1500..dc3d0a21d 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -425,6 +425,7 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/scripting.c ${PM3_ROOT}/client/src/ui.c ${PM3_ROOT}/client/src/util.c + ${PM3_ROOT}/client/src/util_hidsio.c ${PM3_ROOT}/client/src/wiegand_formats.c ${PM3_ROOT}/client/src/wiegand_formatutils.c ${CMAKE_BINARY_DIR}/version_pm3.c diff --git a/client/Makefile b/client/Makefile index d01e08af0..523b8b657 100644 --- a/client/Makefile +++ b/client/Makefile @@ -759,6 +759,7 @@ SRCS = mifare/aiddesfire.c \ scripting.c \ ui.c \ util.c \ + util_hidsio.c \ version_pm3.c \ wiegand_formats.c \ wiegand_formatutils.c diff --git a/client/src/cmdhfseos.c b/client/src/cmdhfseos.c index 02dec90ab..c5fe9d8c1 100644 --- a/client/src/cmdhfseos.c +++ b/client/src/cmdhfseos.c @@ -38,6 +38,7 @@ #include "crypto/libpcrypto.h" // AES decrypt #include "commonutil.h" // get_sw #include "protocols.h" // ISO7816 APDU return codes +#include "util_hidsio.h" static uint8_t zeros[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -100,17 +101,6 @@ static const known_algo_t known_algorithm_map[] = { {9, "AES-128_CBC_MODE"}, }; -static const sioMediaTypeName_t sioMediaTypeMapping[] = { - { 0x00, "Unknown"}, - { 0x01, "DESFire"}, - { 0x02, "MIFARE"}, - { 0x03, "iCLASS (PicoPass)"}, - { 0x04, "ISO14443AL4"}, - { 0x06, "MIFARE Plus"}, - { 0x07, "Seos"}, - { 0xFF, "INVALID VALUE"} -}; - static int create_cmac(uint8_t *key, uint8_t *input, uint8_t *out, int input_len, int encryption_algorithm) { uint8_t iv[16] = {0x00}; @@ -1638,22 +1628,6 @@ static int CmdHfSeosList(const char *Cmd) { return CmdTraceListAlias(Cmd, "hf seos", "seos -c"); } -// get a SIO media type based on the UID -// uid[8] tag uid -// returns description of the best match -static const char *getSioMediaTypeInfo(uint8_t uid) { - - for (int i = 0; i < ARRAYLEN(sioMediaTypeMapping); ++i) { - if (uid == sioMediaTypeMapping[i].uid) { - return sioMediaTypeMapping[i].desc; - } - } - - //No match, return default - return sioMediaTypeMapping[ARRAYLEN(sioMediaTypeMapping) - 1].desc; -} - - static int CmdHfSeosSAM(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf seos sam", diff --git a/client/src/cmdhfseos.h b/client/src/cmdhfseos.h index f75e070d5..f1dfe99a0 100644 --- a/client/src/cmdhfseos.h +++ b/client/src/cmdhfseos.h @@ -21,12 +21,6 @@ #include "common.h" -// structure and database for uid -> tagtype lookups -typedef struct { - uint8_t uid; - const char *desc; -} sioMediaTypeName_t; - int infoSeos(bool verbose); int CmdHFSeos(const char *Cmd); int seos_kdf(bool encryption, uint8_t *masterKey, uint8_t keyslot, diff --git a/client/src/util_hidsio.c b/client/src/util_hidsio.c new file mode 100644 index 000000000..932999c27 --- /dev/null +++ b/client/src/util_hidsio.c @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// 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, either version 3 of the License, or +// (at your option) any later version. +// +// 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. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// HID Global SIO utilities +//----------------------------------------------------------------------------- +#include "commonutil.h" +#include "util_hidsio.h" + +// structure and database for uid -> tagtype lookups +typedef struct { + uint8_t uid; + const char *desc; +} sioMediaTypeName_t; + +static const sioMediaTypeName_t sioMediaTypeMapping[] = { + { 0x00, "Unknown"}, + { 0x01, "DESFire"}, + { 0x02, "MIFARE"}, + { 0x03, "iCLASS (PicoPass)"}, + { 0x04, "ISO14443AL4"}, + { 0x06, "MIFARE Plus"}, + { 0x07, "Seos"}, + { 0xFF, "INVALID VALUE"} +}; + +// get a SIO media type based on the UID +// uid[8] tag uid +// returns description of the best match +const char *getSioMediaTypeInfo(uint8_t uid) { + + for (int i = 0; i < ARRAYLEN(sioMediaTypeMapping); ++i) { + if (uid == sioMediaTypeMapping[i].uid) { + return sioMediaTypeMapping[i].desc; + } + } + + //No match, return default + return sioMediaTypeMapping[ARRAYLEN(sioMediaTypeMapping) - 1].desc; +} diff --git a/client/src/util_hidsio.h b/client/src/util_hidsio.h new file mode 100644 index 000000000..5c68f342b --- /dev/null +++ b/client/src/util_hidsio.h @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// 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, either version 3 of the License, or +// (at your option) any later version. +// +// 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. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// HID Global SIO utilities +//----------------------------------------------------------------------------- +#ifndef __UTIL_HIDSIO_H_ +#define __UTIL_HIDSIO_H_ + +#include "common.h" +#include "stdint.h" + +const char *getSioMediaTypeInfo(uint8_t uid); + +#endif