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.
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):
Regarding NFC tags NDEF formating:
Sincerely,
-- Justin Angel
Principal Engineer for Windows Phone Developer Experience at Nokia
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...
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:
The tag is formatted like so: (reference - www.nfc-forum.org/specs/spec_list/#tagtypes)
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
[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).
链接地址: http://www.djcxy.com/p/88606.html