'Read MifareUltralight Data - Custom Solution
I am writing a solution using Xamarin Forms, targeting Android, strong textthat will read data from an NFC card, however it is important to note that the NFC card contains unique data, so the standard NDEF records do not work.
The hardware is a Samsung Galaxy Tab Active Pro.
The original app was developed around UWP and used a Windows Tablet, so the developers used an implementation of the PCSC SDK and recently, I tried the same implementation, but no matter what I do, I am not able to read the data, except for ReadPages(int pageOffset), which results in the underlying SDK not returning the correct results.
This is the high level implementation of the ReadPages and you will also note Transceive (more about that shortly).
public static class MifareUltralightExtension
{
public static async Task<Iso7816.ApduResponse> TransmitAsync(this MifareUltralight mifare, Iso7816.ApduCommand apduCommand)
{
Iso7816.ApduResponse response = Activator.CreateInstance(apduCommand.ApduResponseType) as Iso7816.ApduResponse;
int length;
MifareUltralightType type = mifare.Type;
switch (type)
{
case MifareUltralightType.Ultralight:
length = 12;
break;
case MifareUltralightType.UltralightC:
length = 36;
break;
case MifareUltralightType.Unknown:
throw new Exception("Unknown tag");
default:
throw new Exception("Unknown tag");
}
List<byte> temp = new List<byte>();
for (int i = 0; i < length; i++)
{
byte[] read = mifare.ReadPages(i);
for (int j = 0; j < read.Length; j++)
{
temp.Add(read[j]);
}
}
byte[] b = temp.ToArray();
//Iso7816.ApduCommand command = new Iso7816.ApduCommand((byte)0xFF, (byte)0xB0, (byte)0x00, 0, null, (byte)0x10);
//byte[] a = mifare.Transceive(new byte[] { (byte)0xFF, (byte)0xB0, (byte)0x00, (byte)0x00, 0 });
//byte[] b = mifare.Transceive(command.GetBuffer());
byte[] buffer = mifare.Transceive(apduCommand.GetBuffer());
response.ExtractResponse(buffer);
return response;
}
}
I have also been trying to pass a APDU command (as outlined in the above code, where the second parameter accepts an ISO7816 command.
The byte data being passed down into the command the HeadBlock below, which is apparently the read command, however I have also note 0x03 and others, so it is not clear on what is right or wrong:
private const int BlockSize = 4;
private const byte HeaderBlock = 0x04;
private const UInt16 FormatHeader = 0x2b7b;
Using the HeaderBlock passed as a command to Transceive results in a message saying that the Transceive request is too long.
I have tried so many different approaches to this problem yet I am not able to find a suitable solution.
If anyone can please provide some help around this, it would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
