private void processCreateFile(APDU apdu) {
        if (isLocked()) {
            ISOException.throwIt(SW_CONDITIONS_NOT_SATISFIED);
        }

        byte[] buffer = apdu.getBuffer();
        
        short lc = (short) (buffer[OFFSET_LC] & 0xff);
        boolean eapProtection = (buffer[OFFSET_P1] != (byte)0x00);
        
        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);
        }

        if (lc < (short) 6 || (buffer[OFFSET_CDATA + 1] & 0xff) < 4)
            ISOException.throwIt(SW_WRONG_LENGTH);

        if (buffer[OFFSET_CDATA] != 0x63)
            ISOException.throwIt(SW_DATA_INVALID);

        short size = Util.makeShort(buffer[(short) (OFFSET_CDATA + 2)],
                buffer[(short) (OFFSET_CDATA + 3)]);

        short fid = Util.makeShort(buffer[(short) (OFFSET_CDATA + 4)],
                buffer[(short) (OFFSET_CDATA + 5)]);

        fileSystem.createFile(fid, size, eapProtection);
    }