- for(int i=0;i<1;i++) {
-
- if(traceLen > TRACE_SIZE) {
- DbpString("Trace full");
- break;
- }
-
- if (BUTTON_PRESS()) break;
-
- // Send act_all
- ReaderTransmitIClass(act_all, 1);
- // Card present?
- if(ReaderReceiveIClass(resp)) {
- ReaderTransmitIClass(identify, 1);
- if(ReaderReceiveIClass(resp) == 10) {
- // Select card
- memcpy(&select[1],resp,8);
- ReaderTransmitIClass(select, sizeof(select));
-
- if(ReaderReceiveIClass(resp) == 10) {
- Dbprintf(" Selected CSN: %02x %02x %02x %02x %02x %02x %02x %02x",
- resp[0], resp[1], resp[2],
- resp[3], resp[4], resp[5],
- resp[6], resp[7]);
- }
- // Card selected
- Dbprintf("Readcheck on Sector 2");
- ReaderTransmitIClass(readcheck_cc, sizeof(readcheck_cc));
- if(ReaderReceiveIClass(resp) == 8) {
- Dbprintf(" CC: %02x %02x %02x %02x %02x %02x %02x %02x",
- resp[0], resp[1], resp[2],
- resp[3], resp[4], resp[5],
- resp[6], resp[7]);
- }else return;
- Dbprintf("Authenticate");
- //for now replay captured auth (as cc not updated)
- memcpy(check+5,MAC,4);
- Dbprintf(" AA: %02x %02x %02x %02x",
- check[5], check[6], check[7],check[8]);
- ReaderTransmitIClass(check, sizeof(check));
- if(ReaderReceiveIClass(resp) == 4) {
- Dbprintf(" AR: %02x %02x %02x %02x",
- resp[0], resp[1], resp[2],resp[3]);
- }else {
- Dbprintf("Error: Authentication Fail!");
- return;
- }
- Dbprintf("Write Block");
-
- //read configuration for max block number
- read_success=false;
- read[1]=1;
- uint8_t *blockno=&read[1];
- crc = iclass_crc16((char *)blockno,1);
- read[2] = crc >> 8;
- read[3] = crc & 0xff;
- while(!read_success){
- ReaderTransmitIClass(read, sizeof(read));
- if(ReaderReceiveIClass(resp) == 10) {
- read_success=true;
- mem=resp[5];
- memory.k16= (mem & 0x80);
- memory.book= (mem & 0x20);
- memory.k2= (mem & 0x8);
- memory.lockauth= (mem & 0x2);
- memory.keyaccess= (mem & 0x1);
-
- }
- }
- if (memory.k16){
- cardsize=255;
- }else cardsize=32;
- //check card_size
-
- memcpy(write+1,blockNo,1);
- memcpy(write+2,data,8);
- memcpy(write+10,mac,4);
- while(!send_success){
- ReaderTransmitIClass(write, sizeof(write));
- if(ReaderReceiveIClass(resp) == 10) {
- write_success=true;
- }
- }//
+void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) {
+ int i;
+ int written = 0;
+ int total_block = (endblock - startblock) + 1;
+ for (i = 0; i < total_block;i++){
+ // block number
+ if (iClass_WriteBlock_ext(i+startblock, data+(i*12))){
+ Dbprintf("Write block [%02x] successful",i + startblock);
+ written++;
+ } else {
+ if (iClass_WriteBlock_ext(i+startblock, data+(i*12))){
+ Dbprintf("Write block [%02x] successful",i + startblock);
+ written++;
+ } else {
+ Dbprintf("Write block [%02x] failed",i + startblock);
+ }