Beispiel #1
0
 def test_dump(self, tag, data, dump):
     tag.clf.exchange.side_effect = [
         (HEX('1d 07 0102030405060708 0000 01') + data[i:i + 16])
         for i in range(0, len(data), 16)
     ] + 3 * [nfc.clf.TimeoutError]
     assert tag.dump() == dump
     tag.sys = 0x0000
     assert tag.dump() == ["This is not an NFC Forum Tag."]
Beispiel #2
0
 def test_dump(self, tag, data, dump):
     tag.clf.exchange.side_effect = [
         (HEX('1d 07 0102030405060708 0000 01') + data[i:i+16])
         for i in range(0, len(data), 16)
     ] + 3 * [nfc.clf.TimeoutError]
     assert tag.dump() == dump
     tag.sys = 0x0000
     assert tag.dump() == ["This is not an NFC Forum Tag."]
Beispiel #3
0
 def test_dump_tag_with_16_blocks(self, tag):
     tag.clf.exchange.side_effect = [  # Response
         tag.target.rid_res[:2] + self.mmap[:120],  # RALL
         HEX("0F") + self.mmap[120:128],  # READ8(15)
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
     ]
     assert tag.dump() == [
         "HR0=00h, HR1=00h",
         "  0: 01 02 03 04 05 06 07 00 (UID0-UID6, RESERVED)",
         "  1: e1 10 3f 00 01 03 f2 30 |..?....0|",
         "  2: 33 02 03 f0 02 03 03 fe |3.......|",
         "  3: d1 01 fa 55 01 61 62 63 |...U.abc|",
         "  4: 64 65 66 67 68 69 6a 6b |defghijk|",
         "  5: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         "  6: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         "  7: 62 63 64 65 66 67 68 69 |bcdefghi|",
         "  8: 6a 6b 6c 6d 6e 6f 70 71 |jklmnopq|",
         "  9: 72 73 74 75 76 77 78 79 |rstuvwxy|",
         " 10: 7a 61 62 63 64 65 66 67 |zabcdefg|",
         " 11: 68 69 6a 6b 6c 6d 6e 6f |hijklmno|",
         " 12: 70 71 72 73 74 75 76 77 |pqrstuvw|",
         " 13: 55 55 aa aa 12 49 06 00 (RESERVED)",
         " 14: 01 e0 00 00 00 00 00 00 (LOCK0-LOCK1, OTP0-OTP5)",
         " 15: 00 00 00 00 00 00 00 00 (LOCK2-LOCK3, RESERVED)",
     ]
Beispiel #4
0
 def test_dump_ndef_read_access_not_zero(self, tag):
     responses = [
         HEX('029000'),
         HEX('039000'),
         HEX('02000f9000'),
         HEX('0320003b00340406 e104 0040 80 00 9000'),
         HEX('029000'),
         HEX('03000e9000'),
         HEX('02d1010a55036e666370792e6f72679000'),
     ]
     tag.clf.exchange.side_effect = responses
     assert tag.dump() == []
