简体   繁体   中英

Mifare Desfire / Mifare plus can't read with ACS ACR1252

Hi i'm newbie in RFID reading. So firstly i downloaded pcsc sharp repository from github. Then i tried to read binary from common rfid tag, it works perfect but the next step was to read data from as i think emulated rfid tag. RFID tag controller is pn71501. From this tag using pcsc sharp i can't read any data excluding ATR and uid. I tried to read this tag using my iPhone and it read it. So what i'm doing wrong?

I also tried to use already done software but it couldn't read it also.

Here is what i get using NFC Tools:

在此处输入图像描述 在此处输入图像描述

PS Smart Card reader i used is ACS ACR1252

Here is my code:

using System;
using System.Text;
using System.Collections.Generic;
using PCSC;
using PCSC.Iso7816;

namespace Transmit {
    public class Program {
        public static void Main() {
            using (var context = ContextFactory.Instance.Establish(SCardScope.System)) {
                var readerNames = context.GetReaders();
                if (NoReaderFound(readerNames)) {
                    Console.WriteLine("You need at least one reader in order to run this example.");
                    Console.ReadKey();
                    return;
                }

                var readerName = ChooseRfidReader(readerNames);
                if (readerName == null) {
                    return;
                }

                String response = "";

                using (var rfidReader = context.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any)) {
                  // for (byte i = 0x00; i < 0x47; i++) {
                        var apdu = new CommandApdu(IsoCase.Case3Extended, rfidReader.Protocol) {
                            CLA = 0xFF,
                            Instruction = (InstructionCode)0xB0,
                            P1 = 0x00,
                            P2 = 0x00,
                            Le = 0x10
                        };

                        using (rfidReader.Transaction(SCardReaderDisposition.Leave)) {
                            //Console.WriteLine("Retrieving the UID .... ");

                            var sendPci = SCardPCI.GetPci(rfidReader.Protocol);
                            var receivePci = new SCardPCI(); // IO returned protocol control information.

                            var receiveBuffer = new byte[256];
                            var command = apdu.ToArray();


                            var bytesReceived = rfidReader.Transmit(
                                sendPci, // Protocol Control Information (T0, T1 or Raw)
                                command, // command APDU
                                command.Length,
                                receivePci, // returning Protocol Control Information
                                receiveBuffer,
                                receiveBuffer.Length); // data buffer

                            var responseApdu =
                                new ResponseApdu(receiveBuffer, bytesReceived, IsoCase.Case3Extended, rfidReader.Protocol);

                        Console.WriteLine(String.Format("SW1: {0:X2} SW2: {1:X2}", responseApdu.SW1, responseApdu.SW2));
                        //if(responseApdu.DataSize > 0) {
                        //response += BitConverter.ToString(responseApdu.GetData()).Replace('-', ' ');
                          response += responseApdu.DataSize;
                           // }
                        }
                   // }
                }
                /*String[] devidedResponse = response.Split(' ');

                String stillResponse = "";

                bool notStarted = true;

                int skipBytes = 7;
                int onByte = 0;

                for(int i = 0; i < devidedResponse.Length; i++) {
                    if (devidedResponse[i] != "D1" && notStarted) {
                        continue;
                    } else if (onByte < skipBytes) {
                        notStarted = false;
                        onByte += 1;
                        continue;
                    } else if (devidedResponse[i] == "FE") {
                        break;
                    }

                    stillResponse += devidedResponse[i] + " ";
                }

                String res = stillResponse.Trim();

                string asciiCharString = "";

                var splitResult = res.Split(' ');

                foreach (string hexChar in splitResult) {
                    var byteChar = int.Parse(hexChar, System.Globalization.NumberStyles.HexNumber);
                    asciiCharString += (char)byteChar;
                }*/
                
                Console.WriteLine(response);
            }

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();
        }

        private static string ChooseRfidReader(IList<string> readerNames) {
            // Show available readers.
            Console.WriteLine("Available readers: ");
            for (var i = 0; i < readerNames.Count; i++) {
                Console.WriteLine($"[{i}] {readerNames[i]}");
            }

            // Ask the user which one to choose.
            Console.Write("Which reader is an RFID reader? ");
            var line = Console.ReadLine();

            if (int.TryParse(line, out var choice) && choice >= 0 && (choice <= readerNames.Count)) {
                return readerNames[choice];
            }

            Console.WriteLine("An invalid number has been entered.");
            Console.ReadKey();
            return null;
        }

        private static bool NoReaderFound(ICollection<string> readerNames) =>
            readerNames == null || readerNames.Count < 1;
    }
}

I know. I looked it up earlier. Can you read the card with the file explorer?

A hardware device like a UART can be read at three different levels

  1. Read/Write UART directly by finding hardware I/O address
  2. Read/Write through driver. In c# Use Open Serial Port. The driver gets the hardware I/O
  3. Read/Write through an application. The application does 1 and/or 2 above.

You have a working application (number 3) and I do not know if it is using method 1 or 2.

With the card reader I'm trying to make your programming as simple as possible. The easiest method is 3 if you have an API. Next easiest is method 2 which you should be able to use if you installed the vendor driver. You should see device in device manager.

To unlock the card (encryption) you also need to install the certificate than came with card. The file explorer should be able to read/write card.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM