设置主卡仿真 [英] Setting up host card emulation

查看:304
本文介绍了设置主卡仿真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试一个Arduino UNO与NFC盾之间的连接到我的Nexus 4运行Android 4.4。

我有服务的设置,它只是在瞬间记录。问题在于,NFC的意图没有得到绑定到我的应用程序。调试器报告以下错误:

  2月11日至24日:45:46.139 4006-4027 /? E / BrcmNfcNfa:UICC [为0x0]未激活

因此​​,这里是我的2个问题:


  • 在事物的Arduino的一面,并在NFC盾需要发送到我的手机我的手机要明白,我是在分类'其他'找某应用什么样的消息<? / p>


  • 在事物的android的一面,会是怎样的援助过滤器标签值赶上那意图是什么?我可以做一个自定义一个或做我需要坚持某种ISO规范的这个工作?


更新

行,所以这里是我的Arduino草图的相关部分,我建我的APDU:

  uint8_t有消息[5];            消息[0] = 0×00;
            消息[1] = 0xA4;
            消息[2] = 0×04;
            消息[3] = 0×00;
            消息[4​​] = 0×08;
            消息[5] = 0x4C656C616E746F73ULL;

这是在我的Andr​​oid应用程序的APDU服务XML文件:

 &LT;主机-APDU服务的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:说明=@字符串/ servicedesc
    机器人:requireDeviceUnlock =假&GT;
    &LT;援助团的android:说明=@字符串/ aiddescription
        机器人:类=其他&GT;
        &LT;辅助过滤器的android:NAME =4C656C616E746F73/&GT;
    &LT; /援助组&gt;
&LT; /主机-APDU服务&GT;

这是日志我得到的,当我悬停我的手机在NFC盾:

  11-24 22:33:40.563 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件=为0x18
11-24 22:33:40.563 4006-4027 /? D / HostEmulationManager:notifyHostEmulationActivated
11-24 22:33:40.563 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件= 0x17已
11-24 22:33:40.563 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:NFA_CE_DATA_EVT; H = 0x302;数据LEN = 5
11-24 22:33:40.563 4006-4027 /? D / HostEmulationManager:notifyHostEmulationData
11-24 22:33:40.563 4006-4027 /? D / HostEmulationManager:删除非选择APDU在STATE_W4_SELECT
11-24 22:33:40.683 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件= 0x17已
11-24 22:33:40.683 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:NFA_CE_DATA_EVT; H = 0x302;数据LEN = 5
11-24 22:33:40.683 4006-4027 /? D / HostEmulationManager:notifyHostEmulationData
11-24 22:33:40.683 4006-4027 /? D / HostEmulationManager:删除非选择APDU在STATE_W4_SELECT
11-24 22:33:40.804 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件= 0x17已
11-24 22:33:40.804 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:NFA_CE_DATA_EVT; H = 0x302;数据LEN = 5
11-24 22:33:40.804 4006-4027 /? D / HostEmulationManager:notifyHostEmulationData
11-24 22:33:40.804 4006-4027 /? D / HostEmulationManager:删除非选择APDU在STATE_W4_SELECT
11-24 22:33:40.924 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件= 0x17已
11-24 22:33:40.924 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:NFA_CE_DATA_EVT; H = 0x302;数据LEN = 5
11-24 22:33:40.934 4006-4027 /? D / HostEmulationManager:notifyHostEmulationData
11-24 22:33:40.934 4006-4027 /? D / HostEmulationManager:删除非选择APDU在STATE_W4_SELECT
11-24 22:33:41.054 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件= 0x17已
11-24 22:33:41.054 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:NFA_CE_DATA_EVT; H = 0x302;数据LEN = 5
11-24 22:33:41.054 4006-4027 /? D / HostEmulationManager:notifyHostEmulationData
11-24 22:33:41.054 4006-4027 /? D / HostEmulationManager:删除非选择APDU在STATE_W4_SELECT
11-24 22:33:41.174 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件= 0x17已
11-24 22:33:41.174 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:NFA_CE_DATA_EVT; H = 0x302;数据LEN = 5
11-24 22:33:41.174 4006-4027 /? D / HostEmulationManager:notifyHostEmulationData
11-24 22:33:41.174 4006-4027 /? D / HostEmulationManager:删除非选择APDU在STATE_W4_SELECT
11-24 22:33:41.304 4006-4027 /? D / BrcmNfcJni:RoutingManager :: stackCallback:事件=的0x19
11-24 22:33:41.304 4006-4027 /? D / HostEmulationManager:notifyHostEmulationDeactivated
11-24 22:33:41.304 4006-4027 /? E / BrcmNfcNfa:UICC [为0x0]未激活

为什么Android是不是路由APDU我HCE服务?


解决方案

您知不知道

  uint8_t有消息[5];消息[0] = 0×00;
消息[1] = 0xA4;
消息[2] = 0×04;
消息[3] = 0×00;
消息[4​​] = 0×08;
消息[5] = 0x4C656C616E746F73ULL;

实际上会导致一个数组,看起来像这样?

  uint8_t有消息[] = {0×00,0xA4,0x04的0x00时,0x08的(0x73)的};