Beispiel #5
0
 def test_dump(self, tag):
     tag.clf.exchange.side_effect = [
         tag.target.rid_res[:2] + self.mmap[:120],  # RALL
     ] + [
         (bytearray([x]) + self.mmap[8*x:8*x+8]) for x in range(15, 64)
     ]
     assert tag.dump() == [
         "HR0=12h, HR1=4Ch",
         "  0: 31 32 33 34 35 36 37 00 (UID0-UID6, RESERVED)",
         "  1: e1 10 3f 00 01 03 f2 30 |..?....0|",
         "  2: 33 02 03 f0 02 03 03 fe |3.......|",
         "  3: d1 01 fa 55 01 61 62 63 |...U.abc|",
         "  4: 64 65 66 67 68 69 6a 6b |defghijk|",
         "  5: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         "  6: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         "  7: 62 63 64 65 66 67 68 69 |bcdefghi|",
         "  8: 6a 6b 6c 6d 6e 6f 70 71 |jklmnopq|",
         "  9: 72 73 74 75 76 77 78 79 |rstuvwxy|",
         " 10: 7a 61 62 63 64 65 66 67 |zabcdefg|",
         " 11: 68 69 6a 6b 6c 6d 6e 6f |hijklmno|",
         " 12: 70 71 72 73 74 75 76 77 |pqrstuvw|",
         " 13: 55 55 aa aa 12 49 06 00 (RESERVED)",
         " 14: 01 e0 00 00 00 00 00 00 (LOCK0-LOCK1, OTP0-OTP5)",
         " 15: 00 00 00 00 00 00 00 00 (LOCK2-LOCK3, RESERVED)",
         " 16: 78 79 7a 61 62 63 64 65 |xyzabcde|",
         " 17: 66 67 68 69 6a 6b 6c 6d |fghijklm|",
         " 18: 6e 6f 70 71 72 73 74 75 |nopqrstu|",
         " 19: 76 77 78 79 7a 61 62 63 |vwxyzabc|",
         " 20: 64 65 66 67 68 69 6a 6b |defghijk|",
         " 21: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         " 22: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         " 23: 62 63 64 65 66 67 68 69 |bcdefghi|",
         " 24: 6a 6b 6c 6d 6e 6f 70 71 |jklmnopq|",
         " 25: 72 73 74 75 76 77 78 79 |rstuvwxy|",
         " 26: 7a 61 62 63 64 65 66 67 |zabcdefg|",
         " 27: 68 69 6a 6b 6c 6d 6e 6f |hijklmno|",
         " 28: 70 71 72 73 74 75 76 77 |pqrstuvw|",
         " 29: 78 79 7a 61 62 63 64 65 |xyzabcde|",
         " 30: 66 67 68 69 6a 6b 6c 6d |fghijklm|",
         " 31: 6e 6f 70 71 72 73 74 75 |nopqrstu|",
         " 32: 76 77 78 79 7a 61 62 63 |vwxyzabc|",
         " 33: 64 65 66 67 68 69 6a 6b |defghijk|",
         " 34: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         " 35: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         " 36: 62 63 64 65 66 67 68 69 |bcdefghi|",
         " 37: 6a 6b 2e 63 6f 6d fe 00 |jk.com..|",
         " 38: 00 00 00 00 00 00 00 00 |........|",
         "  *  00 00 00 00 00 00 00 00 |........|",
         " 63: 00 00 00 00 00 00 00 00 |........|",
     ]
 def test_dump(self, tag):
     tag.clf.exchange.side_effect = [
         tag.target.rid_res[:2] + self.mmap[:120],  # RALL
     ] + [
         (bytearray([x]) + self.mmap[8*x:8*x+8]) for x in range(15, 64)
     ]
     assert tag.dump() == [
         "HR0=12h, HR1=4Ch",
         "  0: 31 32 33 34 35 36 37 00 (UID0-UID6, RESERVED)",
         "  1: e1 10 3f 00 01 03 f2 30 |..?....0|",
         "  2: 33 02 03 f0 02 03 03 fe |3.......|",
         "  3: d1 01 fa 55 01 61 62 63 |...U.abc|",
         "  4: 64 65 66 67 68 69 6a 6b |defghijk|",
         "  5: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         "  6: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         "  7: 62 63 64 65 66 67 68 69 |bcdefghi|",
         "  8: 6a 6b 6c 6d 6e 6f 70 71 |jklmnopq|",
         "  9: 72 73 74 75 76 77 78 79 |rstuvwxy|",
         " 10: 7a 61 62 63 64 65 66 67 |zabcdefg|",
         " 11: 68 69 6a 6b 6c 6d 6e 6f |hijklmno|",
         " 12: 70 71 72 73 74 75 76 77 |pqrstuvw|",
         " 13: 55 55 aa aa 12 49 06 00 (RESERVED)",
         " 14: 01 e0 00 00 00 00 00 00 (LOCK0-LOCK1, OTP0-OTP5)",
         " 15: 00 00 00 00 00 00 00 00 (LOCK2-LOCK3, RESERVED)",
         " 16: 78 79 7a 61 62 63 64 65 |xyzabcde|",
         " 17: 66 67 68 69 6a 6b 6c 6d |fghijklm|",
         " 18: 6e 6f 70 71 72 73 74 75 |nopqrstu|",
         " 19: 76 77 78 79 7a 61 62 63 |vwxyzabc|",
         " 20: 64 65 66 67 68 69 6a 6b |defghijk|",
         " 21: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         " 22: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         " 23: 62 63 64 65 66 67 68 69 |bcdefghi|",
         " 24: 6a 6b 6c 6d 6e 6f 70 71 |jklmnopq|",
         " 25: 72 73 74 75 76 77 78 79 |rstuvwxy|",
         " 26: 7a 61 62 63 64 65 66 67 |zabcdefg|",
         " 27: 68 69 6a 6b 6c 6d 6e 6f |hijklmno|",
         " 28: 70 71 72 73 74 75 76 77 |pqrstuvw|",
         " 29: 78 79 7a 61 62 63 64 65 |xyzabcde|",
         " 30: 66 67 68 69 6a 6b 6c 6d |fghijklm|",
         " 31: 6e 6f 70 71 72 73 74 75 |nopqrstu|",
         " 32: 76 77 78 79 7a 61 62 63 |vwxyzabc|",
         " 33: 64 65 66 67 68 69 6a 6b |defghijk|",
         " 34: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         " 35: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         " 36: 62 63 64 65 66 67 68 69 |bcdefghi|",
         " 37: 6a 6b 2e 63 6f 6d fe 00 |jk.com..|",
         " 38: 00 00 00 00 00 00 00 00 |........|",
         "  *  00 00 00 00 00 00 00 00 |........|",
         " 63: 00 00 00 00 00 00 00 00 |........|",
     ]
