155 lines
8.0 KiB
C++
155 lines
8.0 KiB
C++
#pragma once
|
|
|
|
#include "RC522Types.h"
|
|
#include "Desfire.h"
|
|
|
|
namespace RC522
|
|
{
|
|
class ISO
|
|
{
|
|
public:
|
|
enum class ISO_INSTRUCTION : uint8_t
|
|
{
|
|
ACTIVATE_FILE = 0x44,
|
|
APPEND_RECORD = 0xE2,
|
|
CHANGE_REFERENCE_DATA = 0x24,
|
|
CREATE_FILE = 0xE0,
|
|
DEACTIVATE_FILE = 0x04,
|
|
DELETE_FILE = 0xE4,
|
|
DISABLE_VERIFICATION_REQUIREMENT = 0x26,
|
|
ENABLE_VERIFICATION_REQUIREMENT = 0x28,
|
|
ENVELOPE = 0xC2, // 0xC3
|
|
ERASE_BINARY = 0x0E, // 0x0F
|
|
ERASE_RECORDS = 0x0C,
|
|
EXTERNAL_AUTHENTICATE = 0x82,
|
|
GENERAL_AUTHENTICATE = 0x86, // 0x87
|
|
GENERATE_ASYMMETRIC_KEY_PAIR = 0x46,
|
|
GET_CHALLENGE = 0x84,
|
|
GET_DATA = 0xCA, // 0xCB
|
|
GET_RESPONSE = 0xC0,
|
|
INTERNAL_AUTHENTICATE = 0x88,
|
|
MANAGE_CHANNEL = 0x70,
|
|
MANAGE_SECURITY_ENVIRONMENT = 0x22,
|
|
PERFORM_SCQL_OPERATION = 0x10,
|
|
PERFORM_SECURITY_OPERATION = 0x2A,
|
|
PERFORM_TRANSACTION_OPERATION = 0x12,
|
|
PERFORM_USER_OPERATION = 0x14,
|
|
PUT_DATA = 0xDA, // 0xDB
|
|
READ_BINARY = 0xB0, // 0xB1
|
|
READ_RECORDS = 0xB2, // 0xB3
|
|
RESET_RETRY_COUNTER = 0x2C,
|
|
SEARCH_BINARY = 0xA0, // 0xA1
|
|
SEARCH_RECORD = 0xA2,
|
|
SELECT = 0xA4,
|
|
TERMINATE_CARD_USAGE = 0xFE,
|
|
TERMINATE_DF = 0xE6,
|
|
TERMINATE_EF = 0xE8,
|
|
UPDATE_BINARY = 0xD6, // 0xD7
|
|
UPDATE_RECORD = 0xDC, // 0xDD
|
|
VERIFY = 0x20, // 0x21
|
|
WRITE_BINARY = 0xD0, // 0xD1
|
|
WRITE_RECORD = 0xD2,
|
|
};
|
|
|
|
// enum class ISO_STATUSCODE : uint16_t
|
|
// {
|
|
// ISO7816_OK = 0x9000,
|
|
// // 61 xx
|
|
// ISO7816_BYTES_REMAINING_00 = 0x6100, // Response bytes remaining
|
|
|
|
// // 62 xx
|
|
// ISO7816_WARNING_STATE_UNCHANGED = 0x6200, // Warning, card state unchanged
|
|
// ISO7816_DATA_CORRUPT = 0x6281, // Returned data may be corrupted
|
|
// ISO7816_FILE_EOF = 0x6282, // The end of the file has been reached before the end of reading
|
|
// ISO7816_INVALID_DF = 0x6283, // Invalid DF
|
|
// ISO7816_INVALID_FILE = 0x6284, // Selected file is not valid
|
|
// ISO7816_FILE_TERMINATED = 0x6285, // File is terminated
|
|
|
|
// // 63 xx
|
|
// ISO7816_AUTH_FAILED = 0x6300, // Authentification failed
|
|
// ISO7816_FILE_FILLED = 0x6381, // File filled up by the last write
|
|
|
|
// // 65 xx
|
|
// ISO7816_MEMORY_FULL = 0x6501, // Memory failure
|
|
// ISO7816_WRITE_MEMORY_ERR = 0x6581, // Write problem / Memory failure / Unknown mode
|
|
|
|
// // 67 xx
|
|
// ISO7816_WRONG_LENGTH = 0x6700, // Wrong length
|
|
|
|
// // 68 xx
|
|
// ISO7816_LOGICAL_CHANNEL_NOT_SUPPORTED = 0x6881, // Card does not support the operation on the specified logical channel
|
|
// ISO7816_SECURE_MESSAGING_NOT_SUPPORTED = 0x6882, // Card does not support secure messaging
|
|
// ISO7816_LAST_COMMAND_EXPECTED = 0x6883, // Last command in chain expected
|
|
// ISO7816_COMMAND_CHAINING_NOT_SUPPORTED = 0x6884, // Command chaining not supported
|
|
|
|
// // 69 xx
|
|
// ISO7816_TRANSACTION_FAIL = 0x6900, // No successful transaction executed during session
|
|
// ISO7816_SELECT_FILE_ERR = 0x6981, // Cannot select indicated file, command not compatible with file organization
|
|
// ISO7816_SECURITY_STATUS_NOT_SATISFIED = 0x6982, // Security condition not satisfied
|
|
// ISO7816_FILE_INVALID = 0x6983, // File invalid
|
|
// ISO7816_DATA_INVALID = 0x6984, // Data invalid
|
|
// ISO7816_CONDITIONS_NOT_SATISFIED = 0x6985, // Conditions of use not satisfied
|
|
// ISO7816_COMMAND_NOT_ALLOWED = 0x6986, // Command not allowed (no current EF)
|
|
// ISO7816_SM_DATA_MISSING = 0x6987, // Expected SM data objects missing
|
|
// ISO7816_SM_DATA_INCORRECT = 0x6988, // SM data objects incorrect
|
|
// ISO7816_APPLET_SELECT_FAILED = 0x6999, // Applet selection failed
|
|
|
|
// // 6A xx
|
|
// ISO7816_INVALID_P1P2 = 0x6A00, // Bytes P1 and/or P2 are invalid
|
|
// ISO7816_WRONG_DATA = 0x6A80, // Wrong data
|
|
// ISO7816_FUNC_NOT_SUPPORTED = 0x6A81, // Function not supported
|
|
// ISO7816_FILE_NOT_FOUND = 0x6A82, // File not found
|
|
// ISO7816_RECORD_NOT_FOUND = 0x6A83, // Record not found
|
|
// ISO7816_FILE_FULL = 0x6A84, // Not enough memory space in the file
|
|
// ISO7816_LC_TLV_CONFLICT = 0x6A85, // LC / TLV conlict
|
|
// ISO7816_INCORRECT_P1P2 = 0x6A86, // Incorrect parameters (P1,P2)
|
|
// ISO7816_FILE_EXISTS = 0x6A89, // File exists
|
|
// ISO7816_NOT_IMPLEMENTED = 0x6AFF, //
|
|
|
|
// // 6x 00
|
|
// ISO7816_WRONG_P1P2 = 0x6B00, // Incorrect parameters (P1,P2)
|
|
// ISO7816_CORRECT_LENGTH_00 = 0x6C00, // Correct Expected Length (Le)
|
|
// ISO7816_INS_NOT_SUPPORTED = 0x6D00, // INS value not supported
|
|
// ISO7816_CLA_NOT_SUPPORTED = 0x6E00, // CLA value not supported
|
|
// ISO7816_UNKNOWN = 0x6F00, // No precise diagnosis
|
|
// };
|
|
|
|
// static StatusCode ISO_Enable(TagInfo *tag);
|
|
// static StatusCode ISO_Select(TagInfo *tag);
|
|
|
|
static StatusCode ISO_SelectApplication(TagInfo *tag, uint8_t *aid, uint8_t *aidLen);
|
|
static StatusCode ISO_GetData(TagInfo *tag, uint8_t *backData, uint8_t *backLen);
|
|
static StatusCode ISO_PutData(TagInfo *tag, uint8_t *data, uint8_t *dataLen);
|
|
|
|
// static StatusCode MIFARE_Authenticate(PICC_Command command, uint8_t blockAddr, MIFARE_Key *key, Uid *uid);
|
|
// static void MIFARE_StopCrypto1();
|
|
// static StatusCode MIFARE_NTAG216_AUTH(uint8_t *passWord, uint8_t pACK[]);
|
|
|
|
// static StatusCode MIFARE_Read(uint8_t blockAddr, uint8_t *buffer, uint8_t *bufferSize);
|
|
// static StatusCode MIFARE_Write(uint8_t blockAddr, uint8_t *buffer, uint8_t bufferSize);
|
|
// static StatusCode MIFARE_Ultralight_Write(uint8_t page, uint8_t *buffer, uint8_t bufferSize);
|
|
// static StatusCode MIFARE_Decrement(uint8_t blockAddr, int32_t delta);
|
|
// static StatusCode MIFARE_Increment(uint8_t blockAddr, int32_t delta);
|
|
// static StatusCode MIFARE_Restore(uint8_t blockAddr);
|
|
// static StatusCode MIFARE_Transfer(uint8_t blockAddr);
|
|
// static StatusCode MIFARE_GetValue(uint8_t blockAddr, int32_t *value);
|
|
// static StatusCode MIFARE_SetValue(uint8_t blockAddr, int32_t value);
|
|
|
|
// static void MIFARE_SetAccessBits(uint8_t *accessBitBuffer, uint8_t g0, uint8_t g1, uint8_t g2, uint8_t g3);
|
|
// static bool MIFARE_OpenUidBackdoor(bool logErrors);
|
|
// static bool MIFARE_SetUid(Uid *oldUid, uint8_t *newUid, uint8_t uidSize, bool logErrors);
|
|
// static bool MIFARE_UnbrickUidSector(bool logErrors);
|
|
|
|
// static void MIFARE_DumpMifareClassicToSerial(TagInfo *tag, MIFARE_Key *key);
|
|
// static void MIFARE_DumpMifareClassicSectorToSerial(TagInfo *tag, MIFARE_Key *key, uint8_t sector);
|
|
// static void MIFARE_DumpMifareUltralightToSerial();
|
|
|
|
static const char *GetStatusCodesName(ISO7816StatusCode code);
|
|
|
|
private:
|
|
// static StatusCode MIFARE_TwoStepHelper(PICC_Command command, uint8_t blockAddr, int32_t data);
|
|
// static StatusCode MIFARE_Transceive(uint8_t *sendData, uint8_t sendLen, bool acceptTimeout = false);
|
|
static StatusCode ISO_Transceive(TagInfo *tag, ISO_INSTRUCTION ins, uint8_t *backData, uint8_t *backLen);
|
|
static StatusCode ISO_Transceive(TagInfo *tag, ISO_INSTRUCTION ins, uint8_t *sendData, uint8_t *sendLen, uint8_t *backData, uint8_t *backLen);
|
|
};
|
|
} |