我正在使用NFC标签类型2.当调用运行Broadcom NFC Android堆栈的transceive()函数时,我遇到了1字节ACK / NACK响应的问题。恩智浦NFC Android堆栈不会发生此问题。例如,写命令的ACK响应被定义为0xAh(根据NFC论坛标签类型2协议)。如果NFC标签回复其他内容而不是0xAh,则Broadcom NFC堆栈会将其视为NACK。此问题在NXP NFC堆栈中不会发生。
Broadcom NFC堆栈
在/platform/packages/apps/Nfc/nci/jni/NativeNfcTag.cpp
在函数“nativeNfcTag_doTransceive()”第890行
static jbyteArray nativeNfcTag_doTransceive (JNIEnv* e, jobject, jbyteArray data, jboolean raw, jintArray statusTargetLost)
{
..
..
if ((natTag.getProtocol () == NFA_PROTOCOL_T2T) &&
natTag.isT2tNackResponse (sTransceiveData, sTransceiveDataLen))
{
isNack = true;
}
if (sTransceiveDataLen)
{
if (!isNack) {
// marshall data to java for return
result.reset(e->NewByteArray(sTransceiveDataLen));
if (result.get() != NULL) {
e->SetByteArrayRegion(result.get(), 0, sTransceiveDataLen, (jbyte *) sTransceiveData);
}
else
ALOGE ("%s: Failed to allocate java byte array", __FUNCTION__);
} // else a nack is treated as a transceive failure to the upper layers
free (sTransceiveData);
sTransceiveData = NULL;
sTransceiveDataLen = 0;
}
..
..
}
当我们在/platform/packages/apps/Nfc/nci/jni/NfcTag.cpp第1212行查看函数isT2tNackResponse()时
bool NfcTag::isT2tNackResponse (const UINT8* response, UINT32 responseLen)
{
static const char fn [] = "NfcTag::isT2tNackResponse";
bool isNack = false;
if (responseLen == 1)
{
if (response[0] == 0xA) // line 1212: T2tNackResponse always returns NACK if the first byte is NOT 0xA
isNack = false; //an ACK response, so definitely not a NACK
else
isNack = true; //assume every value is a NACK
}
ALOGD ("%s: return %u", fn, isNack);
return isNack;
}
恩智浦NFC堆栈
恩智浦NFC堆栈中的相同功能
在/platform/packages/apps/Nfc/nxp/jni/com_android_nfc_NativeNfcTag.cpp
在函数“com_android_nfc_NativeNfcTag_doTransceive()”第853行
static jbyteArray com_android_nfc_NativeNfcTag_doTransceive(JNIEnv *e,
jobject o, jbyteArray data, jboolean raw, jintArray statusTargetLost)
{
..
..
/* Copy results back to Java *
* In case of NfcA and raw, also check the CRC in the response
* and cut it off in the returned data.
*/
if ((nfc_jni_transceive_buffer->length > 2) && checkResponseCrc) { // line 853
if (crc_valid(nfc_jni_transceive_buffer->buffer, nfc_jni_transceive_buffer->length)) {
result = e->NewByteArray(nfc_jni_transceive_buffer->length - 2);
if (result != NULL) {
e->SetByteArrayRegion(result, 0,
nfc_jni_transceive_buffer->length - 2,
(jbyte *)nfc_jni_transceive_buffer->buffer);
}
}
} else {
result = e->NewByteArray(nfc_jni_transceive_buffer->length);
if (result != NULL) {
e->SetByteArrayRegion(result, 0,
nfc_jni_transceive_buffer->length,
(jbyte *)nfc_jni_transceive_buffer->buffer);
}
}
..
..
}
在恩智浦NFC堆栈中,所有内容都转发到Java并返回到transceive()函数。
任何帮助/评论将不胜感激。谢谢。
答案 0 :(得分:2)
这是一个已知问题。问题实际上是NFC论坛NCI标准,Broadcom堆栈基于该标准。 NCI标准中的协议消息不区分4比特ACK / NAK响应和1字节的正常响应(+ CRC,其被剥离)。两者都由单个字节表示。 Broadcom堆栈(必须)将它们解释为ACK / NAK。希望这很快就会在标准和软件堆栈的更新中修复。
答案 1 :(得分:0)
这仅适用于NFC论坛标签类型2吗?在代码中,似乎其他标记类型不受此影响。标签类型3,4和NfcV的1字节原始数据不会被过滤。我没有按照NFC论坛的讨论。我们需要区分4位响应和1字节数据的主要原因是什么?