Beispiel #7
0
    def test_dump_ndef_until_no_bytes_returned(self, tag):
        responses = [
            HEX('02 9000'),
            HEX('03 9000'),
            HEX('02 000f 9000'),
            HEX('03 20003b00340406e10408000000 9000'),
            HEX('02 9000'),
            HEX('03 000e 9000'),
            HEX('02 d1010a55036e666370792e6f7267 9000'),
            HEX('03 000ed1010a55036e666370792e6f7267 9000'),
            HEX('02 00000000000000000000000000000000 9000'),
            HEX('03 9000')
        ]
        tag.clf.exchange.side_effect = responses
        assert '\n'.join(tag.dump()) == """
0x0000: 00 0e d1 01 0a 55 03 6e 66 63 70 79 2e 6f 72 67 |.....U.nfcpy.org|
0x0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
""".strip()
Beispiel #8
0
 def test_dump_tag_with_17_blocks(self, tag):
     tag.clf.exchange.side_effect = [  # Response
         tag.target.rid_res[:2] + self.mmap[:120],  # RALL
         fromhex("0F") + self.mmap[120:128],  # READ8(15)
         fromhex("10") + self.mmap[128:136],  # READ8(16)
         fromhex("54 8786859e9d9c9b9a"),  # WRITE-E8(16)
         fromhex("54 78797A6162636465"),  # WRITE-E8(16)
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
     ]
     assert tag.dump() == [
         "HR0=00h, HR1=00h",
         "  0: 01 02 03 04 05 06 07 00 (UID0-UID6, RESERVED)",
         "  1: e1 10 3f 00 01 03 f2 30 |..?....0|",
         "  2: 33 02 03 f0 02 03 03 fe |3.......|",
         "  3: d1 01 fa 55 01 61 62 63 |...U.abc|",
         "  4: 64 65 66 67 68 69 6a 6b |defghijk|",
         "  5: 6c 6d 6e 6f 70 71 72 73 |lmnopqrs|",
         "  6: 74 75 76 77 78 79 7a 61 |tuvwxyza|",
         "  7: 62 63 64 65 66 67 68 69 |bcdefghi|",
         "  8: 6a 6b 6c 6d 6e 6f 70 71 |jklmnopq|",
         "  9: 72 73 74 75 76 77 78 79 |rstuvwxy|",
         " 10: 7a 61 62 63 64 65 66 67 |zabcdefg|",
         " 11: 68 69 6a 6b 6c 6d 6e 6f |hijklmno|",
         " 12: 70 71 72 73 74 75 76 77 |pqrstuvw|",
         " 13: 55 55 aa aa 12 49 06 00 (RESERVED)",
         " 14: 01 e0 00 00 00 00 00 00 (LOCK0-LOCK1, OTP0-OTP5)",
         " 15: 00 00 00 00 00 00 00 00 (LOCK2-LOCK3, RESERVED)",
         " 16: 78 79 7a 61 62 63 64 65 |xyzabcde|",
     ]
     assert tag.clf.exchange.mock_calls == [
         mock.call(fromhex("00 00 00 01020304"), 0.1),
         mock.call(fromhex('02 0f 0000000000000000 01020304'), 0.1),
         mock.call(fromhex('02 10 0000000000000000 01020304'), 0.1),
         mock.call(fromhex('54 10 8786859e9d9c9b9a 01020304'), 0.1),
         mock.call(fromhex('54 10 78797A6162636465 01020304'), 0.1),
         mock.call(fromhex('02 11 0000000000000000 01020304'), 0.1),
         mock.call(fromhex('02 11 0000000000000000 01020304'), 0.1),
         mock.call(fromhex('02 11 0000000000000000 01020304'), 0.1),
     ]
