0

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:

enter image description here enter image description here

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;
    }
}
Aleksei .C
  • 111
  • 1
  • 7
  • The smart card is encrypteda nd you must unlock card before reading. First use a File Explorer to read card. The card will stay unlocked. Then run your app. If App works than the issue is you app need to unlock the card. – jdweng Apr 17 '21 at 14:40
  • @jdweng, How can i read card using File Explorer? I even don't have reader in devices there – Aleksei .C Apr 17 '21 at 17:09
  • There are different type cards. Most cards are mounted in your machine as a File System. So the File Explorer can read the card. The card need to be mounted so you first install the driver of the card from the manufaucturer. When you put the card into the reader the driver automatically mounts the card. The process is similar to when you put a USB device into your machine like a memory stick. The memory stick is mounted as a File System. Other USB devices are installed as a Serial Device. A hardware device has a header that indicates the type of device. – jdweng Apr 17 '21 at 21:09
  • The ACS ACR 1252 is a USB card reader. So the driver for the card reader is installed on machine to look like a removable harddrive. The card reader has hardware/software that communicates with the driver you install on your machine. So the card is info is sent serially to the driver in your machine and the driver makes the serial data look like a File System. – jdweng Apr 17 '21 at 21:14
  • @jdweng, Only harddrives i can see in File Explorer is two my harddrives, beside that nothing else – Aleksei .C Apr 18 '21 at 09:13
  • Did you have a card in the reader? Did you install the manufacturer reader driver? Go to device manager and check if you see reader and card? Is the card a file system or a another type of device? The card could be a serial device. – jdweng Apr 18 '21 at 10:11
  • @jdweng, Yeah i have installed reader driver, in Device Manager it is in Smart card reader, readers name is: ACR1252 1S CL Reader PICC – Aleksei .C Apr 18 '21 at 10:19

1 Answers1

0

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.

jdweng
  • 33,250
  • 2
  • 15
  • 20
  • No I can't read it via file explorer. Maybe you mean by card is typical plastic card which i have to insert into reader, but no it isn't. It is contactless card, it is not even a card. It is device which has nfc emulating chip with name pn71501. I have to attach the device to the reader and that is it. – Aleksei .C Apr 20 '21 at 14:46
  • Basically work the same. Did device come with a disk with a driver? Read following https://www.nxp.com/products/rfid-nfc/nfc-hf/nfc-readers/high-performance-nfc-controller-ic-with-support-for-apple-enhanced-contactless-polling-ecp:PN7150X?tab=Documentation_Tab Page 2 talks about drivers. – jdweng Apr 20 '21 at 15:03
  • No, it isn't. I have a lot of same devices and every device has it's own serial which shared via is NFC Controller i specified earlier. Maybe emulated NFC tag read differently than regular, passive tag? – Aleksei .C Apr 20 '21 at 15:29
  • I just meant to say that card doesn't automatically gets unlocked. check Device Manager to see if you have the correct driver installed. Often with Plug and Play the wrong driver gets installed or yuo first have to log in as Admin before it gets installed. – jdweng Apr 20 '21 at 15:36
  • Yeap the driver is correct, ACS has universal driver for its devices. What do you mean by GET UNLOCKED? Reader is working perfectly with other (passive / not emulated) tags. – Aleksei .C Apr 20 '21 at 15:39
  • There are two drivers. One for the read and one for the device. Some devices have encryption modes that keep device locked until a key unlocks device. Not with this case. Finally found all the documentation : https://www.nxp.com/products/rfid-nfc/nfc-hf/nfc-readers/high-performance-nfc-controller-with-integrated-firmware-for-smart-devices:PN7150?&tab=Documentation_Tab&linkline=Application-Note&force_isolation=true – jdweng Apr 20 '21 at 15:50