/// <summary> /// Reads the file pointed by the SFI found in the FCI of the application. /// </summary> /// <returns>Last status word.</returns> public UInt16 ReadDataFile(AflEntry file) { for (var recordNumber = file.FirstRecord; recordNumber <= file.LastRecord; recordNumber++) { CommandAPDU cAPDU = new EMVReadRecordCommand(recordNumber, file.Sfi, 0); var crp = new CommandResponsePair(cAPDU); crp.Transmit(_cardChannel); if (crp.RApdu.StatusWord == 0x9000) { var tlv = new TlvData(crp.RApdu.Udr); if (tlv.Tag != 0x70) { throw new Exception(String.Format("EMVApplication.readData(): record is not TLV-coded with tag 70 [{0}]", tlv)); } // Store data in list _tlvRecords.Add(tlv); // If used for offline, store it in dedicated list if (recordNumber - file.FirstRecord < file.OfflineNumberOfRecords) { // For files with SFI in the range 1 to 10, the record tag ('70') and the record length are excluded from the offline data authentication process. if (file.Sfi <= 10) { foreach (var tlvData in tlv.InnerTlvs) { _tlvOfflineRecords.Add(tlvData); } } //For files with SFI in the range 11 to 30, the record tag ('70') and the record length are not excluded from the offline data authentication process. else { _tlvOfflineRecords.Add(tlv); } } } _lastStatusWord = crp.RApdu.StatusWord; } return(_lastStatusWord); }
/// <summary> /// Reads log file of the EMV application. Records are stored. /// </summary> /// <returns>Last status word.</returns> public UInt16 ReadLogFile() { BeforeReadLogFileEvent.Raise(this, new EmvEventArgs()); if (LogEntry == null) { throw new LogEntryNotFoundException(String.Format("EMVApplication.readLogFile(): logEntry ({0}) undefined.", _logEntry)); } if (LogFormat == null) { throw new LogFormatNotFoundException(String.Format("EMVApplication.readLogFile(): logFormat ({0}) undefined.", _logFormat)); } _logRecords = new List <List <TlvData> >(); byte recordNumber = 0; do { recordNumber++; CommandAPDU cAPDU = new EMVReadRecordCommand(recordNumber, LogEntry.Sfi, 0); var crp = new CommandResponsePair(cAPDU); crp.Transmit(_cardChannel); _lastStatusWord = crp.RApdu.StatusWord; if (crp.RApdu.StatusWord == 0x9000) { var record = crp.RApdu.Udr; var dataInRecord = _logFormat.ParseRawData(record); _logRecords.Add(dataInRecord); } } while (_lastStatusWord == 0x9000 && recordNumber < _logEntry.CyclicFileSize); AfterReadLogFileEvent.Raise(this, new EmvEventArgs()); return(_lastStatusWord); }