在Windows 10桌面上初始化NDEF标签 [英] Initialize a NDEF tag on Windows 10 Desktop
问题描述
我正在尝试将新的Mifare Classic标签初始化为DNEF格式,并可以由Proximity API读取.
I'm trying to initialize a new Mifare Classic Tag to the DNEF format, readable by the Proximity API.
根据Microsoft,如果需要,接近度API可以将mifare经典标签初始化为NDEF格式(如此处).
According to Microsoft, the proximity API is capable to initialize a mifare classic tag to a NDEF format if needed (as described here and here).
但是,使用以下代码行发布消息:
But, using this line of code to publish the message:
proximityDevice.PublishBinaryMessage("NDEF:WriteTag", ndef.ToByteArray().AsBuffer(), MessageTransmittedHandler);
不要初始化TAG并写任何东西,只能在预先格式化的NDEF标签上工作(例如,由Android Phone完成).
don't initialize the TAG and write anything, just works on a pre-formatted NDEF tag (done by an Android Phone, for example).
有什么方法可以将台式机家族中的TAG初始化为NDEF格式,作为NFC读/写器的感应设备? (NXP NearFieldProximity提供程序)
There are any way to initialize the TAG to a NDEF format on the Desktop familly, being the NFC reader/writer a proximity device? (NXP NearFieldProximity Provider)
更新:
我从 Onovotny 找到了一个适用于.NET的MIRAFE API,并通过所有低级操作来发送APDU数据Mifare卡,支持我正在使用的WinRT SmartCard框架.
I found a MIRAFE API for .NET from Onovotny with all low level operations to send the APDU data to Mifare Cards, supporting the WinRT SmartCard framework that I'm using.
现在,问题在于尝试登录卡时发生的任何数据操作(getData或setData),产生了此异常:
The problem now consists on any data operations (getData or setData) when tries to login the card, producing this Exception:
"The smart card has been reset, so any shared state information is invalid. (Exception from HRESULT: 0x80100068)"
我可以获取卡标识,并且该卡在Android设备上发生了晃动.我还尝试将KeyA更改为{0x00,0x00,0x00,0x00,0x00,0x00},{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}和{0xA0,0xA1,0xA2,0xA3,0xA4,0xA5}结果是一样的.
I can get the card identification and the card is writabble on Android devices. I also tried to change the KeyA to {0x00,0x00,0x00,0x00,0x00,0x00}, { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF} and {0xA0,0xA1,0xA2,0xA3,0xA4,0xA5} but the results are the same.
推荐答案
只需在名为的services.msc上启动Windows服务即可. 智能卡设备枚举服务" ,这样我就可以向智能卡中写入数据/从智能卡中读取数据.
Just started a Windows Service at services.msc called "Smart Card Device Enumeration Service", and I could be able to write/read data to/from SmartCards.
关于NDEF格式,我将MAD数据插入到扇区0的块1和2.然后,将NDEF记录添加到扇区1的块0..2.然后,我更新了MAD和NDEF扇区的密钥A和密钥B,如下所示:
About the NDEF formatting, I inserted MAD data on sector 0, block 1 and 2. After that, added the NDEF records on sector 1, block 0..2. Then, I updated the Key A and Key B of MAD and NDEF sectors like this:
手动填充MAD和2条NDEF记录:
Filling MAD and 2 NDEF records manually:
//Atualiza KeyB
mifareCard.AddOrUpdateSectorKeySet(new SectorKeySet {
Key = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
KeyType = KeyType.KeyB,
Sector = 0
});
//Seta dados do MAD
await mifareCard.SetData(0, 1, new byte[] { 0x14, 0x01, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1 });
await mifareCard.SetData(0, 2, new byte[] { 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1 });
mifareCard.AddOrUpdateSectorKeySet(new SectorKeySet {
Key = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
KeyType = KeyType.KeyB,
Sector = 1
});
//Incluis dois records NDEF
await mifareCard.SetData(1, 0, new byte[] { 0x00, 0x00, 0x03, 0x11, 0xD1, 0x01, 0x0D, 0x55, 0x01, 0x61, 0x64, 0x61, 0x66, 0x72, 0x75, 0x69 });
await mifareCard.SetData(1, 1, new byte[] { 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
await mifareCard.Flush();
更新NDEF记录的密钥:
Updating keys for NDEF records:
//Get MAD sector
var setor = mifareCard.GetSector(0);
//Get Trail data
await setor.GetData(3);
//Update chaves. Acess bits are generated by Mirafe API
await setor.FlushTrailer(
Extensions.ByteArrayToString(new byte[] { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }),
Extensions.ByteArrayToString(new byte[] { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }
));
//Set others sectors keys for NDEF
for (var sector = 1; sector < 16; sector++) {
try {
setor = mifareCard.GetSector(sector);
await setor.GetData(3);
await setor.FlushTrailer(
Extensions.ByteArrayToString(new byte[] { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }),
Extensions.ByteArrayToString(new byte[] { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }
));
} catch (Exception ex) {
Debug.Write(ex.Message + "\n");
}
}
这篇关于在Windows 10桌面上初始化NDEF标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!