/// <summary> /// Internal method that analyzes the ATR Historical Bytes, /// it populate the object with info about the ICC /// </summary> private void DetectCard() { if (AtrInformation.HistoricalBytes.Length > 1) { byte categoryIndicator; using (DataReader reader = DataReader.FromBuffer(AtrInformation.HistoricalBytes)) { categoryIndicator = reader.ReadByte(); if (categoryIndicator == (byte)CategoryIndicator.StatusInfoPresentInTlv) { while (reader.UnconsumedBufferLength > 0) { const byte appIdPresenceIndTag = 0x4F; const byte appIdPresenceIndTagLen = 0x0C; var tagValue = reader.ReadByte(); var tagLength = reader.ReadByte(); if (tagValue == appIdPresenceIndTag && tagLength == appIdPresenceIndTagLen) { byte[] pcscRid = { 0xA0, 0x00, 0x00, 0x03, 0x06 }; byte[] pcscRidRead = new byte[pcscRid.Length]; reader.ReadBytes(pcscRidRead); if (pcscRid.SequenceEqual(pcscRidRead)) { byte storageStandard = reader.ReadByte(); ushort cardName = reader.ReadUInt16(); PcscCardName = (Pcsc.CardName)cardName; PcscDeviceClass = DeviceClass.StorageClass; } reader.ReadBuffer(4); // RFU bytes } else { reader.ReadBuffer(tagLength); } } } } } else { // Compare with Mifare DesFire card ATR byte[] desfireAtr = { 0x3B, 0x81, 0x80, 0x01, 0x80, 0x80 }; if (Atr.SequenceEqual(desfireAtr)) { PcscDeviceClass = DeviceClass.MifareDesfire; } } }
/// <summary> /// Internal method that analyzes the ATR Historical Bytes, /// it populate the object with info about the ICC /// </summary> private void DetectCard() { if (AtrInformation.HistoricalBytes.Length > 1) { using (var reader = new BinaryReader(new MemoryStream(AtrInformation.HistoricalBytes))) { var categoryIndicator = reader.ReadByte(); if (categoryIndicator == (byte)CategoryIndicator.StatusInfoPresentInTlv) { var bytesRemaining = reader.BaseStream.Length - 1; // already read a byte while (bytesRemaining > 0) { const byte appIdPresenceIndTag = 0x4F; const byte appIdPresenceIndTagLen = 0x0C; var tagValue = reader.ReadByte(); bytesRemaining--; var tagLength = reader.ReadByte(); bytesRemaining--; if (tagValue == appIdPresenceIndTag && tagLength == appIdPresenceIndTagLen) { byte[] pcscRid = { 0xA0, 0x00, 0x00, 0x03, 0x06 }; var pcscRidRead = new byte[pcscRid.Length]; reader.Read(pcscRidRead, 0, pcscRidRead.Length); bytesRemaining -= pcscRidRead.Length; if (pcscRid.SequenceEqual(pcscRidRead)) { var storageStandard = reader.ReadByte(); bytesRemaining--; // This is a big-endian value, so swap the bytes var cnb = new byte[2]; cnb[1] = reader.ReadByte(); cnb[0] = reader.ReadByte(); var cardName = BitConverter.ToUInt16(cnb, 0); bytesRemaining -= 2; PcscCardName = (CardName)cardName; PcscDeviceClass = DeviceClass.StorageClass; } reader.ReadBytes(4); // RFU bytes bytesRemaining -= 4; } else { reader.ReadBytes(tagLength); bytesRemaining -= tagLength; } } } } } else { // Compare with Mifare DesFire card ATR byte[] desfireAtr = { 0x3B, 0x81, 0x80, 0x01, 0x80, 0x80 }; if (Atr.SequenceEqual(desfireAtr)) { PcscDeviceClass = DeviceClass.MifareDesfire; } } }
/// <summary> /// Internal method that analyzes the ATR Historical Bytes, /// it populate the object with info about the ICC /// </summary> private void DetectCard() { if (AtrInformation.HistoricalBytes.Length > 1) { byte categoryIndicator; using (MemoryStream mem = new MemoryStream(AtrInformation.HistoricalBytes)) using (BinaryReader reader = new BinaryReader(mem)) { categoryIndicator = reader.ReadByte(); if (categoryIndicator == (byte)CategoryIndicator.StatusInfoPresentInTlv) { while (reader.BaseStream.Position < reader.BaseStream.Length) { const byte appIdPresenceIndTag = 0x4F; const byte appIdPresenceIndTagLen = 0x0C; var tagValue = reader.ReadByte(); var tagLength = reader.ReadByte(); if (tagValue == appIdPresenceIndTag && tagLength == appIdPresenceIndTagLen) { byte[] pcscRid = { 0xA0, 0x00, 0x00, 0x03, 0x06 }; byte[] pcscRidRead = reader.ReadBytes(pcscRid.Length); if (pcscRid.SequenceEqual(pcscRidRead)) { byte storageStandard = reader.ReadByte(); byte[] cardNameData = reader.ReadBytes(2); if (BitConverter.IsLittleEndian) { Array.Reverse(cardNameData); } PcscCardName = (PcscSdk.CardName)BitConverter.ToUInt16(cardNameData, 0); PcscDeviceClass = DeviceClass.StorageClass; } reader.ReadBytes(4); // RFU bytes } else { reader.ReadBytes(tagLength); } } } } } else { // Compare with Mifare DesFire card ATR byte[] desfireAtr = { 0x3B, 0x81, 0x80, 0x01, 0x80, 0x80 }; if (Atr.SequenceEqual(desfireAtr)) { PcscDeviceClass = DeviceClass.MifareDesfire; } } }