public JavaCardApplet() { _masterFile = new DedicatedFile(new FileSystem(Constants.FILESYSTEM_SIZE, Constants.DF_MAX, Constants.EF_MAX)); _masterFile.Setup(null, 0, Constants.FILESYSTEM_SIZE, Constants.MF_HEADER, 0, (short)Constants.MF_HEADER.Length); _headerParser = new HeaderParser(); _currentDF = _masterFile; _currentEF = null; // Initialize structure for TB100 _masterFile.CreateElementaryFile(0x0000, 0x0006, new byte[] { 0x17, 0xFF, 0x06, 0xE4 }, 0x0000, 0x0004); _masterFile.CreateElementaryFile(0x0006, 0x0005, new byte[] { 0x1F, 0x6C, 0x05, 0x70 }, 0x0000, 0x0004); _masterFile.CreateElementaryFile(0x000B, 0x0005, new byte[] { 0x0E, 0x2F, 0xF5, 0xCE }, 0x0000, 0x0004); _masterFile.CreateElementaryFile(0x0010, 0x0003, new byte[] { 0x0E, 0x10, 0x03, 0xDF }, 0x0000, 0x0004); _masterFile.CreateDedicatedFile(0x0013, 0x0022, new byte[] { 0x7F, 0x00, 0x00, 0x22, 0xFF, 0xFF, 0xFE, 0x62 }, 0x0000, 0x0008); ElementaryFile ef0E2F = (ElementaryFile)_masterFile.FindFileByFileId(0x0E2F); ef0E2F.Write(new byte[] { 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30 }, 0, 0x0002, 2); ElementaryFile ef0E10 = (ElementaryFile)_masterFile.FindFileByFileId(0x0E10); ef0E10.Write(new byte[] { 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30 }, 0, 0x0000, 2); DedicatedFile df7F00 = (DedicatedFile)_masterFile.FindFileByFileId(0x7F00); df7F00.CreateElementaryFile(0x0000, 0x0010, new byte[] { 0x6F, 0x01, 0x00, 0x10, 0xFF, 0xFF, 0xFF, 0x83 }, 0, 0x0008); }
/// <summary> /// Process CREATE FILE instruction (E0) /// <para> /// C-APDU: <code>00 E0 {offset} {Lc} {header}</code> /// </para> /// <list type="table"> /// <item> /// <term>offset</term> /// <description>offset of first word of the file coded by P1 P2 (WORDS).</description> /// </item> /// <item> /// <term>header</term> /// <description>header of the new file, must be word aligned.</description> /// </item> /// </list> /// </summary> /// <param name="apdu"></param> /// <returns></returns> private IFakeCardFeedback ProcessCreateFile(CommandAPDU apdu) { byte[] buffer = apdu.GetBuffer(); apdu.SetIncomingAndReceive(); short headerOffset = APDUHelpers.getOffsetCdata(apdu); short headerLength = APDUHelpers.getIncomingLength(apdu); if (headerLength < 4) { ISOException.throwIt(JavaCard.ISO7816.SW_DATA_INVALID); } short offset = Util.getShort(buffer, JavaCard.ISO7816.OFFSET_P1); if (!_headerParser.Parse(buffer, headerOffset, (short)(headerOffset + headerLength))) { ISOException.throwIt(JavaCard.ISO7816.SW_DATA_INVALID); } short size = (short)(_headerParser.bodyLength + (short)(_headerParser.headerLength >> 2)); File file = null; switch (_headerParser.fileType) { case HeaderParser.FILETYPE_DF: file = _currentDF.CreateDedicatedFile(offset, size, buffer, headerOffset, headerLength); break; case HeaderParser.FILETYPE_EFSZ: case HeaderParser.FILETYPE_EFWZ: file = _currentDF.CreateElementaryFile(offset, size, buffer, headerOffset, headerLength); break; default: ISOException.throwIt(JavaCard.ISO7816.SW_CONDITIONS_NOT_SATISFIED); break; } if (file == null) { ISOException.throwIt(JavaCard.ISO7816.SW_DATA_INVALID); } return(apdu.SetOutgoingAndSend(0, 0)); }