@@ -1766,6 +1766,12 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u
17661766 emlSetMem_xt (receivedCmd , wrblock + MFU_DUMP_PREFIX_LENGTH / 4 , 1 , 4 );
17671767 // send ACK
17681768 EmSend4bit (CARD_ACK );
1769+ if (tagType == 13 && wrblock >= 0x2c && wrblock <= 0x2F ) {
1770+ ulc_reread_key = true;
1771+ }
1772+ if (tagType == 14 && wrblock >= 0x30 && wrblock <= 0x37 ) {
1773+ ulaes_reread_key = true;
1774+ }
17691775 } else {
17701776 // send NACK 0x1 == crc/parity error
17711777 EmSend4bit (CARD_NACK_PA );
@@ -1868,10 +1874,22 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u
18681874 // send NACK 0x0 == invalid argument
18691875 EmSend4bit (CARD_NACK_IV );
18701876 } else {
1877+ // TODO: check if block >= AUTH0 and AUTH1=0 and unauth on ULC/ULAES -> NACK
18711878 // first blocks of emu are header
18721879 uint16_t start = (block * 4 ) + MFU_DUMP_PREFIX_LENGTH ;
18731880 uint8_t emdata [MIFARE_BLOCK_SIZE + CRC16_SIZE ] = {0 };
18741881 emlGet (emdata , start , MIFARE_BLOCK_SIZE );
1882+ // mask key pages if needed
1883+ if ((tagType == 13 ) && (block >= 0x29 ) && (block <= 0x2F )) {
1884+ uint8_t offset = block >= 0x2C ? 0 : 0x2C - block ;
1885+ uint8_t length = block >= 0x2C ? 0x30 - block : block - 0x28 ;
1886+ memset (emdata + offset * 4 , 0x00 , length * 4 );
1887+ } else if ((tagType == 14 ) && (block >= 0x2D ) && (block <= 0x37 )) {
1888+ uint8_t offset = block >= 0x30 ? 0 : 0x30 - block ;
1889+ uint8_t length = block >= 0x30 ? (0x37 - block > 4 ? 4 : 0x37 - block ) : block - 0x2C ;
1890+ memset (emdata + offset * 4 , 0x00 , length * 4 );
1891+ }
1892+ // TODO: implement cyclic memory if we reach AUTH0 and AUTH1=0 and unauth on ULC/ULAES, or if we reach end of memory
18751893 AddCrc14A (emdata , MIFARE_BLOCK_SIZE );
18761894 EmSendCmd (emdata , sizeof (emdata ));
18771895 numReads ++ ; // Increment number of times reader requested a block
@@ -1927,6 +1945,7 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u
19271945 EmSend4bit (CARD_NACK_IV );
19281946 goto jump ;
19291947 }
1948+ // TODO: check if block >= AUTH0 and unauth on ULC/ULAES -> NACK
19301949
19311950 // OTP sanity check
19321951 if (block == 0x03 ) {
@@ -1968,6 +1987,7 @@ void SimulateIso14443aTagEx(uint8_t tagType, uint16_t flags, uint8_t *useruid, u
19681987 if (wrblock > pages ) {
19691988 // send NACK 0x0 == invalid argument
19701989 EmSend4bit (CARD_NACK_IV );
1990+ // TODO: check if wrblock >= AUTH0 and unauth on ULC/ULAES -> NACK
19711991 } else {
19721992 // send ACK
19731993 EmSend4bit (CARD_ACK );
0 commit comments