Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a Mifare tag using Windows Phone 8 NFC?

Does Windows Phone 8 NFC support Mifare Ultralight/Classic based tags? I use this code to access NFC device on Nokia Lumia 920 (code example was taken from NDEF Tag Reader – NFC NDEF Tag Reader)

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();
        ProximityDevice device = ProximityDevice.GetDefault();
        device.DeviceArrived += DeviceArrived;
        device.DeviceDeparted += DeviceDeparted;
        device.SubscribeForMessage("NDEF", MessageReceived);
    }

    private void DeviceArrived(ProximityDevice sender)
    {
        // this event occurs when I am tapping any of my tags (tried 5 different Mifare Ultralight/Classic)
    }

    private void DeviceDeparted(ProximityDevice sender)
    {
        // this event occurs when I am moving away any tag
    }

    private void MessageReceived(ProximityDevice sender, ProximityMessage message)
    {
        // this event is never fired!!! :(
    }
}

Is NFC on WP8 defective or is this code wrong?

Update: From this document NFC Forum Type Tags you can find that Mifare Ultralight is compatible with NDEF. Android devices can read tags of this type easily.

like image 754
A-student Avatar asked Nov 03 '12 08:11

A-student


People also ask

Can NFC tag be read?

The Read error message may appear if NFC is enabled and your Xperia device is in contact with another device or object that responds to NFC, such as a credit card, NFC tag or metro card. To prevent this message from appearing, turn off the NFC function when you don't need to use it.


2 Answers

Mifrare is supported on WP8 and on the Lumia 920. I'm guessing here, but it's likely your Mifare NFC tag isn't formatted/initialized to NDEF. You can ask your NFC tags to be NDEF formatted when you buy NFC tags.

The Lumia 920 chip (NXP PN544 family) supports the following tag types (at least):

  • Type 1: Topaz family
  • Type 2: Mifare Ultralight family, my-d-move, NTag
  • Type 3: Felica family
  • Type 4: Desfire family
  • Non standardized: Mifare Standard

Regarding NFC tags NDEF formating:

  • WP8 only supports NDEF level access to these tags, which means that the tag needs to be NDEF formatted or have an exsiting NDEF message to it (can be an empty one). If you try to use the APIs on a non-formatted NFC tags they won’t work (as WP8 lacks support for low level Tag Type specific commands/access)
  • If you want to NDEF format your tags you have the following options: when ordering tags request them to be NDEF formatted (or/and contain an empty NDEF message and the tag to be unlocked), use an NFC USB Reader/Writer HW for PC or use an Symbian/MeeGo/Android NFC device with an NFC writing app

Sincerely,
-- Justin Angel
Principal Engineer for Windows Phone Developer Experience at Nokia

like image 74
JustinAngel Avatar answered Oct 04 '22 11:10

JustinAngel


The code you posted is supposed to read NDEF messages from a NFC tag.

Whereas Mifare is also used with NFC tags, that's where the similarity ends: it's a completely different protocol with its own (proprietary) data format.

So, this code isn't really wrong (nor is NFC on WP8 generally 'defective'), but if you expect it to read Mifare tags, this approach won't work for you.

I don't know if it's possible to read Mifare tags with WP8: this depends on the hardware (as Mifare uses some non-ISO frames) as well as the API support. A quick Google search suggests that the Java SDK for older Nokia phones does support Mifare, so the hardware support may be there. Didn't find anything for WP8, though, so this will most likely require some extensive coding, if it works at all.

To give you some idea of what's needed: after you get your DeviceArrived event (which means that the reader detected an ISO NFC tag), you need to obtain the UID of the card. This should be pretty easy, as that's standard ISO functionality.

Next, you need the ability to directly send Mifare authentication and read/write sector commands to the tag. Since these commands aren't ISO-standard, this is where things get more tricky and reader-dependent. Getting past this stage really required protocol documentation and a working Mifare test tool for your phone. Finally, most Mifare cards are completely unreadable unless you at least know one sector key, and the application data format is proprietary (specific to the card issuer) as well, so even after all that work, it's not guaranteed you can get useful information off the card...

like image 22
mdb Avatar answered Oct 04 '22 12:10

mdb