private void processSelectFile(APDU apdu) {
        byte[] buffer = apdu.getBuffer();
        byte p1 = buffer[OFFSET_P1];
        byte p2 = buffer[OFFSET_P2];
        if(p1 != (byte)0x02 || p2 != (byte)0x0C) {
            ISOException.throwIt(SW_INCORRECT_P1P2);
        }
        short lc = (short) (buffer[OFFSET_LC] & 0x00FF);

        if (lc != 2)
            ISOException.throwIt(SW_WRONG_LENGTH);

        if (apdu.getCurrentState() == APDU.STATE_INITIAL) {
            apdu.setIncomingAndReceive();
        }
        if (apdu.getCurrentState() < APDU.STATE_FULL_INCOMING) {
            // need all data in one APDU.
            ISOException.throwIt(SW_INTERNAL_ERROR);
        }

        short fid = Util.getShort(buffer, OFFSET_CDATA);

        if (fileSystem.getFile(fid) != null) {
            selectedFile = fid;
            volatileState[0] |= FILE_SELECTED;
            return;
        }
        setNoFileSelected();
        ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
    }