style
[RRG-proxmark3.git] / client / src / mifare / mifare4.h
blobfedb482a4d7e7cd0737ff99ee196e4a40d0b34ca
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // iso14443-4 mifare commands
17 //-----------------------------------------------------------------------------
19 #ifndef MIFARE4_H
20 #define MIFARE4_H
22 #include "common.h"
23 #include <stdbool.h>
25 typedef struct {
26 bool Authenticated;
27 uint8_t Key[16];
28 uint16_t KeyNum;
29 uint8_t RndA[16];
30 uint8_t RndB[16];
31 uint8_t TI[4];
32 uint8_t PICCap2[6];
33 uint8_t PCDCap2[6];
34 uint8_t Kenc[16];
35 uint8_t Kmac[16];
36 uint16_t R_Ctr;
37 uint16_t W_Ctr;
38 } mf4Session_t;
40 typedef enum {
41 mtypReadCmd,
42 mtypReadResp,
43 mtypWriteCmd,
44 mtypWriteResp,
45 } MACType_t;
47 typedef struct {
48 uint8_t cond;
49 const char *description;
50 const char *application;
51 } AccessConditions_t;
54 typedef struct {
55 uint8_t Code;
56 const char *Description;
57 } PlusErrorsElm_t;
59 void mfpSetVerboseMode(bool verbose);
60 const char *mfpGetErrorDescription(uint8_t errorCode);
62 int CalculateMAC(mf4Session_t *mf4session, MACType_t mtype, uint8_t blockNum, uint8_t blockCount, uint8_t *data, int datalen, uint8_t *mac, bool verbose);
63 int MifareAuth4(mf4Session_t *mf4session, const uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSignalON, bool dropFieldIfError, bool verbose, bool silentMode);
65 int MFPWritePerso(const uint8_t *keyNum, const uint8_t *key, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
66 int MFPCommitPerso(bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
67 int MFPReadBlock(mf4Session_t *mf4session, bool plain, bool nomaccmd, bool nomacres, uint8_t blockNum, uint8_t blockCount, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac);
68 int MFPWriteBlock(mf4Session_t *mf4session, bool plain, bool nomacres, uint8_t blockNum, uint8_t blockHdr, const uint8_t *data, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac);
69 int mfpReadSector(uint8_t sectorNo, uint8_t keyType, uint8_t *key, uint8_t *dataout, bool verbose);
71 int MFPGetSignature(bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
72 int MFPGetVersion(bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
74 bool mfValidateAccessConditions(const uint8_t *data);
75 bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data);
76 const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data);
77 uint8_t mf_get_accesscondition(uint8_t blockn, const uint8_t *data);
79 uint8_t mfNumBlocksPerSector(uint8_t sectorNo);
80 uint8_t mfFirstBlockOfSector(uint8_t sectorNo);
81 uint8_t mfSectorTrailerOfSector(uint8_t sectorNo);
82 uint8_t mfSectorTrailer(uint16_t blockNo);
83 bool mfIsSectorTrailer(uint16_t blockNo);
84 bool mfIsSectorTrailerBasedOnBlocks(uint8_t sectorno, uint16_t blockno);
85 uint8_t mfSectorNum(uint16_t blockNo);
88 #endif // mifare4.h