mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
hf14a_raw: use @expect_response and fix tests
This commit is contained in:
@@ -1638,15 +1638,12 @@ class HF14ARaw(ReaderRequiredUnit):
|
||||
|
||||
# Exec 14a raw cmd.
|
||||
resp = self.cmd.hf14a_raw(options, args.timeout, data_bytes, args.bits)
|
||||
if resp.status == chameleon_status.Device.HF_TAG_OK:
|
||||
if len(resp.data) > 0:
|
||||
print(
|
||||
# print head
|
||||
" - " +
|
||||
# print data
|
||||
' '.join([hex(byte).replace('0x', '').rjust(2, '0') for byte in resp.data])
|
||||
)
|
||||
else:
|
||||
print(F" [*] {CY}No response{C0}")
|
||||
if len(resp) > 0:
|
||||
print(
|
||||
# print head
|
||||
" - " +
|
||||
# print data
|
||||
' '.join([hex(byte).replace('0x', '').rjust(2, '0') for byte in resp])
|
||||
)
|
||||
else:
|
||||
print(f" [!] {CR}{chameleon_status.message[resp.status]}{C0} ")
|
||||
print(F" [*] {CY}No response{C0}")
|
||||
|
||||
@@ -618,6 +618,7 @@ class ChameleonCMD:
|
||||
resp.data = resp.status == chameleon_status.Device.HF_TAG_OK
|
||||
return resp
|
||||
|
||||
@expect_response(chameleon_status.Device.HF_TAG_OK)
|
||||
def hf14a_raw(self, options, resp_timeout_ms=100, data=[], bitlen=None):
|
||||
"""
|
||||
Send raw cmd to 14a tag
|
||||
@@ -1213,7 +1214,11 @@ class ChameleonCMD:
|
||||
def test_fn():
|
||||
# connect to chameleon
|
||||
dev = chameleon_com.ChameleonCom()
|
||||
dev.open("com19")
|
||||
try:
|
||||
dev.open('com19')
|
||||
except chameleon_com.OpenFailException:
|
||||
dev.open('/dev/ttyACM0')
|
||||
|
||||
cml = ChameleonCMD(dev)
|
||||
ver = cml.get_app_version()
|
||||
print(f"Firmware number of application: {ver[0]}.{ver[1]}")
|
||||
@@ -1232,44 +1237,42 @@ def test_fn():
|
||||
'check_response_crc': 0,
|
||||
}
|
||||
|
||||
# unlock 1
|
||||
resp = cml.hf14a_raw(options=options, resp_timeout_ms=1000, data=[0x40], bitlen=7)
|
||||
try:
|
||||
# unlock 1
|
||||
resp = cml.hf14a_raw(options=options, resp_timeout_ms=1000, data=[0x40], bitlen=7)
|
||||
|
||||
if resp.status == 0x00 and resp.data[0] == 0x0a:
|
||||
print("Gen1A unlock 1 success")
|
||||
# unlock 2
|
||||
resp = cml.hf14a_raw(options=options, resp_timeout_ms=1000, data=[0x43])
|
||||
if resp.status == 0x00 and resp.data[0] == 0x0a:
|
||||
print("Gen1A unlock 2 success")
|
||||
print("Start dump gen1a memory...")
|
||||
block = 0
|
||||
while block < 64:
|
||||
# Tag read block cmd
|
||||
cmd_read_gen1a_block = [0x30, block]
|
||||
|
||||
if resp[0] == 0x0a:
|
||||
print("Gen1A unlock 1 success")
|
||||
# unlock 2
|
||||
resp = cml.hf14a_raw(options=options, resp_timeout_ms=1000, data=[0x43])
|
||||
if resp[0] == 0x0a:
|
||||
print("Gen1A unlock 2 success")
|
||||
print("Start dump gen1a memory...")
|
||||
# Transfer with crc
|
||||
options['append_crc'] = 1
|
||||
options['check_response_crc'] = 1
|
||||
resp = cml.hf14a_raw(options=options, resp_timeout_ms=100, data=cmd_read_gen1a_block)
|
||||
|
||||
print(f"Block {block} : {resp.data.hex()}")
|
||||
block += 1
|
||||
block = 0
|
||||
while block < 64:
|
||||
# Tag read block cmd
|
||||
cmd_read_gen1a_block = [0x30, block]
|
||||
if block == 63:
|
||||
options['keep_rf_field'] = 0
|
||||
resp = cml.hf14a_raw(options=options, resp_timeout_ms=100, data=cmd_read_gen1a_block)
|
||||
|
||||
# Close rf field
|
||||
options['keep_rf_field'] = 0
|
||||
resp = cml.hf14a_raw(options=options)
|
||||
print(f"Block {block} : {resp.hex()}")
|
||||
block += 1
|
||||
|
||||
else:
|
||||
print("Gen1A unlock 2 fail")
|
||||
else:
|
||||
print("Gen1A unlock 2 fail")
|
||||
else:
|
||||
print("Gen1A unlock 1 fail")
|
||||
print("Gen1A unlock 1 fail")
|
||||
except:
|
||||
options['keep_rf_field'] = 0
|
||||
options['wait_response'] = 0
|
||||
cml.hf14a_raw(options=options)
|
||||
|
||||
# disconnect
|
||||
dev.close()
|
||||
|
||||
# never exit
|
||||
while True:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_fn()
|
||||
|
||||
@@ -341,6 +341,11 @@ class ChameleonCom:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cml = ChameleonCom().open("com19")
|
||||
resp = cml.send_cmd_sync(0x03E9, bytearray([0x01, 0x02]), 0xBEEF)
|
||||
print(resp)
|
||||
try:
|
||||
cml = ChameleonCom().open('com19')
|
||||
except OpenFailException:
|
||||
cml = ChameleonCom().open('/dev/ttyACM0')
|
||||
resp = cml.send_cmd_sync(0x03E8, None, 0)
|
||||
print(resp.status)
|
||||
print(resp.data)
|
||||
cml.close()
|
||||
|
||||
Reference in New Issue
Block a user