Beispiel #9
0
 def test_dump(self, tag):
     tag.clf.exchange.side_effect = [
         tag.target.rid_res[:2] + self.mmap[:120],  # RALL
     ]
     assert tag.dump() == [
         "HR0=11h, HR1=48h",
         "  0: 01 02 03 04 05 06 07 00 (UID0-UID6, RESERVED)",
         "  1: e1 10 0e 00 03 2a d1 01 |.....*..|",
         "  2: 26 55 01 61 62 63 64 65 |&U.abcde|",
         "  3: 66 67 68 69 6a 6b 6c 6d |fghijklm|",
         "  4: 6e 6f 70 71 72 73 74 75 |nopqrstu|",
         "  5: 76 77 78 79 7a 61 62 63 |vwxyzabc|",
         "  6: 64 65 66 67 2e 63 6f 6d |defg.com|",
         "  7: fe 00 00 00 00 00 00 00 |........|",
         "  8: 00 00 00 00 00 00 00 00 |........|",
         "  9: 00 00 00 00 00 00 00 00 |........|",
         " 10: 00 00 00 00 00 00 00 00 |........|",
         " 11: 00 00 00 00 00 00 00 00 |........|",
         " 12: 00 00 00 00 00 00 00 00 |........|",
         " 13: 55 55 aa aa 00 00 00 00 (RESERVED)",
         " 14: 01 60 00 00 00 00 00 00 (LOCK0-LOCK1, OTP0-OTP5)",
     ]
Beispiel #10
0
 def test_dump(self, tag):
     tag.clf.exchange.side_effect = [
         tag.target.rid_res[:2] + self.mmap[:120],  # RALL
     ]
     assert tag.dump() == [
         "HR0=11h, HR1=48h",
         "  0: 01 02 03 04 05 06 07 00 (UID0-UID6, RESERVED)",
         "  1: e1 10 0e 00 03 2a d1 01 |.....*..|",
         "  2: 26 55 01 61 62 63 64 65 |&U.abcde|",
         "  3: 66 67 68 69 6a 6b 6c 6d |fghijklm|",
         "  4: 6e 6f 70 71 72 73 74 75 |nopqrstu|",
         "  5: 76 77 78 79 7a 61 62 63 |vwxyzabc|",
         "  6: 64 65 66 67 2e 63 6f 6d |defg.com|",
         "  7: fe 00 00 00 00 00 00 00 |........|",
         "  8: 00 00 00 00 00 00 00 00 |........|",
         "  9: 00 00 00 00 00 00 00 00 |........|",
         " 10: 00 00 00 00 00 00 00 00 |........|",
         " 11: 00 00 00 00 00 00 00 00 |........|",
         " 12: 00 00 00 00 00 00 00 00 |........|",
         " 13: 55 55 aa aa 00 00 00 00 (RESERVED)",
         " 14: 01 60 00 00 00 00 00 00 (LOCK0-LOCK1, OTP0-OTP5)",
     ]
