def test_write_service_check_block_data(self, tag, bn, be): def write(block_number, block_data, wb, we): assert block_data == BLOCK_DATA(block_number % 256) assert wb is True and we is True return True tag.add_service(0x0009, lambda: False, write) cmd = '{:02x} 08 02fe010203040506 010900 01 {:s}' cmd = HEX(cmd.format(14 + len(HEX(be)) + 16, be)) + BLOCK_DATA(bn) assert tag.process_command(cmd) == HEX('0C 09 02fe010203040506 0000')
def test_read_service_check_block_data(self, tag, bn, be): def read(block_number, rb, re): assert rb is True and re is True return BLOCK_DATA(block_number % 256) tag.add_service(0x000B, read, lambda: False) cmd_fmt = '{:02x} 06 02fe010203040506 010b00 01 {:s}' cmd = HEX(cmd_fmt.format(14 + len(HEX(be)), be)) rsp = HEX('1d 07 02fe010203040506 0000 01') + BLOCK_DATA(bn) assert tag.process_command(cmd) == rsp
def test_read_service_multiple_blocks(self, tag, nob, bel): def read(block_number, rb, re): assert rb is (True if block_number == 0 else False) assert re is (True if block_number == nob-1 else False) return BLOCK_DATA(0) tag.add_service(0x000B, read, lambda: False) cmd_fmt = '{:02x} 06 02fe010203040506 010b00 {:s}' rsp_fmt = '{:x}D 07 02fe010203040506 0000 {:02x} {:s}' cmd = HEX(cmd_fmt.format(13 + len(HEX(bel)), bel)) rsp = HEX(rsp_fmt.format(nob, nob, nob * 16 * '00')) assert tag.process_command(cmd) == rsp
def test_read_service_multiple_blocks(self, tag, nob, bel): def read(block_number, rb, re): assert rb is (True if block_number == 0 else False) assert re is (True if block_number == nob - 1 else False) return BLOCK_DATA(0) tag.add_service(0x000B, read, lambda: False) cmd_fmt = '{:02x} 06 02fe010203040506 010b00 {:s}' rsp_fmt = '{:x}D 07 02fe010203040506 0000 {:02x} {:s}' cmd = HEX(cmd_fmt.format(13 + len(HEX(bel)), bel)) rsp = HEX(rsp_fmt.format(nob, nob, nob * 16 * '00')) assert tag.process_command(cmd) == rsp
def test_write_service_multiple_blocks(self, tag, nob, bel): def write(block_number, block_data, wb, we): assert block_data == BLOCK_DATA(0) assert wb is (True if block_number == 0 else False) assert we is (True if block_number == nob-1 else False) return True tag.add_service(0x0009, lambda: False, write) cmd_fmt = '{:02x} 08 02fe010203040506 010900 {:s} {:s}' rsp_fmt = '{:02x} 09 02fe010203040506 0000' cmd = HEX(cmd_fmt.format(13+len(HEX(bel))+nob*16, bel, nob*16*'00')) rsp = HEX(rsp_fmt.format(12)) assert tag.process_command(cmd) == rsp
def test_write_service_multiple_blocks(self, tag, nob, bel): def write(block_number, block_data, wb, we): assert block_data == BLOCK_DATA(0) assert wb is (True if block_number == 0 else False) assert we is (True if block_number == nob - 1 else False) return True tag.add_service(0x0009, lambda: False, write) cmd_fmt = '{:02x} 08 02fe010203040506 010900 {:s} {:s}' rsp_fmt = '{:02x} 09 02fe010203040506 0000' cmd = HEX( cmd_fmt.format(13 + len(HEX(bel)) + nob * 16, bel, nob * 16 * '00')) rsp = HEX(rsp_fmt.format(12)) assert tag.process_command(cmd) == rsp
def test_write_wrong_service_list_index(self, tag): tag.add_service(0x000B, None, None) cmd = HEX('20 08 02fe010203040506 010b00 018100') + bytearray(16) rsp = HEX('0C 09 02fe010203040506 01A3') assert tag.process_command(cmd) == rsp
def test_write_to_non_existing_block(self, tag): tag.add_service(0x000B, None, None) cmd = HEX('20 08 02fe010203040506 010b00 018000') + bytearray(16) rsp = HEX('0C 09 02fe010203040506 01A2') assert tag.process_command(cmd) == rsp
def test_write_insufficient_block_data(self, tag): tag.add_service(0x000B, None, None) cmd = HEX('1F 08 02fe010203040506 010b00 018000') + bytearray(15) rsp = HEX('0C 09 02fe010203040506 FFA2') assert tag.process_command(cmd) == rsp
def test_read_wrong_service_list_index(self, tag): tag.add_service(0x000B, None, None) cmd = HEX('10 06 02fe010203040506 010b00 018100') rsp = HEX('0C 07 02fe010203040506 01A3') assert tag.process_command(cmd) == rsp
def test_read_from_non_existing_block(self, tag): tag.add_service(0x000B, None, None) cmd = HEX('10 06 02fe010203040506 010b00 018000') rsp = HEX('0C 07 02fe010203040506 01A2') assert tag.process_command(cmd) == rsp
def test_read_more_blocks_than_possible(self, tag): tag.add_service(0x000B, None, None) cmd = HEX('2E 06 02fe010203040506 010b00 10' + 16 * '8000') rsp = HEX('0C 07 02fe010203040506 FFA2') assert tag.process_command(cmd) == rsp