Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions script/pn532_cli_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,8 @@ def args_parser(self) -> ArgumentParserNoExit:
examples:
hf mf setuid -u 11223344
hf mf setuid -u 11223344 -g 2
hf mf setuid --blk0 1122334444080400aabbccddeeff1122 -g 3
hf mf setuid -u 11223344556677 -g 3
hf mf setuid -u 11223344556677 --blk0 11223344556677084400120111003912 -g 3
hf mf setuid --blk0 1122334444080400aabbccddeeff1122 -g 4 --pwd 00000000
"""
return parser
Expand Down Expand Up @@ -1407,13 +1408,13 @@ def get_block0(self, uid, args):
print(f"{CR}Block0 needs to be 16 bytes{C0}")
return

uid = str_to_bytes(block0[0:8])
bcc = 0
bcc = uid[0] ^ uid[1] ^ uid[2] ^ uid[3]
# check if bcc is valid on the block0
if block0[8:10] != format(bcc, "02x"):
print(f"{CR}Invalid BCC{C0}")
return
if not (block0[16:20].lower() == "4400" or block0[16:20].lower() == "4200"):
uid = str_to_bytes(block0[0:8])
bcc = uid[0] ^ uid[1] ^ uid[2] ^ uid[3]
# check if bcc is valid on the block0
if block0[8:10] != format(bcc, "02x"):
print(f"{CR}Invalid BCC{C0}")
return
return str_to_bytes(block0)

def gen1a_set_block0(self, block0: bytes):
Expand Down Expand Up @@ -1476,10 +1477,11 @@ def gen2_set_block0(self, block0: bytes, key: bytes, use_key_b: bool = False):
print(f" - {CR}Write failed.{C0}")

def gen3_set_block0(self, uid: bytes, block0: bytes, lock: bool = False):
selectTag = self.cmd.selectTag()
if not selectTag:
print(f"{CR}Select tag failed{C0}")
isGen3 = self.cmd.isGen3()
if not isGen3:
print(f"{CR}Tag is not Gen3{C0}")
return
print("Found Gen3 Tag")
resp1 = self.cmd.setGen3Uid(uid)
print(
f"Set UID to {uid.hex().upper()}: {CG}Success{C0}"
Expand Down Expand Up @@ -1551,6 +1553,7 @@ def on_exec(self, args: argparse.Namespace):
block0 = self.get_block0(uid, args)
if block0 == None:
return
self.device_com.set_normal_mode()
gen = args.g
if gen == 1:
self.gen1a_set_block0(block0)
Expand Down
6 changes: 5 additions & 1 deletion script/pn532_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ def isGen3(self):
return False

def setGen3Uid(self, uid: bytes):
selected_tag = self.selectTag()
if selected_tag is None:
print(f"{CR}Select tag failed{C0}")
return
options = {
"activate_rf_field": 0,
"wait_response": 1,
Expand All @@ -352,7 +356,7 @@ def setGen3Uid(self, uid: bytes):
}
command = "90FBCCCC07" + uid.hex()
resp = self.hf14a_raw(
options=options, resp_timeout_ms=1000, data=bytes.fromhex(command)
options=options, resp_timeout_ms=2000, data=bytes.fromhex(command)
)
if resp[0] == 0x00:
return True
Expand Down
21 changes: 0 additions & 21 deletions script/pn532_tag_scanner.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
import struct
import re
import ctypes
from typing import Union
import threading

import pn532_com
from unit.calc import crc16A, crc16Ccitt
from pn532_com import Response, DEBUG
from pn532_utils import expect_response
from pn532_enum import Command, MifareCommand, ApduCommand, TagFile, NdefCommand, Status
from pn532_enum import Pn532KillerCommand
from pn532_cmd import Pn532CMD

from pn532_enum import ButtonPressFunction, ButtonType, MifareClassicDarksideStatus
from pn532_enum import MfcKeyType, MfcValueBlockOperator
from time import sleep
from pn532_utils import CC, CB, CG, C0, CY, CR
import os
import subprocess
import ndef
from multiprocessing import Pool, cpu_count
from typing import Union
from pathlib import Path
from platform import uname
import sys
import select
Expand All @@ -32,7 +13,6 @@
import tkinter as tk

def test_fn():
# connect to pn532
dev = pn532_com.Pn532Com()
platform_name = uname().release
if "Microsoft" in platform_name:
Expand Down Expand Up @@ -102,6 +82,5 @@ def update_uid():
print("Error:", e)
dev.close()


if __name__ == "__main__":
test_fn()