MIFARE经典1k MFRC522-python lib

时间:2015-03-15 17:06:43

标签: python nfc mifare

我正在学习使用带有Raspberry pi的MFRC522模块。 我正在使用MFRC522-python lib。

我能够从mifare 1k读取和写入数据,直到我尝试更改Key。 我试过更改扇区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"

1 个答案:

答案 0 :(得分:0)

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