无法验证 NTAG213 [英] Cannot authenticate NTAG213
问题描述
我正在使用 ACR122U NFC 阅读器对 NTAG213 NFC 标签进行密码保护.我想我已经设法正确设置了密码,但之后我无法进行身份验证和更改标签.我的身份验证代码如下所示:
I am using an ACR122U NFC reader to password protect an NTAG213 NFC label. I think I have managed to set the password correctly, but I cannot authenticate and change the label afterward. My code for authenticating looks like this:
#include <winscard.h>
#include <iostream>
#pragma comment(lib, "winscard.lib")
const char *ReaderName = "ACS ACR122 0";
unsigned Password = 0x12345678;
int main()
{
//Establish context
SCARDCONTEXT hContext;
DWORD SCard_Status1 = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &hContext);
if(SCard_Status1 != SCARD_S_SUCCESS)
return 1;
//connect to the card
SCARDHANDLE hCardHandle;
DWORD Protocol;
DWORD SCard_Status2 = SCardConnect(hContext, ReaderName, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T1, &hCardHandle, &Protocol);
if(SCard_Status2 != SCARD_S_SUCCESS)
{
SCardReleaseContext(hContext);
return 1;
}
SCARD_IO_REQUEST Request;
Request.dwProtocol = Protocol;
Request.cbPciLength = sizeof(SCARD_IO_REQUEST);
BYTE TxData[] =
{
0xFF, //CLA
0x00, //INS
0x00, //P1
0x00, //P2
0x08, //LC
0xD4,
0x40,
0x01,
0x1B, //PWD_AUTH (See data sheet)
Password,
Password >> 8,
Password >> 16,
Password >> 24,
};
BYTE RxData[254];
unsigned long RxLength = sizeof(RxData);
DWORD SCard_Status3 = SCardTransmit(hCardHandle, &Request, TxData, sizeof(TxData), NULL, RxData, &RxLength);
std::cout << "SCard_Status = " << SCard_Status3 << std::endl;
std::cout << "RxLength = " << RxLength << std::endl;
SCardDisconnect(hCardHandle, SCARD_EJECT_CARD);
SCardReleaseContext(hContext);
return 0;
}
这应该将 PWD_AUTH 命令发送到带有密码的 NTAG213.如果密码错误,我预计会收到一个错误,如果密码正确,我希望收到 PACK 的两个字节.但是 SCard_Status 是 SCARD_S_SUCCESS 并且 RxLength 之后是 0.如果我尝试写入标签,则会出现错误.
This should send the PWD_AUTH command to the NTAG213 with the Pwd. I expected to receive an error if the password is wrong or two bytes with the PACK if the password is correct. But SCard_Status is SCARD_S_SUCCESS and RxLength is 0 afterwards. And if I try to write to the label I get an error.
我找不到任何说明如何执行此操作的示例.谁能看到我做错了什么?
I am having trouble finding any examples showing how to do this. Can anyone see what I am doing wrong?
推荐答案
我要自己回答这个问题.我设法通过将 TxData 更改为以下内容来使其工作:
I am going to answer this myself. I managed to make it work by changing TxData to this:
BYTE TxData[] =
{
0xFF, //CLA
0x00, //INS
0x00, //P1
0x00, //P2
0x07, //LC
0xD4, 0x42, //InCommunicateThru
0x1B, //PWD_AUTH (See data sheet)
Password,
Password >> 8,
Password >> 16,
Password >> 24,
};
我在 ACR122U 内的 NFC 处理器 PN532 的数据表中找到了命令 InCommunicateThru (D4 42) 作为 InDataExchange (D4 40) 的替代品.
I found the command InCommunicateThru (D4 42) as a replacement for InDataExchange (D4 40) in the data sheet for the PN532, which is the NFC processor inside the ACR122U.
这篇关于无法验证 NTAG213的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!