From 34a5d15bfc1e41dc370552a63ad1be1fec8d32a7 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 21 Jul 2021 18:10:19 +0300 Subject: [PATCH] command header via array --- client/src/mifare/desfiresecurechan.c | 20 +++++++++++++++----- client/src/mifare/desfiresecurechan.h | 5 +++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/client/src/mifare/desfiresecurechan.c b/client/src/mifare/desfiresecurechan.c index d8d6cdf46..89183d5f3 100644 --- a/client/src/mifare/desfiresecurechan.c +++ b/client/src/mifare/desfiresecurechan.c @@ -52,6 +52,7 @@ AllowedChannelModesS AllowedChannelModes[] = { {MFDES_GET_UID, DACd40, DCCNative, DCMEncrypted}, {MFDES_CHANGE_KEY_SETTINGS, DACd40, DCCNative, DCMEncrypted}, + {MFDES_CHANGE_FILE_SETTINGS, DACd40, DCCNative, DCMEncrypted}, {MFDES_READ_DATA, DACd40, DCCNative, DCMEncrypted}, {MFDES_WRITE_DATA, DACd40, DCCNative, DCMEncrypted}, @@ -73,17 +74,26 @@ AllowedChannelModesS AllowedChannelModes[] = { {MFDES_GET_UID, DACEV1, DCCNative, DCMEncrypted}, {MFDES_CHANGE_KEY_SETTINGS, DACEV1, DCCNative, DCMEncrypted}, + {MFDES_CHANGE_FILE_SETTINGS, DACEV1, DCCNative, DCMEncrypted}, {MFDES_CHANGE_KEY, DACEV1, DCCNative, DCMEncryptedPlain}, {MFDES_CHANGE_KEY_EV2, DACEV1, DCCNative, DCMEncryptedPlain}, }; -static uint8_t DesfireGetCmdHeaderLen(uint8_t cmd) { - if (cmd == MFDES_CHANGE_KEY || cmd == MFDES_CHANGE_CONFIGURATION) - return 1; +#define CMD_HEADER_LEN_ALL 0xffff +CmdHeaderLengthsS CmdHeaderLengths[] = { + {MFDES_CREATE_APPLICATION, CMD_HEADER_LEN_ALL}, + {MFDES_DELETE_APPLICATION, CMD_HEADER_LEN_ALL}, + {MFDES_CHANGE_KEY, 1}, + {MFDES_CHANGE_KEY_EV2, 2}, + {MFDES_CHANGE_CONFIGURATION, 1}, + {MFDES_CHANGE_FILE_SETTINGS, 1}, +}; - if (cmd == MFDES_CHANGE_KEY_EV2) - return 2; +static uint8_t DesfireGetCmdHeaderLen(uint8_t cmd) { + for (int i = 0; i < ARRAY_LENGTH(CmdHeaderLengths); i++) + if (CmdHeaderLengths[i].cmd == cmd) + return CmdHeaderLengths[i].len; return 0; } diff --git a/client/src/mifare/desfiresecurechan.h b/client/src/mifare/desfiresecurechan.h index aa056323a..235e3a41b 100644 --- a/client/src/mifare/desfiresecurechan.h +++ b/client/src/mifare/desfiresecurechan.h @@ -26,6 +26,11 @@ typedef struct { DesfireCommunicationMode commMode; } AllowedChannelModesS; +typedef struct { + uint8_t cmd; + uint32_t len; +} CmdHeaderLengthsS; + void DesfireSecureChannelEncode(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen); void DesfireSecureChannelDecode(DesfireContext *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen);