我目前正在尝试将Arduino UNO和NFC Shield连接到运行Android 4.4的Nexus 4。
我有服务设置,它只是暂时记录。问题是,NFC意图并没有绑定到我的应用程序。调试器报告以下错误:
11-24 02:45:46.139 4006-4027/? E/BrcmNfcNfa﹕ UICC[0x0] is not activated
所以这是我的两个问题:
在Arduino方面,NFC屏蔽需要将哪种“消息”发送到我的手机才能让我的手机了解我正在寻找“其他”类别中的某个应用?< / p>
在android的方面,什么是帮助过滤器标签值来捕获这个意图?我可以自定义一个或者我是否需要遵守某种ISO规范才能使用它?
更新
好的,这是我构建APDU的Arduino草图的相关部分:
uint8_t message[5];
message[0] = 0x00;
message[1] = 0xA4;
message[2] = 0x04;
message[3] = 0x00;
message[4] = 0x08;
message[5] = 0x4C656C616E746F73ULL;
这是我的Android应用程序中的APDU服务XML文件:
<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>
这是我将手机悬停在NFC护罩上时的日志:
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
为什么Android没有将APDU路由到我的HCE服务?
答案 0 :(得分:4)
你意识到了
uint8_t message[5];
message[0] = 0x00;
message[1] = 0xA4;
message[2] = 0x04;
message[3] = 0x00;
message[4] = 0x08;
message[5] = 0x4C656C616E746F73ULL;
实际上会产生一个看起来像这样的数组吗?
uint8_t message[] = { 0x00, 0xA4, 0x04, 0x00, 0x08, 0x73 };
这意味着您的AID的其余部分(0x4C
,0x65
,0x6C
,0x61
,0x6E
,0x74
,{ {1}})被有效地切断和,因此您的APDU也有一个错误的长度(Lc)字段。
因此,您可能需要正确格式化SELECT APDU:
0x6F
此外,我建议您使用uint8_t message[] = {
0x00, /* CLA */
0xA4, /* INS */
0x04, /* P1 */
0x00, /* P2 */
0x08, /* Lc */
0x4C, 0x65, 0x6C, 0x61, 0x6E, 0x74, 0x6F, 0x73,
0x00 /* Le */ };
形式的AID(即第一个字节的高半字节设置为Fxxxxxxxxx...
,长度在5到16个字节之间),表示专有的,未注册的AID ,否则您可能会与其他标准应用程序发生冲突。有关正确格式化AID的详细信息,请参阅ISO / IEC 7816-4。
答案 1 :(得分:1)
这可以选择AID =“F0394148148100”,它在专有范围i内。即必须将第一个字节的第8-5位设置为“1”。然后是'F',然后在arudino的APDU中使用AID,如下所示。
private static byte[] AID={
(byte)0x00
, (byte)0xA4
, (byte)0x04
, (byte)0x00
, (byte)0x07
, (byte)0xF0, (byte)0x39, (byte)0x41, (byte)0x48, (byte)0x14, (byte)0x81, (byte)0x00
, (byte)0x00
};
然后在apduxml中使用此AID,如下所示
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/ServiceMe"
android:requireDeviceUnlock="false">
<aid-group android:description="@string/NfcService"
android:category="other">
<aid-filter android:name="F0394148148100"/>
</aid-group>
</host-apdu-service>
然后使用在应用程序清单的服务标签中定义的服务
public class MyHostApduService extends HostApduService
{
@Override
public void onDeactivated(int reason)
{
// TODO Auto-generated method stub
}
@Override
public byte[] processCommandApdu(byte[] commandApdu, Bundle extras)
{
// TODO Auto-generated method stub
String n1="Hi there this is working";
byte[] response=n1.getBytes();
System.err.println(response);
return response;
}
}
然后获取响应APDU并获取结果中的字符串。
答案 2 :(得分:0)
此处的示例(http://developer.android.com/guide/topics/connectivity/nfc/hce.html)开箱即用。