15

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.

A-student
  • 775
  • 1
  • 5
  • 12
  • Please taka a look at my topic: http://stackoverflow.com/questions/21239536/unauthorizedaccessexception-while-initializing-proximitydevice-windows-phone –  Jan 20 '14 at 17:12

4 Answers4

14

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

JustinAngel
  • 15,984
  • 3
  • 42
  • 73
  • The tags I’m using are already written and cannot be rewritten. Anyway thank you for the reply! – A-student Nov 05 '12 at 08:17
  • 1
    To add to Justin's great response, here is another good post for follow-up http://dotnet-redzone.blogspot.com/2012/12/nfc-tags-with-windows-phone-8.html – Lance McCarthy Jan 26 '13 at 03:18
  • 1
    @JustinAngel Will the NFC SDK be extended in the future to allow low level access? Maybe in the second WP8 update? In its current form there is no real opportunity to use WP8 in a business setting with NFC tags. – Franz Kafka Mar 11 '13 at 14:41
  • @JustinAngel does this mean the encryption/decryption stuff won't work? – Rob Grant Oct 08 '13 at 11:01
  • Could you please take a look at my topic about NFC PLEASE : ( : http://stackoverflow.com/questions/21239536/unauthorizedaccessexception-while-initializing-proximitydevice-windows-phone –  Jan 20 '14 at 17:13
5

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...

mdb
  • 49,388
  • 10
  • 62
  • 62
  • Thank you for the reply. From this doc http://www.nfc-forum.org/resources/white_papers/NXP_BV_Type_Tags_White_Paper-Apr_09.pdf you can find that Mifare Ultralight is compatible with NDEF and is supported by NFC Forum. Android devices can read tags of this type easily. Your answer concerns only Mifare Classic and not very helpful, there is no low-level NFC API on WP8. – A-student Nov 03 '12 at 10:00
3

Windows Phone 8 Apps only have access to the very high level libraries, and cannot read tags that are not NDEF formatted.

MIFARE UL tags must use the NFC Forum NDEF Type 2 standard, which is simplistic due to the small 48 byte user memory of the tag.

If you have a low level reader/writer, you can make your UL tag NDEF compliant without modifying the majority of your data, but you will need to sacrifice:

  • all 4 bytes of OTP memory at page 3 (for the NDEF Capability Container)
  • the first 6 bytes of user programmable memory (6 at the very minimum, might want to pad to 8 to cleanly fill first two pages).

The tag is formatted like so: (reference - www.nfc-forum.org/specs/spec_list/#tagtypes)

  • PAGE 3, BYTES 0-3: CC [MAGIC NUMBER, VERSION, USER MEM SIZE, READ/WRITE]
  • PAGE 4, BYTES 0-1: NDEF MESSAGE TLV HEADER [Type, Length] (Recommend type ExternalRtd)
  • PAGE 4, BYTES 2-3: RECORD DESCRIPTOR (Includes a string that specifies record type, suggest making it 1 byte long to save space, or 3 bytes long for neat padding)
  • PAGE 5, BYTES 0-1 or 3: RECORD DESCRIPTOR
  • REST OF PAGES/BYTES ARE RECORD/DATA

EXAMPLE: Tag has message type ExternalRtd, and record type "abc" (record type should technically be of the format "urn:nfc:ext:companyname.com:typename" to be fully NDEF compliant, but we can't afford to use that much space)

[Page No., Byte No.] , Value , Comment

  • [3, 0] , 0xE1 , The magic number
  • [3, 1] , 0x10 , the NDEF Version number, major version 1, minor version 0.
  • [3, 2] , 0x06 , the user memory size of the tag / 8. In this case 6, since 6*8=48
  • [3, 3] , 0x00 , read/write allowed. 0x00 = write allowed, 0x0F = read only
  • [4, 0] , 0x03 , The T in the TLV, the type. In this case, an NDEF Message.
  • [4, 1] , 0x2E , The L in the TLV, the Length. In this case, the rest of the tag, 46 bytes.
  • [4, 2] , 0xD4 , Record MB_ME_CF_SR_IL_TNF. In this case, 11010100 (Is the first record, is the last record, is not a chunk, is a short message, no id in header, is of type "External Type")
  • [4, 3] , 0x03 , Record Type Length. In this case 3 (Type "abc" is 3 long)
  • [5, 0] , 0x28 , Payload Length, the rest of the tag. In this case 40.
  • [5, 1] , 0x61 , First byte of type, 0x61 = 97 = 'a'
  • [5, 2] , 0x61 , Second byte of type, 0x62 = 98 = 'b'
  • [5, 3] , 0x61 , Third byte of type, 0x63 = 99 = 'c'

  • The remaining 40 bytes of the tag, pages 6 to 11, are your payload.

If you just want to Initialise the tag so that the phone can read it and do the rest, just write the CC, and only the TLV with a L of zero and no V. (4,0 = 0x03 and 4,1 =0x00).

Ryan
  • 1,126
  • 11
  • 19
1

I had a similar problem, I bought pack of NFC tags on eBay, but they were not NDEF formatted. WP8 can utilize only NDEF formatted tags, so I had to find a way how to format them. I found on Twitter a guy with NFC equipped Android phone and he formatted these tags for me. Too bad that Windows Phone 8 cannot do this as well.

You can vote here on official WPdev Uservoice page for the low-level NFC API feature:
Provide low-level NFC API for NDEF formatting and (un)locking tags

Martin Suchan
  • 10,490
  • 3
  • 32
  • 63
  • If I use `SubscribeForMessage("Windows.something", handler); to subscribe every binary data, can I read it? http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.networking.proximity.proximitydevice.subscribeformessage.aspx – xhg May 13 '14 at 08:31