86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
"""Tests for the Infineon my-d vicinity (SRF55V02P / SRF55V10P)."""
|
|
import asyncio
|
|
import pytest
|
|
|
|
from pm3py.sim.frame import RFFrame
|
|
from pm3py.transponders.hf.iso15693.infineon.myd_vicinity import SRF55V02P, SRF55V10P
|
|
|
|
|
|
def run(coro):
|
|
return asyncio.new_event_loop().run_until_complete(coro)
|
|
|
|
|
|
def cmd(tag, payload: bytes):
|
|
return run(tag.handle_frame(RFFrame.from_bytes(payload)))
|
|
|
|
|
|
class TestIdentity:
|
|
@pytest.mark.parametrize("cls,prefix,blocks", [
|
|
(SRF55V02P, b"\xE0\x05\x40", 56),
|
|
(SRF55V10P, b"\xE0\x05\x00", 248),
|
|
])
|
|
def test_uid_and_blocks(self, cls, prefix, blocks):
|
|
tag = cls()
|
|
assert tag._uid[0:3] == prefix
|
|
assert tag._num_blocks == blocks
|
|
|
|
def test_infineon_mfg_code(self):
|
|
assert SRF55V02P()._uid[1] == 0x05
|
|
|
|
def test_no_get_system_info(self):
|
|
tag = SRF55V02P()
|
|
run(tag.power_on())
|
|
r = cmd(tag, bytes([0x02, 0x2B]))
|
|
assert r.data[0] == 0x01 and r.data[1] == 0x01 # command not supported
|
|
|
|
def test_inventory(self):
|
|
tag = SRF55V02P()
|
|
run(tag.power_on())
|
|
r = cmd(tag, bytes([0x26, 0x01, 0x00]))
|
|
assert r.data[0] == 0x00
|
|
assert bytes(reversed(r.data[2:10])) == tag._uid
|
|
|
|
|
|
class TestBlockMode:
|
|
def test_iso_read_write(self):
|
|
tag = SRF55V02P()
|
|
run(tag.power_on())
|
|
cmd(tag, bytes([0x02, 0x21, 0x05, 0xCA, 0xFE, 0xBA, 0xBE]))
|
|
assert cmd(tag, bytes([0x02, 0x20, 0x05])).data[1:5] == b"\xCA\xFE\xBA\xBE"
|
|
|
|
|
|
class TestPageMode:
|
|
def test_custom_read_page_reflects_blocks(self):
|
|
tag = SRF55V02P()
|
|
run(tag.power_on())
|
|
# block 5 lives in page 2 (bytes 4-7 of the 8-byte page)
|
|
cmd(tag, bytes([0x02, 0x21, 0x05, 0xCA, 0xFE, 0xBA, 0xBE]))
|
|
r = cmd(tag, bytes([0x02, 0xA0, 0x05, 0x10, 0x02, 0x00]))
|
|
assert len(r.data) == 9
|
|
assert r.data[5:9] == b"\xCA\xFE\xBA\xBE"
|
|
|
|
def test_custom_write_page(self):
|
|
tag = SRF55V02P()
|
|
run(tag.power_on())
|
|
cmd(tag, bytes([0x02, 0xA0, 0x05, 0x30, 0x03, 0x00]) + bytes(range(8)))
|
|
r = cmd(tag, bytes([0x02, 0xA0, 0x05, 0x10, 0x03, 0x00]))
|
|
assert r.data[1:9] == bytes(range(8))
|
|
|
|
def test_write_and_reread(self):
|
|
tag = SRF55V02P()
|
|
run(tag.power_on())
|
|
r = cmd(tag, bytes([0x02, 0xA0, 0x05, 0xB0, 0x04, 0x00]) + bytes([9] * 8))
|
|
assert r.data[0] == 0x00 and r.data[1:9] == bytes([9] * 8)
|
|
|
|
|
|
class TestValueCounter:
|
|
def test_decrement_only(self):
|
|
tag = SRF55V02P()
|
|
run(tag.power_on())
|
|
# set page 6 counter0 to 16
|
|
cmd(tag, bytes([0x02, 0xA0, 0x05, 0x30, 0x06, 0x00]) + bytes([0x10, 0, 0, 0, 0, 0, 0, 0]))
|
|
# decrement to 5 → ok
|
|
assert cmd(tag, bytes([0x02, 0xA0, 0x05, 0x00, 0x06, 0x00]) + bytes([5, 0, 0, 0])).data[0] == 0x00
|
|
# increment to 9 → rejected
|
|
assert cmd(tag, bytes([0x02, 0xA0, 0x05, 0x00, 0x06, 0x00]) + bytes([9, 0, 0, 0])).data[0] == 0x01
|