这意味着你的援助的剩余部分( 0x4C 0x65 0x6C 0x61 0x6E 0x74 0x6F )的有效切断您因此APDU也有一个错误的长度(LC)字段。

所以,你可能要正确格式化SELECT APDU:

  uint8_t有消息[] = {
    为0x00,/ * CLA * /
    0xA4,/ * INS * /
    0×04,/ * * P1 /
    为0x00,/ * P2 * /
    0×08,/ * LC * /
    0x4C,0x65,0x6C,0x61,0x6E,0x74,0x6F(0x73)的,
    为0x00 / *乐* /};

此外,我建议你使用表单的AID Fxxxxxxxxx ... (即设置为第一个字节的高四位 0xF的,表示一个专有的,未注册的AID,否则你可能会和其他标准的应用程序发生冲突5和16字节之间的长度)。见ISO / IEC 7816-4的更多信息,正确格式化辅助。

I am currently attempting to connect between an Arduino UNO with NFC Shield to my Nexus 4 running Android 4.4.

I have the service setup, it's simply logging at the moment. Problem is, the NFC intent doesn't get bound to my app. The debugger reports the following error:

11-24 02:45:46.139    4006-4027/? E/BrcmNfcNfa﹕ UICC[0x0] is not activated

So here's my 2 questions:

  • On the Arduino side of things, what kind of 'message' does the NFC shield needs to send to my phone for my phone to understand that I'm looking for a certain app in category 'Other'?

  • On the android side of things, what will be the aid-filter tag value to catch that intent? Can I make up a custom one or do I need to stick to some kind of ISO specification for this to work?

UPDATE

OK so here's the relevant part of my Arduino sketch where I build my APDU:

            uint8_t message[5];

            message[0] = 0x00;
            message[1] = 0xA4;
            message[2] = 0x04;
            message[3] = 0x00;
            message[4] = 0x08;              
            message[5] = 0x4C656C616E746F73ULL;

And here's the APDU service XML file in my android app:

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/servicedesc"
    android:requireDeviceUnlock="false">
    <aid-group android:description="@string/aiddescription"
        android:category="other">
        <aid-filter android:name="4C656C616E746F73"/>
    </aid-group>
</host-apdu-service>

And this is the log I get when I hover my phone over the NFC shield:

11-24 22:33:40.563    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x18
11-24 22:33:40.563    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationActivated
11-24 22:33:40.563    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17
11-24 22:33:40.563    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5
11-24 22:33:40.563    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData
11-24 22:33:40.563    4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT
11-24 22:33:40.683    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17
11-24 22:33:40.683    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5
11-24 22:33:40.683    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData
11-24 22:33:40.683    4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT
11-24 22:33:40.804    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17
11-24 22:33:40.804    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5
11-24 22:33:40.804    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData
11-24 22:33:40.804    4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT
11-24 22:33:40.924    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17
11-24 22:33:40.924    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5
11-24 22:33:40.934    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData
11-24 22:33:40.934    4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT
11-24 22:33:41.054    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17
11-24 22:33:41.054    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5
11-24 22:33:41.054    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData
11-24 22:33:41.054    4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT
11-24 22:33:41.174    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x17
11-24 22:33:41.174    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: NFA_CE_DATA_EVT; h=0x302; data len=5
11-24 22:33:41.174    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationData
11-24 22:33:41.174    4006-4027/? D/HostEmulationManager﹕ Dropping non-select APDU in STATE_W4_SELECT
11-24 22:33:41.304    4006-4027/? D/BrcmNfcJni﹕ RoutingManager::stackCallback: event=0x19
11-24 22:33:41.304    4006-4027/? D/HostEmulationManager﹕ notifyHostEmulationDeactivated
11-24 22:33:41.304    4006-4027/? E/BrcmNfcNfa﹕ UICC[0x0] is not activated

How come Android isn't routing the APDU to my HCE Service?

解决方案

You do realize that

uint8_t message[5];

message[0] = 0x00;
message[1] = 0xA4;
message[2] = 0x04;
message[3] = 0x00;
message[4] = 0x08;              
message[5] = 0x4C656C616E746F73ULL;

will actually result in an array that looks like this?

uint8_t message[] = { 0x00, 0xA4, 0x04, 0x00, 0x08, 0x73 };

Which means that the remaining parts of your AID (0x4C, 0x65, 0x6C, 0x61, 0x6E, 0x74, 0x6F) are effectively cut off and consequently your APDU also has a wrong length (Lc) field.

So you may want to properly format the SELECT APDU:

uint8_t message[] = {
    0x00, /* CLA */
    0xA4, /* INS */
    0x04, /* P1  */
    0x00, /* P2  */
    0x08, /* Lc  */
    0x4C, 0x65, 0x6C, 0x61, 0x6E, 0x74, 0x6F, 0x73,
    0x00  /* Le  */ };

Moreover, I suggest that you use an AID of the form Fxxxxxxxxx... (i.e. the upper nibble of the first byte set to 0xF, length between 5 and 16 bytes) indicating a proprietary, unregistered AID, otherwise you might collide with other standard applications. See ISO/IEC 7816-4 for more information on properly formatting AIDs.

这篇关于设置主卡仿真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