textual
[RRG-proxmark3.git] / include / hitag.h
blob168d3f439bdd3b114b18040cd54ac9305a0f37b5
1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
4 // the license.
5 //-----------------------------------------------------------------------------
6 // Hitag2, HitagS
7 //
8 // (c) 2012 Roel Verdult
9 // (c) 2016 Oguzhan Cicek, Hendrik Schwartke, Ralf Spenneberg
10 // <info@os-s.de>
11 //-----------------------------------------------------------------------------
14 #ifndef HITAG_H__
15 #define HITAG_H__
17 #include "common.h"
19 typedef enum {
20 RHTSF_CHALLENGE = 01,
21 RHTSF_KEY = 02,
22 WHTSF_CHALLENGE = 03,
23 WHTSF_KEY = 04,
24 HTS_LAST_CMD = WHTSF_KEY,
25 RHT1F_PLAIN = 11,
26 RHT1F_AUTHENTICATE = 12,
27 HT1_LAST_CMD = RHT1F_AUTHENTICATE,
28 RHT2F_PASSWORD = 21,
29 RHT2F_AUTHENTICATE = 22,
30 RHT2F_CRYPTO = 23,
31 WHT2F_CRYPTO = 24,
32 RHT2F_TEST_AUTH_ATTEMPTS = 25,
33 RHT2F_UID_ONLY = 26,
34 WHT2F_PASSWORD = 27,
35 HT2_LAST_CMD = WHT2F_PASSWORD,
36 } hitag_function;
38 typedef struct {
39 uint8_t password[4];
40 } PACKED rht2d_password;
42 typedef struct {
43 uint8_t NrAr[8];
44 uint8_t data[4];
45 } PACKED rht2d_authenticate;
47 typedef struct {
48 uint8_t key[6];
49 uint8_t data[4];
50 } PACKED rht2d_crypto;
52 typedef struct {
53 uint8_t key_no;
54 uint8_t logdata_0[4];
55 uint8_t logdata_1[4];
56 uint8_t nonce[4];
57 uint8_t key[4];
58 } PACKED rht1d_authenticate;
60 typedef union {
61 rht2d_password pwd;
62 rht1d_authenticate ht1auth;
63 rht2d_authenticate auth;
64 rht2d_crypto crypto;
65 } hitag_data;
68 //---------------------------------------------------------
69 // Hitag S
70 //---------------------------------------------------------
71 // protocol-state
72 typedef enum PROTO_STATE {
73 HT_READY = 0,
74 HT_INIT,
75 HT_AUTHENTICATE,
76 HT_SELECTED,
77 HT_QUIET,
78 HT_TTF,
79 HT_FAIL
80 } PSTATE;
82 typedef enum TAG_STATE {
83 HT_NO_OP = 0,
84 HT_READING_PAGE,
85 HT_WRITING_PAGE_ACK,
86 HT_WRITING_PAGE_DATA,
87 HT_WRITING_BLOCK_DATA
88 } TSATE;
90 //number of start-of-frame bits
91 typedef enum SOF_TYPE {
92 HT_STANDARD = 0,
93 HT_ADVANCED,
94 HT_FAST_ADVANCED,
95 HT_ONE,
96 HT_NO_BITS
97 } stype;
99 struct hitagS_tag {
100 PSTATE pstate; //protocol-state
101 TSATE tstate; //tag-state
102 uint32_t uid;
103 uint8_t pages[64][4];
104 uint64_t key;
105 uint8_t pwdl0, pwdl1, pwdh0;
106 //con0
107 int max_page;
108 stype mode;
109 //con1
110 bool auth; //0=Plain 1=Auth
111 bool TTFC; //Transponder Talks first coding. 0=Manchester 1=Biphase
112 int TTFDR; //data rate in TTF Mode
113 int TTFM; //the number of pages that are sent to the RWD
114 bool LCON; //0=con1/2 read write 1=con1 read only and con2 OTP
115 bool LKP; //0=page2/3 read write 1=page2/3 read only in Plain mode and no access in authenticate mode
116 //con2
117 //0=read write 1=read only
118 bool LCK7; //page4/5
119 bool LCK6; //page6/7
120 bool LCK5; //page8-11
121 bool LCK4; //page12-15
122 bool LCK3; //page16-23
123 bool LCK2; //page24-31
124 bool LCK1; //page32-47
125 bool LCK0; //page48-63
128 #endif