1 //-----------------------------------------------------------------------------
2 // Copyright (C) Gerhard de Koning Gans - May 2008
3 // Contribution made during a security research at Radboud University Nijmegen
4 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // See LICENSE.txt for the text of the license.
17 //-----------------------------------------------------------------------------
22 #include "iclass_cmd.h"
24 // iCLASS has a slightly different timing compared to ISO15693. According to the picopass data sheet the tag response is expected 330us after
25 // the reader command. This is measured from end of reader EOF to first modulation of the tag's SOF which starts with a 56,64us unmodulated period.
26 // 330us = 140 ssp_clk cycles @ 423,75kHz when simulating.
27 // 56,64us = 24 ssp_clk_cycles
28 #define DELAY_ICLASS_VCD_TO_VICC_SIM (140 - 26) // (140 - 24)
30 // times in ssp_clk_cycles @ 3,3625MHz when acting as reader
31 #define DELAY_ICLASS_VICC_TO_VCD_READER DELAY_ISO15693_VICC_TO_VCD_READER
34 // times in samples @ 212kHz when acting as reader
35 #define ICLASS_READER_TIMEOUT_ACTALL 330 // 1558us, nominal 330us + 7slots*160us = 1450us
36 #define ICLASS_READER_TIMEOUT_UPDATE 3390 // 16000us, nominal 4-15ms
37 #define ICLASS_READER_TIMEOUT_OTHERS 80 // 380us, nominal 330us
39 // The length of a received command will in most cases be no more than 18 bytes.
40 // we expect max 34 (32+2) bytes as tag answer (response to READ4)
41 #ifndef ICLASS_BUFFER_SIZE
42 #define ICLASS_BUFFER_SIZE 34 + 2
46 #define AddCrc(data, len) compute_crc(CRC_ICLASS, (data), (len), (data)+(len), (data)+(len)+1)
48 void SniffIClass(uint8_t jam_search_len
, uint8_t *jam_search_string
);
49 void ReaderIClass(uint8_t flags
);
51 void iClass_WriteBlock(uint8_t *msg
);
52 void iclass_credit_epurse(iclass_credit_epurse_t
*payload
);
53 void iClass_Dump(uint8_t *msg
);
55 void iClass_Restore(iclass_restore_req_t
*msg
);
57 int do_iclass_simulation_nonsec(void);
58 int do_iclass_simulation(int simulationMode
, uint8_t *reader_mac_buf
);
59 void SimulateIClass(uint32_t arg0
, uint32_t arg1
, uint32_t arg2
, uint8_t *datain
);
60 void iclass_simulate(uint8_t sim_type
, uint8_t num_csns
, bool send_reply
, uint8_t *datain
, uint8_t *dataout
, uint16_t *dataoutlen
);
62 void iClass_Authentication_fast(iclass_chk_t
*p
);
63 bool iclass_auth(iclass_auth_req_t
*payload
, uint8_t *out
);
65 void iClass_ReadBlock(uint8_t *msg
);
66 bool iclass_read_block(uint16_t blockno
, uint8_t *data
, uint32_t *start_time
, uint32_t *eof_time
, bool shallow_mod
);
68 bool select_iclass_tag(picopass_hdr_t
*hdr
, bool use_credit_key
, uint32_t *eof_time
, bool shallow_mod
);
69 bool authenticate_iclass_tag(iclass_auth_req_t
*payload
, picopass_hdr_t
*hdr
, uint32_t *start_time
, uint32_t *eof_time
, uint8_t *mac_out
);
71 uint8_t get_pagemap(const picopass_hdr_t
*hdr
);
72 void iclass_send_as_reader(uint8_t *frame
, int len
, uint32_t *start_time
, uint32_t *end_time
, bool shallow_mod
);
74 void iClass_Recover(iclass_recover_req_t
*msg
);