2019-03-13 19:18:37 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-07 08:58:03 +08:00
|
|
|
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// See LICENSE.txt for the text of the license.
|
2019-03-13 19:18:37 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Hitag2, HitagS
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef HITAG_H__
|
|
|
|
#define HITAG_H__
|
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#include "common.h"
|
2019-03-13 19:18:37 +08:00
|
|
|
|
|
|
|
typedef enum {
|
2019-03-14 19:30:32 +08:00
|
|
|
RHTSF_CHALLENGE = 01,
|
|
|
|
RHTSF_KEY = 02,
|
|
|
|
WHTSF_CHALLENGE = 03,
|
|
|
|
WHTSF_KEY = 04,
|
2020-05-14 07:01:48 +08:00
|
|
|
HTS_LAST_CMD = WHTSF_KEY,
|
2020-01-16 02:26:12 +08:00
|
|
|
RHT1F_PLAIN = 11,
|
|
|
|
RHT1F_AUTHENTICATE = 12,
|
2020-05-14 07:01:48 +08:00
|
|
|
HT1_LAST_CMD = RHT1F_AUTHENTICATE,
|
2019-03-14 19:30:32 +08:00
|
|
|
RHT2F_PASSWORD = 21,
|
|
|
|
RHT2F_AUTHENTICATE = 22,
|
|
|
|
RHT2F_CRYPTO = 23,
|
|
|
|
WHT2F_CRYPTO = 24,
|
|
|
|
RHT2F_TEST_AUTH_ATTEMPTS = 25,
|
|
|
|
RHT2F_UID_ONLY = 26,
|
2019-07-10 06:00:57 +08:00
|
|
|
WHT2F_PASSWORD = 27,
|
2020-05-14 07:01:48 +08:00
|
|
|
HT2_LAST_CMD = WHT2F_PASSWORD,
|
2019-03-13 19:18:37 +08:00
|
|
|
} hitag_function;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-03-14 19:30:32 +08:00
|
|
|
uint8_t password[4];
|
2019-03-13 19:18:37 +08:00
|
|
|
} PACKED rht2d_password;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-03-14 19:30:32 +08:00
|
|
|
uint8_t NrAr[8];
|
|
|
|
uint8_t data[4];
|
2019-03-13 19:18:37 +08:00
|
|
|
} PACKED rht2d_authenticate;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-03-14 19:30:32 +08:00
|
|
|
uint8_t key[6];
|
|
|
|
uint8_t data[4];
|
2019-03-13 19:18:37 +08:00
|
|
|
} PACKED rht2d_crypto;
|
|
|
|
|
2020-01-15 05:08:43 +08:00
|
|
|
typedef struct {
|
2021-03-05 17:22:12 +08:00
|
|
|
uint8_t key_no;
|
2020-01-16 02:26:12 +08:00
|
|
|
uint8_t logdata_0[4];
|
|
|
|
uint8_t logdata_1[4];
|
|
|
|
uint8_t nonce[4];
|
|
|
|
uint8_t key[4];
|
2020-01-15 05:08:43 +08:00
|
|
|
} PACKED rht1d_authenticate;
|
|
|
|
|
2019-03-13 19:18:37 +08:00
|
|
|
typedef union {
|
2019-03-14 19:30:32 +08:00
|
|
|
rht2d_password pwd;
|
2020-01-16 02:26:12 +08:00
|
|
|
rht1d_authenticate ht1auth;
|
2019-03-14 19:30:32 +08:00
|
|
|
rht2d_authenticate auth;
|
|
|
|
rht2d_crypto crypto;
|
2019-03-13 19:18:37 +08:00
|
|
|
} hitag_data;
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// Hitag S
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// protocol-state
|
|
|
|
typedef enum PROTO_STATE {
|
|
|
|
HT_READY = 0,
|
|
|
|
HT_INIT,
|
|
|
|
HT_AUTHENTICATE,
|
|
|
|
HT_SELECTED,
|
|
|
|
HT_QUIET,
|
|
|
|
HT_TTF,
|
|
|
|
HT_FAIL
|
|
|
|
} PSTATE;
|
|
|
|
|
|
|
|
typedef enum TAG_STATE {
|
|
|
|
HT_NO_OP = 0,
|
|
|
|
HT_READING_PAGE,
|
|
|
|
HT_WRITING_PAGE_ACK,
|
|
|
|
HT_WRITING_PAGE_DATA,
|
|
|
|
HT_WRITING_BLOCK_DATA
|
|
|
|
} TSATE;
|
|
|
|
|
|
|
|
//number of start-of-frame bits
|
|
|
|
typedef enum SOF_TYPE {
|
|
|
|
HT_STANDARD = 0,
|
|
|
|
HT_ADVANCED,
|
|
|
|
HT_FAST_ADVANCED,
|
|
|
|
HT_ONE,
|
|
|
|
HT_NO_BITS
|
2019-03-14 19:30:32 +08:00
|
|
|
} stype;
|
2019-03-13 19:18:37 +08:00
|
|
|
|
|
|
|
struct hitagS_tag {
|
2022-01-04 05:15:01 +08:00
|
|
|
PSTATE pstate; // protocol-state
|
|
|
|
TSATE tstate; // tag-state
|
2019-03-14 19:30:32 +08:00
|
|
|
uint32_t uid;
|
|
|
|
uint8_t pages[64][4];
|
|
|
|
uint64_t key;
|
|
|
|
uint8_t pwdl0, pwdl1, pwdh0;
|
2022-01-04 05:15:01 +08:00
|
|
|
// con0
|
2019-03-14 19:30:32 +08:00
|
|
|
int max_page;
|
|
|
|
stype mode;
|
2022-01-04 05:15:01 +08:00
|
|
|
// con1
|
|
|
|
bool auth; // 0 = Plain 1 = Auth
|
|
|
|
bool TTFC; // Transponder Talks first coding. 0 = Manchester 1 = Biphase
|
|
|
|
int TTFDR; // data rate in TTF Mode
|
|
|
|
int TTFM; // the number of pages that are sent to the RWD
|
|
|
|
bool LCON; // 0 = con1/2 read write 1 =con1 read only and con2 OTP
|
|
|
|
bool LKP; // 0 = page2/3 read write 1 =page2/3 read only in Plain mode and no access in authenticate mode
|
|
|
|
// con2
|
|
|
|
// 0 = read write 1 = read only
|
|
|
|
bool LCK7; // page4/5
|
|
|
|
bool LCK6; // page6/7
|
|
|
|
bool LCK5; // page8-11
|
|
|
|
bool LCK4; // page12-15
|
|
|
|
bool LCK3; // page16-23
|
|
|
|
bool LCK2; // page24-31
|
|
|
|
bool LCK1; // page32-47
|
|
|
|
bool LCK0; // page48-63
|
2019-03-13 19:18:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|