- PrintAndLog("Segment %02u: raw header=%02x %02x %02x %02x, flag=%01x (valid=%01u, last=%01u), len=%04u, WRP=%02u, WRC=%02u, RD=%01u, CRC=%02x",
- n,
+ 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,