-
Notifications
You must be signed in to change notification settings - Fork 8
/
wipe.py
82 lines (61 loc) · 1.85 KB
/
wipe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
from __future__ import print_function
import RPi.GPIO as GPIO
import MFRC522
# Keys
DEFAULT_KEY = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
# Selecting key
KEY = DEFAULT_KEY
RFID = MFRC522.MFRC522()
print("# RFID Wipe\n")
print("Waiting for tag...\n")
while True:
Sector = 1
while True:
(Status, TagSize) = RFID.Request(RFID.PICC_REQIDL)
if Status != RFID.MI_OK:
continue
if TagSize < 1:
print("Can't read tag properly!")
break
if Sector >= TagSize:
break
# Only for formatting
Spacer = ""
if Sector < 10:
Spacer = " "
print("Wiping sector %s%s ... " % (Spacer, Sector), end="")
# Selecting blocks
BaseBlockLength = 4
if Sector < 32:
BlockLength = BaseBlockLength
StartAddr = Sector * BlockLength
else:
BlockLength = 16
StartAddr = 32 * BaseBlockLength + (Sector - 32) * BlockLength
BlockAddrs = []
for i in range(0, (BlockLength - 1)):
BlockAddrs.append((StartAddr + i))
TrailerBlockAddr = (StartAddr + (BlockLength - 1))
# Initializing tag
(Status, UID) = RFID.Anticoll()
if Status != RFID.MI_OK:
break
# Wiping sector
RFID.SelectTag(UID)
Status = RFID.Auth(RFID.PICC_AUTHENT1A, TrailerBlockAddr, KEY, UID)
if Status == RFID.MI_OK:
data = bytearray()
data.extend(bytearray("".ljust(len(BlockAddrs) * 16)))
i = 0
for block_num in BlockAddrs:
RFID.Write(block_num, data[(i*16):(i+1)*16])
i += 1
print("OK!")
else:
print("NO ACCESS!")
RFID.StopCrypto1()
Sector += 1
print("\nTag wiped!")
break
GPIO.cleanup()