fix missing gitignore
[RRG-proxmark3.git] / include / iclass_cmd.h
blobbb7b6193a42bb492df2cfca0767a8b505725a42c
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 // iCLASS type prototyping
17 //-----------------------------------------------------------------------------
19 #ifndef _ICLASS_CMD_H_
20 #define _ICLASS_CMD_H_
22 #include "common.h"
24 //-----------------------------------------------------------------------------
25 // iCLASS / PICOPASS
26 //-----------------------------------------------------------------------------
27 #define PICOPASS_BLOCK_SIZE 8
29 // iCLASS reader flags
30 #define FLAG_ICLASS_READER_INIT 0x01
31 #define FLAG_ICLASS_READER_CLEARTRACE 0x02
32 //#define FLAG_ICLASS_READER_ONLY_ONCE 0x04
33 #define FLAG_ICLASS_READER_CREDITKEY 0x08
34 #define FLAG_ICLASS_READER_AIA 0x10
35 #define FLAG_ICLASS_READER_SHALLOW_MOD 0x20
37 // iCLASS reader status flags
38 #define FLAG_ICLASS_NULL 0x00
39 #define FLAG_ICLASS_CSN 0x01
40 #define FLAG_ICLASS_CC 0x02
41 #define FLAG_ICLASS_CONF 0x04
42 #define FLAG_ICLASS_AIA 0x08
44 // iCLASS simulation modes
45 #define ICLASS_SIM_MODE_CSN 0
46 #define ICLASS_SIM_MODE_CSN_DEFAULT 1
47 #define ICLASS_SIM_MODE_READER_ATTACK 2
48 #define ICLASS_SIM_MODE_FULL 3
49 #define ICLASS_SIM_MODE_READER_ATTACK_KEYROLL 4
50 #define ICLASS_SIM_MODE_EXIT_AFTER_MAC 5 // note: device internal only
51 #define ICLASS_SIM_MODE_CONFIG_CARD 6
54 // iCLASS auth request data structure
55 // used with read block, dump, write block
56 typedef struct {
57 uint8_t key[8];
58 bool use_raw;
59 bool use_elite;
60 bool use_credit_key;
61 bool use_replay;
62 bool send_reply;
63 bool do_auth;
64 bool shallow_mod;
65 uint8_t blockno;
66 } PACKED iclass_auth_req_t;
68 // iCLASS read block response data structure
69 typedef struct {
70 bool isOK;
71 uint8_t div_key[8];
72 uint8_t mac[4];
73 uint8_t data[8];
74 } PACKED iclass_readblock_resp_t;
76 // iCLASS dump data structure
77 typedef struct {
78 iclass_auth_req_t req;
79 uint8_t start_block;
80 uint8_t end_block;
81 } PACKED iclass_dump_req_t;
83 // iCLASS write block request data structure
84 typedef struct {
85 iclass_auth_req_t req;
86 uint8_t data[8];
87 uint8_t mac[4];
88 } PACKED iclass_writeblock_req_t;
90 // iCLASS write block request data structure
91 typedef struct {
92 iclass_auth_req_t req;
93 uint8_t epurse[4];
94 } PACKED iclass_credit_epurse_t;
96 // iCLASS dump data structure
97 typedef struct {
98 uint8_t blockno;
99 uint8_t data[8];
100 } PACKED iclass_restore_item_t;
102 typedef struct {
103 iclass_auth_req_t req;
104 uint8_t item_cnt;
105 iclass_restore_item_t blocks[];
106 } PACKED iclass_restore_req_t;
108 typedef struct {
109 iclass_auth_req_t req;
110 iclass_auth_req_t req2;
111 } PACKED iclass_recover_req_t;
113 typedef struct iclass_premac {
114 uint8_t mac[4];
115 } PACKED iclass_premac_t;
117 typedef struct {
118 bool use_credit_key;
119 bool shallow_mod;
120 uint8_t count;
121 iclass_premac_t items[];
122 } PACKED iclass_chk_t;
124 typedef struct iclass_block {
125 uint8_t d[8];
126 } iclass_block_t;
128 typedef struct iclass_prekey {
129 uint8_t mac[4];
130 uint8_t key[8];
131 } iclass_prekey_t;
133 typedef struct {
134 char desc[70];
135 uint8_t data[16];
136 } iclass_config_card_item_t;
139 // iclass / picopass chip config structures and shared routines
140 typedef struct {
141 uint8_t app_limit; //[8]
142 uint8_t otp[2]; //[9-10]
143 uint8_t block_writelock;//[11]
144 uint8_t chip_config; //[12]
145 uint8_t mem_config; //[13]
146 uint8_t eas; //[14]
147 uint8_t fuses; //[15]
148 } PACKED picopass_conf_block_t;
150 // iCLASS secure mode memory mapping
151 typedef struct {
152 uint8_t csn[8];
153 picopass_conf_block_t conf;
154 uint8_t epurse[8];
155 uint8_t key_d[8];
156 uint8_t key_c[8];
157 uint8_t app_issuer_area[8];
158 } PACKED picopass_hdr_t;
160 // iCLASS non-secure mode memory mapping
161 typedef struct {
162 uint8_t csn[8];
163 picopass_conf_block_t conf;
164 uint8_t app_issuer_area[8];
165 } PACKED picopass_ns_hdr_t;
167 // reader flags
168 typedef struct {
169 uint8_t flags;
170 } PACKED iclass_card_select_t;
172 // reader flags
173 typedef struct {
174 uint8_t status;
175 union {
176 picopass_hdr_t hdr;
177 picopass_ns_hdr_t ns_hdr;
178 } header;
179 } PACKED iclass_card_select_resp_t;
182 #endif // _ICLASS_H_