mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-25 07:35:40 -07:00
create/delete file commands
This commit is contained in:
parent
9625369fe0
commit
d1a4c89e07
3 changed files with 60 additions and 18 deletions
|
@ -1049,14 +1049,32 @@ int DesfireGetFileISOIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen
|
|||
int DesfireGetFileSettings(DesfireContext *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen) {
|
||||
return DesfireCommand(dctx, MFDES_GET_FILE_SETTINGS, &fileid, 1, resp, resplen, -1);
|
||||
}
|
||||
int DesfireCreateFile(DesfireContext *dctx, uint8_t *fdata, size_t fdatalen) {
|
||||
return DesfireCommandTxData(dctx, MFDES_CREATE_STD_DATA_FILE, fdata, fdatalen);
|
||||
|
||||
int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen) {
|
||||
const DesfireCreateFileCommandsS *rcmd = GetDesfireFileCmdRec(ftype);
|
||||
if (rcmd == NULL)
|
||||
return -10;
|
||||
if (fdatalen != rcmd->len || fdatalen != (rcmd->len + (rcmd->mayHaveISOfid) ? 2 : 0))
|
||||
return -20;
|
||||
|
||||
return DesfireCommandTxData(dctx, rcmd->cmd, fdata, fdatalen);
|
||||
}
|
||||
|
||||
int DesfireDeleteFile(DesfireContext *dctx, uint8_t fid) {
|
||||
return DesfireCommandTxData(dctx, MFDES_DELETE_FILE, &fid, 1);
|
||||
}
|
||||
|
||||
int DesfireCommitTrqansaction(DesfireContext *dctx, bool enable_options, uint8_t options) {
|
||||
if (enable_options)
|
||||
return DesfireCommandTxData(dctx, MFDES_COMMIT_TRANSACTION, &options, 1);
|
||||
else
|
||||
return DesfireCommandNoData(dctx, MFDES_COMMIT_TRANSACTION);
|
||||
}
|
||||
|
||||
int DesfireAbortTrqansaction(DesfireContext *dctx) {
|
||||
return DesfireCommandNoData(dctx, MFDES_ABORT_TRANSACTION);
|
||||
}
|
||||
|
||||
uint8_t DesfireKeyAlgoToType(DesfireCryptoAlgorythm keyType) {
|
||||
switch (keyType) {
|
||||
case T_DES:
|
||||
|
@ -1148,18 +1166,27 @@ void PrintKeySettings(uint8_t keysettings, uint8_t numkeys, bool applevel, bool
|
|||
static const char *DesfireUnknownStr = "unknown";
|
||||
static const char *DesfireDisabledStr = "disabled";
|
||||
static const char *DesfireFreeStr = "free";
|
||||
static const char *DesfireFileTypes[] = {
|
||||
"Standard data",
|
||||
"Backup data",
|
||||
"Value",
|
||||
"Linear Record",
|
||||
"Cyclic Record",
|
||||
"Transaction MAC",
|
||||
static const DesfireCreateFileCommandsS DesfireFileCommands[] = {
|
||||
{0x00, "Standard data", MFDES_CREATE_STD_DATA_FILE, 6, true},
|
||||
{0x01, "Backup data", MFDES_CREATE_BACKUP_DATA_FILE, 6, true},
|
||||
{0x02, "Value", MFDES_CREATE_VALUE_FILE, 16, false},
|
||||
{0x03, "Linear Record", MFDES_CREATE_LINEAR_RECORD_FILE, 9, true},
|
||||
{0x04, "Cyclic Record", MFDES_CREATE_CYCLIC_RECORD_FILE, 9, true},
|
||||
{0x05, "Transaction MAC", MFDES_CREATE_TRANS_MAC_FILE, 22, false},
|
||||
};
|
||||
|
||||
const DesfireCreateFileCommandsS *GetDesfireFileCmdRec(uint8_t type) {
|
||||
for (int i = 0; i < ARRAYLEN(DesfireFileCommands); i++)
|
||||
if (DesfireFileCommands[i].id == type)
|
||||
return &DesfireFileCommands[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *GetDesfireFileType(uint8_t type) {
|
||||
if (type < ARRAYLEN(DesfireFileTypes))
|
||||
return DesfireFileTypes[type];
|
||||
const DesfireCreateFileCommandsS *res = GetDesfireFileCmdRec(type);
|
||||
if (res != NULL)
|
||||
return res->text;
|
||||
else
|
||||
return DesfireUnknownStr;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,14 @@
|
|||
#include "mifare/desfire_crypto.h"
|
||||
#include "mifare/mifare4.h"
|
||||
|
||||
typedef struct {
|
||||
const uint8_t id;
|
||||
const char *text;
|
||||
const uint8_t cmd;
|
||||
const uint8_t len;
|
||||
const bool mayHaveISOfid;
|
||||
} DesfireCreateFileCommandsS;
|
||||
|
||||
extern const CLIParserOption DesfireAlgoOpts[];
|
||||
extern const CLIParserOption DesfireKDFAlgoOpts[];
|
||||
extern const CLIParserOption DesfireCommunicationModeOpts[];
|
||||
|
@ -64,13 +72,19 @@ int DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *para
|
|||
|
||||
int DesfireGetFileIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetFileISOIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
|
||||
int DesfireGetFileSettings(DesfireContext *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen);
|
||||
int DesfireChangeFileSettings(DesfireContext *dctx, uint8_t *data, size_t datalen);
|
||||
|
||||
const DesfireCreateFileCommandsS *GetDesfireFileCmdRec(uint8_t type);
|
||||
const char *GetDesfireAccessRightStr(uint8_t right);
|
||||
void DesfirePrintAccessRight(uint8_t *data);
|
||||
void DesfirePrintFileSettings(uint8_t *data, size_t len);
|
||||
void DesfirePrintSetFileSettings(uint8_t *data, size_t len);
|
||||
int DesfireCreateFile(DesfireContext *dctx, uint8_t *fdata, size_t fdatalen);
|
||||
|
||||
int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen);
|
||||
int DesfireDeleteFile(DesfireContext *dctx, uint8_t fid);
|
||||
int DesfireCommitTrqansaction(DesfireContext *dctx, bool enable_options, uint8_t options);
|
||||
int DesfireAbortTrqansaction(DesfireContext *dctx);
|
||||
|
||||
#endif // __DESFIRECORE_H
|
||||
|
|
|
@ -82,12 +82,13 @@ AllowedChannelModesS AllowedChannelModes[] = {
|
|||
|
||||
#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},
|
||||
{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},
|
||||
{MFDES_CREATE_TRANS_MAC_FILE, 17},
|
||||
};
|
||||
|
||||
static uint8_t DesfireGetCmdHeaderLen(uint8_t cmd) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue