MIFARE 经典 1k MFRC522-python 库

MIFARE classic 1k MFRC522-python lib

我正在学习将 MFRC522 模块与 Raspberry pi 一起使用。 我正在使用 MFRC522-python 库。

在尝试更改密钥之前,我能够从 mifare 1k 读取和写入数据。 我尝试更改扇区 7。 是这样的:

[0, 0, 0, 0, 0, 0, 255, 7, 128, 105, 255, 255, 255, 255, 255, 255]

然后像这样改变之后:

[0, 0, 0, 0, 0, 0, 255, 7, 128, 105, 250, 250, 250, 250, 250, 250]

修改后我可以用密钥 A 读取扇区 0-3:

255, 255, 255, 255, 255, 255

和密钥 B 的扇区 7:

250,250,250,250,250,250

试图恢复初始设置我犯了一个错误,将扇区 7 更改为:

[255, 255, 255,255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]

现在我只能读取 UID。 我知道 6-7-8 块包含权限,但我找不到关于这个主题的好文档。 我如何重置初始设置?

我正在尝试使用此代码:

# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."

# This loop keeps checking for chips. If one is near it will get the UID  and authenticate
while continue_reading:

# Scan for cards    
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

# If a card is found
if status == MIFAREReader.MI_OK:
    print "Card detected"

# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()

# If we have the UID, continue
if status == MIFAREReader.MI_OK:

    # Print UID
    print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])

    # This is the default key for authentication
    key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
    setas = [0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x07,0x80,0x69,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
    sect = 7
    # Select the scanned tag
    MIFAREReader.MFRC522_SelectTag(uid)

    # Authenticate
    status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, sect, key, uid)

    # Check if authenticated
    if status == MIFAREReader.MI_OK:
        MIFAREReader.MFRC522_Read(sect)

        MIFAREReader.MFRC522_Write(sect,setas)

        MIFAREReader.MFRC522_Read(sect)
        MIFAREReader.MFRC522_StopCrypto1()
    else:
        print "Authentication error"

good doc about Mifare classic 1k 在这里你可以学习如何设置访问位。

我已经完全阻止对整个扇区的所有访问。

注意:

To further complicate things, there are also 3 “negated” bits per block that are stored as the opposite value of the “normal” bits. So, if
C10 is 1, then C10 must be 0. The tag will check to ensure these negated values all check out, and if they don’t then the tag will assume
the tag’s memory is corrupt or there has been some sort of tampering attempt and completely block all access to the entire sector. It is
essential that the access bits are properly written to the tag or sectors with invalid sector trailers will be unreadable.

其他好的文档可以在 adafruit 文档中找到,如下所示: learn Adafruit