recover_pk Flake8 ignore E501
[RRG-proxmark3.git] / include / iclass_cmd.h
blobe4761584ff0ea2d6eb604b5aeb34411661089927
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 uint32_t index;
112 uint32_t loop;
113 uint8_t nfa[8];
114 bool debug;
115 bool test;
116 } PACKED iclass_recover_req_t;
118 typedef struct iclass_premac {
119 uint8_t mac[4];
120 } PACKED iclass_premac_t;
122 typedef struct {
123 bool use_credit_key;
124 bool shallow_mod;
125 uint8_t count;
126 iclass_premac_t items[];
127 } PACKED iclass_chk_t;
129 typedef struct iclass_block {
130 uint8_t d[8];
131 } iclass_block_t;
133 typedef struct iclass_prekey {
134 uint8_t mac[4];
135 uint8_t key[8];
136 } iclass_prekey_t;
138 typedef struct {
139 char desc[70];
140 uint8_t data[16];
141 } iclass_config_card_item_t;
144 // iclass / picopass chip config structures and shared routines
145 typedef struct {
146 uint8_t app_limit; //[8]
147 uint8_t otp[2]; //[9-10]
148 uint8_t block_writelock;//[11]
149 uint8_t chip_config; //[12]
150 uint8_t mem_config; //[13]
151 uint8_t eas; //[14]
152 uint8_t fuses; //[15]
153 } PACKED picopass_conf_block_t;
155 // iCLASS secure mode memory mapping
156 typedef struct {
157 uint8_t csn[PICOPASS_BLOCK_SIZE];
158 picopass_conf_block_t conf;
159 uint8_t epurse[PICOPASS_BLOCK_SIZE];
160 uint8_t key_d[PICOPASS_BLOCK_SIZE];
161 uint8_t key_c[PICOPASS_BLOCK_SIZE];
162 uint8_t app_issuer_area[PICOPASS_BLOCK_SIZE];
163 } PACKED picopass_hdr_t;
165 // iCLASS non-secure mode memory mapping
166 typedef struct {
167 uint8_t csn[8];
168 picopass_conf_block_t conf;
169 uint8_t app_issuer_area[8];
170 } PACKED picopass_ns_hdr_t;
172 // reader flags
173 typedef struct {
174 uint8_t flags;
175 } PACKED iclass_card_select_t;
177 // reader flags
178 typedef struct {
179 uint8_t status;
180 union {
181 picopass_hdr_t hdr;
182 picopass_ns_hdr_t ns_hdr;
183 } header;
184 } PACKED iclass_card_select_resp_t;
187 #endif // _ICLASS_H_