Beispiel #11
0
def test_tag_dump(tag):
    assert tag.dump() == []
Beispiel #12
0
 def test_dump(self, tag):
     responses = [
         HEX("28292a2b 2c2d2e2f 30313233 34353637"),
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
         HEX("30313233 34353637 38393a3b 3c3d3e3f"),
         HEX("34353637 38393a3b 3c3d3e3f 40414243"),
         HEX("38393a3b 3c3d3e3f 40414243 44454647"),
         HEX("00000000 00000000 00000000 00000000"),
         HEX("00000000 00000000 00000000 00000000"),
         HEX("00000000 00000000 00000000 00000000"),
         HEX("3c3d3e3f 40414243 44454647 48494a4b"),
         HEX("40414243 44454647 48494a4b 4c4d4e4f"),
         HEX("44454647 48494a4b 4c4d4e4f 28292a2b"),
         HEX("48494a4b 4c4d4e4f 28292a2b 2c2d2e2f"),
         HEX("4c4d4e4f 28292a2b 2c2d2e2f 30313233"),
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
         nfc.clf.TimeoutError,
     ]
     tag.clf.exchange.side_effect = responses
     assert tag.dump() == [
         "000: 28 29 2a 2b (UID0-UID2, BCC0)",
         "001: ?? ?? ?? ?? (UID3-UID6)",
         "002: 30 31 32 33 (BCC1, INT, LOCK0-LOCK1)",
         "003: 34 35 36 37 (OTP0-OTP3)",
         "004: 38 39 3a 3b |89:;|",
         "005: 00 00 00 00 |....|",
         "  *  00 00 00 00 |....|",
         "007: 00 00 00 00 |....|",
         "008: 3c 3d 3e 3f |<=>?|",
         "009: 40 41 42 43 |@ABC|",
         "00A: 44 45 46 47 |DEFG|",
         "00B: 48 49 4a 4b |HIJK|",
         "00C: 4c 4d 4e 4f |LMNO|",
     ]
     tag.clf.exchange.side_effect = responses
     assert tag._dump(13) == [
         "000: 28 29 2a 2b (UID0-UID2, BCC0)",
         "001: ?? ?? ?? ?? (UID3-UID6)",
         "002: 30 31 32 33 (BCC1, INT, LOCK0-LOCK1)",
         "003: 34 35 36 37 (OTP0-OTP3)",
         "004: 38 39 3a 3b |89:;|",
         "005: 00 00 00 00 |....|",
         "  *  00 00 00 00 |....|",
         "007: 00 00 00 00 |....|",
         "008: 3c 3d 3e 3f |<=>?|",
         "009: 40 41 42 43 |@ABC|",
         "00A: 44 45 46 47 |DEFG|",
         "00B: 48 49 4a 4b |HIJK|",
         "00C: 4c 4d 4e 4f |LMNO|",
     ]
     tag.clf.exchange.side_effect = responses
     assert tag._dump(14) == [
         "000: 28 29 2a 2b (UID0-UID2, BCC0)",
         "001: ?? ?? ?? ?? (UID3-UID6)",
         "002: 30 31 32 33 (BCC1, INT, LOCK0-LOCK1)",
         "003: 34 35 36 37 (OTP0-OTP3)",
         "004: 38 39 3a 3b |89:;|",
         "005: 00 00 00 00 |....|",
         "  *  00 00 00 00 |....|",
         "007: 00 00 00 00 |....|",
         "008: 3c 3d 3e 3f |<=>?|",
         "009: 40 41 42 43 |@ABC|",
         "00A: 44 45 46 47 |DEFG|",
         "00B: 48 49 4a 4b |HIJK|",
         "00C: 4c 4d 4e 4f |LMNO|",
         "00D: ?? ?? ?? ?? |....|",
     ]
