+ // Makes no sence to show this on blank media...
+ if(dcf != 0xFFFF) {
+
+ if(bIsSegmented) {
+ PrintAndLog("WRP=%02u, WRC=%01u, RD=%01u, SSC=%02x",
+ data_buf[7] & 0x0f,
+ (data_buf[7] & 0x70) >> 4,
+ (data_buf[7] & 0x80) >> 7,
+ data_buf[8]
+ );
+ }
+
+ // Header area is only available on IM-S cards, on master tokens this data is the master token data itself
+ if(bIsSegmented || dcf > 60000) {
+ if(dcf > 60000) {
+ PrintAndLog("Master token data");
+ PrintAndLog("%s", sprint_hex(data_buf+8, 14));
+ } else {
+ PrintAndLog("Remaining Header Area");
+ PrintAndLog("%s", sprint_hex(data_buf+9, 13));
+ }
+ }
+ }
+
+ uint8_t segCrcBytes[8] = {0,0,0,0,0,0,0,0};
+ uint32_t segCalcCRC = 0;
+ uint32_t segCRC = 0;
+
+ // Data card?
+ if(dcf <= 60000) {
+
+ PrintAndLog("\nADF: User Area");
+ PrintAndLog("------------------------------------------------------");
+
+ if(bIsSegmented) {
+
+ // Data start point on segmented cards
+ i = 22;
+
+ // decode segments
+ for (segmentNum=1; segmentNum < 128; segmentNum++ )
+ {
+ segment_len = ((data_buf[i+1] ^ crc) & 0x0f) * 256 + (data_buf[i] ^ crc);
+ segment_flag = ((data_buf[i+1] ^ crc) & 0xf0) >> 4;
+ wrp = (data_buf[i+2] ^ crc);
+ wrc = ((data_buf[i+3] ^ crc) & 0x70) >> 4;
+
+ bool hasWRC = (wrc > 0);
+ bool hasWRP = (wrp > wrc);
+ int wrp_len = (wrp - wrc);
+ int remain_seg_payload_len = (segment_len - wrp - 5);
+
+ // validate segment-crc
+ segCrcBytes[0]=data_buf[0]; //uid0
+ segCrcBytes[1]=data_buf[1]; //uid1
+ segCrcBytes[2]=data_buf[2]; //uid2
+ segCrcBytes[3]=data_buf[3]; //uid3
+ segCrcBytes[4]=(data_buf[i] ^ crc); //hdr0
+ segCrcBytes[5]=(data_buf[i+1] ^ crc); //hdr1
+ segCrcBytes[6]=(data_buf[i+2] ^ crc); //hdr2
+ segCrcBytes[7]=(data_buf[i+3] ^ crc); //hdr3
+
+ segCalcCRC = CRC8Legic(segCrcBytes, 8);
+ segCRC = data_buf[i+4] ^ crc;
+
+ PrintAndLog("Segment %02u \nraw header | 0x%02X 0x%02X 0x%02X 0x%02X \nSegment len: %u, Flag: 0x%X (valid:%01u, last:%01u), WRP: %02u, WRC: %02u, RD: %01u, CRC: 0x%02X (%s)",
+ segmentNum,
+ data_buf[i] ^ crc,
+ data_buf[i+1] ^ crc,
+ data_buf[i+2] ^ crc,
+ data_buf[i+3] ^ crc,
+ segment_len,
+ segment_flag,
+ (segment_flag & 0x4) >> 2,
+ (segment_flag & 0x8) >> 3,
+ wrp,
+ wrc,
+ ((data_buf[i+3]^crc) & 0x80) >> 7,
+ segCRC,
+ ( segCRC == segCalcCRC ) ? "OK" : "fail"
+ );
+
+ i += 5;