2
votes

I downloaded the android ACS library and was trying out the sample code and the ReaderTest app on my android device using the ACR122U reader with a otg cable.

I tried sending the following APDU command - FF CA 00 00 00 but i keep hitting this exception at the following line in the code snippet below:

                    // Transmit APDU
                    responseLength = mReader.transmit(params[0].slotNum,
                            command, command.length, response,
                            response.length);

the exception :

com.acs.smartcard.InvalidDeviceStateException: The current state is not equal to specific

I've checked to make sure that all elements being passed to the .transmit method are accurate (slotNum, command, command.length, etc). Just can't make out why that exception is being thrown.

Any help would be greatly appreciated !

2

2 Answers

8
votes

I managed to find the solution. This exception was thrown as there was a need to perform some initialization which i was not very well aware of. Found that example in a NFC library. The steps are detailed in the code snippet below:

private void initalizeCard() throws ReaderException {
    reader.power(0, Reader.CARD_WARM_RESET);
    reader.setProtocol(0, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1);

    byte[] sendBuffer={(byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00};
    byte[] recvBuffer=new byte[300];
    reader.transmit(0, sendBuffer, sendBuffer.length, recvBuffer, recvBuffer.length);
}
1
votes

you must do warm-reset--->set-protocol first and then you apdu command will got correct response.