proxmark3/include/mifare.h

273 lines
7.1 KiB
C
Raw Normal View History

2012-12-05 07:43:19 +08:00
//-----------------------------------------------------------------------------
// (c) 2012 Roel Verdult
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// MIFARE type prototyping
//-----------------------------------------------------------------------------
#ifndef _MIFARE_H_
#define _MIFARE_H_
#include "common.h"
2012-12-05 07:43:19 +08:00
2019-03-10 01:41:30 +08:00
#define MF_KEY_A 0
#define MF_KEY_B 1
2019-02-22 01:15:46 +08:00
2019-03-10 01:41:30 +08:00
#define MF_MAD1_SECTOR 0x00
#define MF_MAD2_SECTOR 0x10
2019-02-22 01:15:46 +08:00
//-----------------------------------------------------------------------------
// Common types, used by client and ARM
//-----------------------------------------------------------------------------
// New Ultralight/NTAG dump file format
// Length must be aligned to 4 bytes (UL/NTAG page)
#define MFU_DUMP_PREFIX_LENGTH 56
typedef struct {
uint8_t version[8];
uint8_t tbo[2];
uint8_t tbo1[1];
uint8_t pages; // max page number in dump
uint8_t signature[32];
uint8_t counter_tearing[3][4]; // 3 bytes counter, 1 byte tearing flag
uint8_t data[1024];
2019-10-18 04:32:09 +08:00
} PACKED mfu_dump_t;
2012-12-05 07:43:19 +08:00
//-----------------------------------------------------------------------------
// ISO 14443A
//-----------------------------------------------------------------------------
typedef struct {
2019-03-21 22:19:18 +08:00
uint8_t uid[10];
uint8_t uidlen;
uint8_t atqa[2];
uint8_t sak;
uint8_t ats_len;
uint8_t ats[256];
} PACKED iso14a_card_select_t;
2012-12-05 07:43:19 +08:00
typedef enum ISO14A_COMMAND {
2019-03-10 07:00:59 +08:00
ISO14A_CONNECT = (1 << 0),
ISO14A_NO_DISCONNECT = (1 << 1),
ISO14A_APDU = (1 << 2),
ISO14A_RAW = (1 << 3),
2019-03-10 01:41:30 +08:00
ISO14A_REQUEST_TRIGGER = (1 << 4),
2019-03-10 07:00:59 +08:00
ISO14A_APPEND_CRC = (1 << 5),
ISO14A_SET_TIMEOUT = (1 << 6),
ISO14A_NO_SELECT = (1 << 7),
ISO14A_TOPAZMODE = (1 << 8),
ISO14A_NO_RATS = (1 << 9),
ISO14A_SEND_CHAINING = (1 << 10)
2012-12-05 07:43:19 +08:00
} iso14a_command_t;
typedef struct {
2019-03-10 07:00:59 +08:00
uint8_t *response;
uint8_t *modulation;
2019-03-16 04:04:25 +08:00
uint16_t response_n;
uint16_t modulation_n;
2019-03-10 01:41:30 +08:00
uint32_t ProxToAirDuration;
2019-03-16 04:04:25 +08:00
uint8_t par; // enough for precalculated parity of 8 Byte responses
2019-10-18 04:32:09 +08:00
} PACKED tag_response_info_t;
2020-03-17 18:37:38 +08:00
// DESFIRE_RAW flag enums
typedef enum DESFIRE_COMMAND {
NONE = 0x00,
INIT = 0x01,
DISCONNECT = 0x02,
CLEARTRACE = 0x04,
BAR = 0x10,
} desfire_command_t;
2020-04-11 17:32:31 +08:00
typedef enum {
MFDES_AUTH_DES = 1,
MFDES_AUTH_ISO = 2,
MFDES_AUTH_AES = 3,
MFDES_AUTH_PICC = 4
} mifare_des_authmode_t;
typedef enum {
MFDES_ALGO_DES = 1,
MFDES_ALGO_3DES = 2,
2020-04-12 23:10:27 +08:00
MFDES_ALGO_3K3DES = 3,
MFDES_ALGO_AES = 4
2020-04-11 17:32:31 +08:00
} mifare_des_authalgo_t;
//-----------------------------------------------------------------------------
// ISO 14443B
//-----------------------------------------------------------------------------
typedef struct {
2019-03-21 22:19:18 +08:00
uint8_t uid[10];
uint8_t uidlen;
uint8_t atqb[7];
uint8_t chipid;
uint8_t cid;
2019-10-18 04:32:09 +08:00
} PACKED iso14b_card_select_t;
typedef enum ISO14B_COMMAND {
2019-03-10 07:00:59 +08:00
ISO14B_CONNECT = (1 << 0),
ISO14B_DISCONNECT = (1 << 1),
ISO14B_APDU = (1 << 2),
ISO14B_RAW = (1 << 3),
2019-03-10 01:41:30 +08:00
ISO14B_REQUEST_TRIGGER = (1 << 4),
2019-03-10 07:00:59 +08:00
ISO14B_APPEND_CRC = (1 << 5),
ISO14B_SELECT_STD = (1 << 6),
ISO14B_SELECT_SR = (1 << 7),
ISO14B_SET_TIMEOUT = (1 << 8),
} iso14b_command_t;
typedef enum ISO15_COMMAND {
2019-03-10 07:00:59 +08:00
ISO15_CONNECT = (1 << 0),
ISO15_NO_DISCONNECT = (1 << 1),
ISO15_RAW = (1 << 2),
ISO15_APPEND_CRC = (1 << 3),
ISO15_HIGH_SPEED = (1 << 4),
ISO15_READ_RESPONSE = (1 << 5)
} iso15_command_t;
//-----------------------------------------------------------------------------
// "hf 14a sim x", "hf mf sim x" attacks
//-----------------------------------------------------------------------------
typedef struct {
2019-03-10 01:41:30 +08:00
uint32_t cuid;
uint32_t nonce;
uint32_t ar;
uint32_t nr;
uint32_t at;
uint32_t nonce2;
uint32_t ar2;
uint32_t nr2;
uint8_t sector;
uint8_t keytype;
enum {
EMPTY,
FIRST,
SECOND,
} state;
2019-10-18 04:32:09 +08:00
} PACKED nonces_t;
2018-07-05 22:32:10 +08:00
//-----------------------------------------------------------------------------
// ISO 7618 Smart Card
2018-07-05 22:32:10 +08:00
//-----------------------------------------------------------------------------
typedef struct {
2019-03-10 01:41:30 +08:00
uint8_t atr_len;
uint8_t atr[30];
} PACKED smart_card_atr_t;
2018-07-05 22:32:10 +08:00
typedef enum SMARTCARD_COMMAND {
2019-03-10 07:00:59 +08:00
SC_CONNECT = (1 << 0),
SC_NO_DISCONNECT = (1 << 1),
SC_RAW = (1 << 2),
SC_SELECT = (1 << 3),
SC_RAW_T0 = (1 << 4),
SC_CLEARLOG = (1 << 5),
SC_LOG = (1 << 6),
} smartcard_command_t;
2018-01-29 20:48:18 +08:00
//-----------------------------------------------------------------------------
// FeliCa
//-----------------------------------------------------------------------------
// IDm = ID manufacturer
// mc = manufactureCode
// mc1 mc2 u1 u2 u3 u4 u5 u6
// PMm = Product manufacturer
// icCode =
2019-03-10 01:41:30 +08:00
// ic1 = ROM
// ic2 = IC
// maximum response time =
2019-03-10 01:41:30 +08:00
// B3(request service)
// B4(request response)
// B5(authenticate)
// B6(read)
// B7(write)
// B8()
// ServiceCode 2bytes (access-rights)
// FileSystem = 1 Block = 16 bytes
2018-01-29 20:48:18 +08:00
typedef struct {
2019-03-10 01:41:30 +08:00
uint8_t IDm[8];
uint8_t code[2];
uint8_t uid[6];
uint8_t PMm[8];
uint8_t iccode[2];
uint8_t mrt[6];
uint8_t servicecode[2];
} PACKED felica_card_select_t;
2018-01-29 20:48:18 +08:00
typedef struct {
uint8_t sync[2];
uint8_t length[1];
uint8_t cmd_code[1];
uint8_t IDm[8];
2019-10-29 17:22:47 +08:00
} PACKED felica_frame_response_t;
typedef struct {
uint8_t status_flag1[1];
uint8_t status_flag2[1];
2019-10-29 18:14:38 +08:00
} PACKED felica_status_flags_t;
2019-10-29 17:22:47 +08:00
typedef struct {
felica_frame_response_t frame_response;
uint8_t node_number[1];
uint8_t node_key_versions[2];
} PACKED felica_request_service_response_t;
typedef struct {
2019-10-29 17:22:47 +08:00
felica_frame_response_t frame_response;
uint8_t mode[1];
} PACKED felica_request_request_response_t;
2019-10-24 14:44:20 +08:00
typedef struct {
2019-10-29 17:22:47 +08:00
felica_frame_response_t frame_response;
2019-10-29 18:14:38 +08:00
felica_status_flags_t status_flags;
2019-10-24 14:44:20 +08:00
uint8_t number_of_block[1];
uint8_t block_data[16];
2019-10-24 22:08:44 +08:00
uint8_t block_element_number[1];
2019-10-24 14:44:20 +08:00
} PACKED felica_read_without_encryption_response_t;
2019-10-29 18:14:38 +08:00
typedef struct {
felica_frame_response_t frame_response;
felica_status_flags_t status_flags;
} PACKED felica_status_response_t;
typedef struct {
felica_frame_response_t frame_response;
uint8_t number_of_systems[1];
uint8_t system_code_list[32];
} PACKED felica_syscode_response_t;
typedef struct {
felica_frame_response_t frame_response;
felica_status_flags_t status_flags;
uint8_t format_version[1];
uint8_t basic_version[2];
uint8_t number_of_option[1];
uint8_t option_version_list[4];
} PACKED felica_request_spec_response_t;
2019-12-17 15:19:42 +08:00
typedef struct {
felica_frame_response_t frame_response;
uint8_t m2c[8];
uint8_t m3c[8];
} PACKED felica_auth1_response_t;
typedef struct {
uint8_t code[1];
uint8_t IDtc[8];
uint8_t IDi[8];
uint8_t PMi[8];
} PACKED felica_auth2_response_t;
2018-01-29 20:48:18 +08:00
typedef enum FELICA_COMMAND {
2019-03-10 07:00:59 +08:00
FELICA_CONNECT = (1 << 0),
FELICA_NO_DISCONNECT = (1 << 1),
FELICA_RAW = (1 << 3),
FELICA_APPEND_CRC = (1 << 5),
FELICA_NO_SELECT = (1 << 6),
2018-01-29 20:48:18 +08:00
} felica_command_t;
2012-12-05 07:43:19 +08:00
#endif // _MIFARE_H_