MFRC522 authentication problem

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times
Contact:

MFRC522 authentication problem

Post by tiny »

Hello, maybe someone can help me.

I am working with Flowcode 8.2.2.15 and am currently experimenting a bit with the file MFRC522_Read_Write.fcfx from the entry:
viewtopic.php?f=63&t=19788&p=86494&hili ... ite#p86494

Reading out the UID works, but I can't handle the authentication. I always get an error message.

I tried 6x 0xFF as key and also 6x 0xFF and 4x the UID, i.e. a total of 10 bytes, as stated in the reader description:
• Authentication command code (60h, 61h)
• Block address
• Sector key byte 0
• Sector key byte 1
• Sector key byte 2
• Sector key byte 3
• Sector key byte 4
• Sector key byte 5
• Card serial number byte 0
• Card serial number byte 1
• Card serial number byte 2
• Card serial number byte 3

I use the Mifare NFC card reader module.
Mifare NFC card reader.jpg
Mifare NFC card reader.jpg (36.44 KiB) Viewed 2823 times
Does anyone have some good tips or a working process? Of course, I would also like to save data to the Tag and then read it out again for verification.

thanks
Christina

User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times
Contact:

Re: MFRC522 authentication problem

Post by tiny »

No one here in the forum who can help me?

There is always an authentication error:
Error 3 if I use the 6 bytes 0xFF and an error 1 if I use 6x 0xFF and the 4 UID bytes.
Here the file, changes mainly in the display.

Christina
Test_MFRC522_Read_Write.fcfx
(32.13 KiB) Downloaded 212 times

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: MFRC522 authentication problem

Post by mnf »

Hi Tiny,

Tried your code on an Arduino and it seems to run AOK (at least with software SPI - I'm getting more convinced there is a fault with the hardware SPI code here) - I get Auth OK, Write Ok, read Ok and read/write ok - sometimes select error, sometimes auth error - but usually works.
I didn't change anything (except to delete the out->e2 and change the pins for the attached reader and display. - I happened to have an Arduino set up with card reader and the same i2c display !

Where are you getting the problem?

I've little experience of writing to the cards - my one attempt resulted in locking the card after my attempt to change the code for a block?

Martin

User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times
Contact:

Re: MFRC522 authentication problem

Post by tiny »

Hello Martin,

Thanks for the answer!
I can only test this routine on a PIC (ECIO40P16), I have no other platform.
SPI and I2C runs on software. Reading the UID and card type is no problem, but authentication always results in an error message. Of course, write and read do not work with this.

I looked at a few Arduino sketches on the Internet, there is always a select command before authentication. There is also the macro in FC, but what are ValidBits? Which value belongs here or is this command necessary?

I used a new and a used / formatted tag. With an NFC reader / writer on the smartphone, it also works without any problems, the day can be written and read.

Christina

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: MFRC522 authentication problem

Post by mnf »

Hi Christina,

From the datasheet....
MFAuthent
This command manages MIFARE authentication to enable a secure communication to
any MIFARE Mini, MIFARE 1K and MIFARE 4K card. The following data is written to the
FIFO buffer before the command can be activated:
• Authentication command code (60h, 61h)
• Block address
• Sector key byte 0
• Sector key byte 1
• Sector key byte 2
• Sector key byte 3
• Sector key byte 4
• Sector key byte 5
• Card serial number byte 0
• Card serial number byte 1
• Card serial number byte 2
• Card serial number byte 3
In total 12 bytes are written to the FIFO.
Remark: When the MFAuthent command is active all access to the FIFO buffer is
blocked. However, if there is access to the FIFO buffer, the ErrorReg register’s WrErr bit is
set.

This command automatically terminates when the MIFARE card is authenticated and the
Status2Reg register’s MFCrypto1On bit is set to logic 1.
This command does not terminate automatically if the card does not answer, so the timer
must be initialized to automatic mode. In this case, in addition to the IdleIRq bit, the
TimerIRq bit can be used as the termination criteria. During authentication processing, the
RxIRq bit and TxIRq bit are blocked. The Crypto1On bit is only valid after termination of
the MFAuthent command, either after processing the protocol or writing Idle to the
CommandReg register.
If an error occurs during authentication, the ErrorReg register’s ProtocolErr bit is set to
logic 1 and the Status2Reg register’s Crypto1On bit is set to logic 0
However - you seem to have hardcoded the serial number (3a,35,71,25) - is this is what you intended to do (one card to test) - or should this be set to the four UID bytes read?

Martin

User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times
Contact:

Re: MFRC522 authentication problem

Post by tiny »

Hi Martin,

the UID is only hardcoded for the test, if it works, depending on the application, up to 10 UID are stored in an EEprom and already compared with the EEprom data during the UID query. This ensures that only registered tags can be used. Then I would like to write an 8-digit UID on the card and also verify it, but for the time being this is only for test purposes.

For the used / formatted card the authorization string is 6x 0x00, for the new card 6x 0xFF and before a test run I activate the corresponding entries in the program.
No matter which card, error 1 or 3.

Christina

Post Reply