选择AID时,Android NFC / HCE服务返回0x6F00(无精确诊断)

时间:2014-09-26 20:45:22

标签: android nfc hce

我创建了一个AID为F0123412349999的HCE服务。根据Android HCE文档,我需要发送SELECT APDU,以便HCE服务知道将以下消息重定向到哪个服务。这是我成功连接时发送到手机的APDU:

{ 0x00, //CLA 
  0xA4, //INS
  0x00, //P1 
  0x07, //P2
  0x07, //Lc Length Content
  0xF0, //Data (AID)
  0x12, 
  0x34, 
  0x12,
  0x34, 
  0x99, 
  0x99, 
  0x00  //Length of data expected
};

传输成功,但我做的Android手机返回0x6f00。这被翻译为" No Precise Diagnosis"。我不知道出了什么问题,显然错误信息有些模糊。以下代码是我的HCE服务:

public class MyHostApduService extends HostApduService {

    @Override
    public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
        Log.i("HCE service", "processCommandApdu");

            byte[] answer = new byte[2];
            answer[0] = (byte) 0x90;
            answer[1] = (byte) 0x00;
        return answer;
    }

    @Override
    public void onDeactivated(int reason) {
        Log.i("HCE service", "Deactivated: " + reason);
    }

    @Override
    public void onCreate() {
        Log.i("HCE service", "Created");
    }
}

和AID注册:

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/app_name"
    android:requireDeviceUnlock="false" >

    <aid-group
        android:category="other"
        android:description="@string/app_name" >
        <aid-filter android:name="F0123412349999" />
        <aid-filter android:name="F0394148148100" />
    </aid-group>
</host-apdu-service>

清单注册:

   <service
            android:name=".MyHostApduService"
            android:exported="true"
            android:permission="android.permission.BIND_NFC_SERVICE" >
            <intent-filter>
                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
            </intent-filter>

            <meta-data
                android:name="android.nfc.cardemulation.host_apdu_service"
                android:resource="@xml/apduservice" />
        </service>

我用来阅读Android手机的读者是ACR122阅读器。手机是HTC One。让我感到奇怪的一件事是手机发送的ATR与读卡器发送的是0x3B80800101。我虽然这会更大并且包含更多信息,但我可能错了。

我可以更改/修复什么来让Android将我的消息发送到我的HCE服务?

1 个答案:

答案 0 :(得分:2)

您要发送到手机的SELECT APDU中参数P1和P2的值可能无效。 请尝试以下方法:

P1 = 0x04

P2 = 0x00

您可以在由行业协会Global Platform发布的名为“Card Specification”的文档中检查SELECT命令的所有参数。

相关问题