Beispiel #13
0
 def test_dump(self, tag):
     responses = [
         HEX("28292a2b 2c2d2e2f 30313233 34353637"),
         nfc.clf.TimeoutError, nfc.clf.TimeoutError, nfc.clf.TimeoutError,
         HEX("30313233 34353637 38393a3b 3c3d3e3f"),
         HEX("34353637 38393a3b 3c3d3e3f 40414243"),
         HEX("38393a3b 3c3d3e3f 40414243 44454647"),
         HEX("00000000 00000000 00000000 00000000"),
         HEX("00000000 00000000 00000000 00000000"),
         HEX("00000000 00000000 00000000 00000000"),
         HEX("3c3d3e3f 40414243 44454647 48494a4b"),
         HEX("40414243 44454647 48494a4b 4c4d4e4f"),
         HEX("44454647 48494a4b 4c4d4e4f 28292a2b"),
         HEX("48494a4b 4c4d4e4f 28292a2b 2c2d2e2f"),
         HEX("4c4d4e4f 28292a2b 2c2d2e2f 30313233"),
         nfc.clf.TimeoutError, nfc.clf.TimeoutError, nfc.clf.TimeoutError,
     ]
     tag.clf.exchange.side_effect = responses
     assert tag.dump() == [
         "000: 28 29 2a 2b (UID0-UID2, BCC0)",
         "001: ?? ?? ?? ?? (UID3-UID6)",
         "002: 30 31 32 33 (BCC1, INT, LOCK0-LOCK1)",
         "003: 34 35 36 37 (OTP0-OTP3)",
         "004: 38 39 3a 3b |89:;|",
         "005: 00 00 00 00 |....|",
         "  *  00 00 00 00 |....|",
         "007: 00 00 00 00 |....|",
         "008: 3c 3d 3e 3f |<=>?|",
         "009: 40 41 42 43 |@ABC|",
         "00A: 44 45 46 47 |DEFG|",
         "00B: 48 49 4a 4b |HIJK|",
         "00C: 4c 4d 4e 4f |LMNO|",
     ]
     tag.clf.exchange.side_effect = responses
     assert tag._dump(13) == [
         "000: 28 29 2a 2b (UID0-UID2, BCC0)",
         "001: ?? ?? ?? ?? (UID3-UID6)",
         "002: 30 31 32 33 (BCC1, INT, LOCK0-LOCK1)",
         "003: 34 35 36 37 (OTP0-OTP3)",
         "004: 38 39 3a 3b |89:;|",
         "005: 00 00 00 00 |....|",
         "  *  00 00 00 00 |....|",
         "007: 00 00 00 00 |....|",
         "008: 3c 3d 3e 3f |<=>?|",
         "009: 40 41 42 43 |@ABC|",
         "00A: 44 45 46 47 |DEFG|",
         "00B: 48 49 4a 4b |HIJK|",
         "00C: 4c 4d 4e 4f |LMNO|",
     ]
     tag.clf.exchange.side_effect = responses
     assert tag._dump(14) == [
         "000: 28 29 2a 2b (UID0-UID2, BCC0)",
         "001: ?? ?? ?? ?? (UID3-UID6)",
         "002: 30 31 32 33 (BCC1, INT, LOCK0-LOCK1)",
         "003: 34 35 36 37 (OTP0-OTP3)",
         "004: 38 39 3a 3b |89:;|",
         "005: 00 00 00 00 |....|",
         "  *  00 00 00 00 |....|",
         "007: 00 00 00 00 |....|",
         "008: 3c 3d 3e 3f |<=>?|",
         "009: 40 41 42 43 |@ABC|",
         "00A: 44 45 46 47 |DEFG|",
         "00B: 48 49 4a 4b |HIJK|",
         "00C: 4c 4d 4e 4f |LMNO|",
         "00D: ?? ?? ?? ?? |....|",
     ]