简体   繁体   English

具有固定UID的Android NFC卡仿真

[英]Android NFC Card emulation with fixed UID

I've downloaded NFC parts from AOSP and I'm looking for the method used by Android to generate the random UID used by card emulation. 我从AOSP下载了NFC部件,我正在寻找Android使用的方法来生成卡仿真使用的随机UID。 My goal is to fix the UID instead of having a different one each time there is a communication with the target. 我的目标是在每次与目标进行通信时修复UID而不是使用不同的UID。 I found inside "libnfc-nci" module the file "nfa_ce_act.c" containing this: 我在“libnfc-nci”模块中找到了包含以下内容的文件“nfa_ce_act.c”:

void nfa_ce_t3t_generate_rand_nfcid (UINT8 nfcid2[NCI_RF_F_UID_LEN])
{
UINT32 rand_seed = GKI_get_tick_count ();

/* For Type-3 tag, nfcid2 starts witn 02:fe */
nfcid2[0] = 0x02;
nfcid2[1] = 0xFE;

/* The remaining 6 bytes are random */
nfcid2[2] = (UINT8) (rand_seed & 0xFF);
nfcid2[3] = (UINT8) (rand_seed>>8 & 0xFF);
rand_seed>>=(rand_seed&3);
nfcid2[4] = (UINT8) (rand_seed & 0xFF);
nfcid2[5] = (UINT8) (rand_seed>>8 & 0xFF);
rand_seed>>=(rand_seed&3);
nfcid2[6] = (UINT8) (rand_seed & 0xFF);
nfcid2[7] = (UINT8) (rand_seed>>8 & 0xFF);
}

This method generate an UID for FeliCa tags. 此方法为FeliCa标记生成UID。 I'm not able to find the one for ISO14443 cards (MIFARE) which generate an UID beginning with 0x08 by default. 我无法找到ISO14443卡(MIFARE)的卡,它默认生成一个以0x08开头的UID。 According to Martijn Coenen, as explained in his G+ Post, it's something possible. 根据Martijn Coenen的说法,正如他在G + Post中所解释的那样,这是可能的。

Sorry, I realize many people wanted this, but it's not possible in the official version. 对不起,我意识到很多人都想要这个,但在正式版中是不可能的。 (You could of course do it with some AOSP hacking). (你当然可以通过一些AOSP黑客来做)。 The reason is that HCE is designed around background operation. 原因是HCE是围绕后台操作设计的。 If we allow apps to set the UID, every app possibly wants to set their own UID, and there's no way to resolve the conflict. 如果我们允许应用程序设置UID,则每个应用程序都可能想要设置自己的UID,并且无法解决冲突。 We hope that with HCE, NFC infrastructure will move to higher levels of the protocol stack to do authentication instead of relying on the UID (which is easily cloned anyway). 我们希望通过HCE,NFC基础设施将转移到更高级别的协议栈进行身份验证,而不是依赖于UID(无论如何都很容易克隆)。 https://plus.google.com/+MartijnCoenen/posts/iX6LLoQmZLZ https://plus.google.com/+MartijnCoenen/posts/iX6LLoQmZLZ

Is anyone know how to achieve it? 有谁知道如何实现它?

Thanks 谢谢

One important thing to know is that the UID transfered at a very low level of the nfc protocol. 需要知道的一件重要事情是UID转换到nfc协议的非常低的水平。 This means that it is done independently by the nfc firmware and not within the android operating system. 这意味着它由nfc固件独立完成,而不是在Android操作系统中完成。 We had the same problem in our NFCGate project and found a solution for Broadcom BCM20793 chips like the ones in the Nexus4/5 and others by writing the UID with NFC_SetConfig directly into the chip firmware. 我们在NFCGate项目中遇到了同样的问题,并通过将UID与NFC_SetConfig直接写入芯片固件,找到了与Nexus4 / 5和其他芯片类似的Broadcom BCM20793芯片的解决方案。

You can see a working version in our repository on github . 您可以在github上的我们的存储库中看到一个可用的版本。 Here is a non-tested version to show the principle: 这是一个未经测试的版本,以显示原理:

uint8_t cfg[] = {
    CFG_TYPE_UID, // config type
    3,            // uid length
    0x0A,         // uid byte 1
    0x0B,         // uid byte 2
    0x0C          // uid byte 3
};
NFC_SetConfig(sizeof(cfg), cfg);

Our tests revealed that android sometimes sets the UID back to random (length=0 if I recall correctly), so you need to find a good place to set it when you need it or do something similar as we did and intercept NFC_SetConfig calls from android to re-set our own UID. 我们的测试显示android有时会将UID设置为随机(如果我没记错的话,长度= 0),所以你需要找到一个好的地方来设置它,当你需要它或做类似我们做的事情并拦截来自android的NFC_SetConfig调用重新设置我们自己的UID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM