2016-12-28 329 views
1

我正在測試一個ACR35,並且我在提供的SDK中遇到此問題。ACR35:APDU命令選擇文件返回狀態6A 82(找不到文件)

我有具有以下文件結構的DESFire EV1卡:

[ Master File ] 
     | 
     |___ [ AID - F222222222 (Dedicated file) ] 
        | 
        |___ [ File id - 0001 (Elementary File) ] 

我已經驗證該文件結構確實存在與其他閱讀器(帶有集成NFC讀取器的Android設備)的卡上。

我用這個代碼選擇DF(由其AID):

public void powerOn(){ 
    if (mReader.piccPowerOn(timeout, cardType)) { 
     Log.i(TAG, "poweron true"); 
     byte[] test = ApduCommand.HexStringToByteArray("00A4040005F222222222"); 
     /*Transmit the command to the reader with timeout: 5 sec*/ 
     mReader.piccTransmit(timeout, test); 
    }else{ 
     Log.i(TAG, "poweron false"); 
     powerOn(); 
    } 
} 

而且我在等待這裏的響應:

/* Set the PICC response APDU callback. */ 
mReader.setOnPiccResponseApduAvailableListener(new AudioJackReader.OnPiccResponseApduAvailableListener() { 
    @Override 
    public void onPiccResponseApduAvailable(AudioJackReader reader, byte[] responseApdu) { 
     String resultHex = ApduCommand.ByteArrayToHexString(responseApdu); 
     Log.i(TAG, "APDU response ("+current_status+")" + resultHex); 

     if(resultHex.equals("9000")) { 
      if (current_status == STATUS_SELECT_AID) { 
       if (mReader.piccPowerOn(timeout, cardType)) { 
        Log.i(TAG, "selecting file"); 
        byte[] selFile = ApduCommand.HexStringToByteArray("00A40200020001"); 
        current_status = STATUS_SELECT_FILE; 
        mReader.piccTransmit(timeout, selFile); 
       } else { 
        Log.i(TAG, "timed out.."); 
       } 
      }else if(current_status == STATUS_SELECT_FILE) { 
       if (mReader.piccPowerOn(timeout, cardType)) { 
        Log.i(TAG, "reading binary data"); 
        byte[] readBinary = ApduCommand.HexStringToByteArray("00B0000000"); 
        current_status = STATUS_READ_DATA; 
        mReader.piccTransmit(timeout, readBinary); 
       } else { 
        Log.i(TAG, "timed out.."); 
       } 
      } 
     } 
    } 
}); 

在這裏,我得到一個成功狀態(90 00 )選擇DF,但在選擇文件時,我找到了文件未找到狀態(6A 82)。

登錄如下:

12-28 18:17:02.752 27298-28923/com.example.m1alesis.smartcardreader I/acrx: APDU response (0)9000 
12-28 18:17:02.752 27298-28923/com.example.m1alesis.smartcardreader I/acrx: selecting file 
12-28 18:17:03.412 27298-28949/com.example.m1alesis.smartcardreader I/acrx: APDU response (1)6A82 

使用相同的卡,並在Android NFC讀取器模式完全相同的APDU命令工作正常,我可以選擇該文件,但ACR35似乎並不喜歡多順序APDU命令。

Github的項目:https://github.com/rthapa/smartcardreader

+0

在嘗試選擇文件之前調用'piccPowerOn()'是否有原因?我不太確定這種方法的作用,但是如果它禁用並重新啓用電源,那麼DESFire應用程序可能不再被選中。 –

+1

@MichaelRoland就是這樣!它現在非常有意義。哇,我通過這些代碼像100次,無法弄清楚。謝謝,如果你發佈這個答案,我會接受它。這對未來的其他人可能有用。 – unknown

回答

0

不要叫mReader.piccPowerOn(timeout, cardType)發送的APDU之間。方法piccPowerOn()將使讀者重置DESFire卡。因此,當您執行SELECT(by FID)命令00 A4 0200 02 0001時,將不再選擇應用程序F222222222