Skip to content

Commit 839b717

Browse files
committed
Fix hf mf setuid on Gen3 7 Byte UID Tag.
1 parent 163bbc4 commit 839b717

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

script/pn532_cli_unit.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,8 @@ def args_parser(self) -> ArgumentParserNoExit:
13741374
examples:
13751375
hf mf setuid -u 11223344
13761376
hf mf setuid -u 11223344 -g 2
1377-
hf mf setuid --blk0 1122334444080400aabbccddeeff1122 -g 3
1377+
hf mf setuid -u 11223344556677 -g 3
1378+
hf mf setuid -u 11223344556677 --blk0 11223344556677084400120111003912 -g 3
13781379
hf mf setuid --blk0 1122334444080400aabbccddeeff1122 -g 4 --pwd 00000000
13791380
"""
13801381
return parser
@@ -1407,13 +1408,13 @@ def get_block0(self, uid, args):
14071408
print(f"{CR}Block0 needs to be 16 bytes{C0}")
14081409
return
14091410

1410-
uid = str_to_bytes(block0[0:8])
1411-
bcc = 0
1412-
bcc = uid[0] ^ uid[1] ^ uid[2] ^ uid[3]
1413-
# check if bcc is valid on the block0
1414-
if block0[8:10] != format(bcc, "02x"):
1415-
print(f"{CR}Invalid BCC{C0}")
1416-
return
1411+
if not (block0[16:20].lower() == "4400" or block0[16:20].lower() == "4200"):
1412+
uid = str_to_bytes(block0[0:8])
1413+
bcc = uid[0] ^ uid[1] ^ uid[2] ^ uid[3]
1414+
# check if bcc is valid on the block0
1415+
if block0[8:10] != format(bcc, "02x"):
1416+
print(f"{CR}Invalid BCC{C0}")
1417+
return
14171418
return str_to_bytes(block0)
14181419

14191420
def gen1a_set_block0(self, block0: bytes):
@@ -1480,6 +1481,7 @@ def gen3_set_block0(self, uid: bytes, block0: bytes, lock: bool = False):
14801481
if not isGen3:
14811482
print(f"{CR}Tag is not Gen3{C0}")
14821483
return
1484+
print("Found Gen3 Tag")
14831485
resp1 = self.cmd.setGen3Uid(uid)
14841486
print(
14851487
f"Set UID to {uid.hex().upper()}: {CG}Success{C0}"

script/pn532_cmd.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ def isGen3(self):
342342
return False
343343

344344
def setGen3Uid(self, uid: bytes):
345+
selected_tag = self.selectTag()
346+
if selected_tag is None:
347+
print(f"{CR}Select tag failed{C0}")
348+
return
345349
options = {
346350
"activate_rf_field": 0,
347351
"wait_response": 1,
@@ -352,7 +356,7 @@ def setGen3Uid(self, uid: bytes):
352356
}
353357
command = "90FBCCCC07" + uid.hex()
354358
resp = self.hf14a_raw(
355-
options=options, resp_timeout_ms=1000, data=bytes.fromhex(command)
359+
options=options, resp_timeout_ms=2000, data=bytes.fromhex(command)
356360
)
357361
if resp[0] == 0x00:
358362
return True

0 commit comments

Comments
 (0)